- Main Page
- Classes
- Files

# parse.hpp File Reference

`#include <cstdlib>`
`#include <istream>`
`#include <locale>`
`#include <ostream>`
`#include <string>`
`#include "calc_error.hpp"`
`#include "node.hpp"`

Go to the source code of this file.

## Classes
class | parser
## Functions
void | parse_loop (std::istream &input, std::ostream &output)

## Function Documentation

void parse_loop | ( | std::istream & | input,
|  | std::ostream & | output |
| ) |  |  |

Parse loop. Read expressions from `input` and print results to `output`.

Parameters:

  | input | The input stream.
  | output | The output stream.

Definition at line 338 of file parse.cpp.

References parser::get_statement().

    00339 {
    00340   std::string line;
    00341   // No portable way to test whether the console is an interactive terminal
    00342   // vs. a non-interactive file. If you have a system-specific way to test,
    00343   // output the prompt only for the interactive case.
    00344   for (output << "> "; std::getline(input, line); output << "> ") {
    00345     std::istringstream input(line);
    00346     parser p(input);
    00347     try {
    00348       while (p.get_statement(output)) {
    00349         /* empty */
    00350       }
    00351     } catch(calc_error const& ex) {
    00352       output << ex.what() << '\n';
    00353     } catch(std::exception const& ex) {
    00354       output << "exception: " << ex.what() << '\n';
    00355     }
    00356   }
    00357 }