- Main Page
- Classes
- Files

# parse.hpp File Reference

`#include <istream>`
`#include <locale>`
`#include <ostream>`
`#include <stdexcept>`
`#include <string>`

Go to the source code of this file.

## Classes
class | parse_error
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 182 of file parse.cpp.

References parser::get_expr().

    00183 {
    00184   std::string line;
    00185   // No portable way to test whether the console is an interactive terminal
    00186   // vs. a non-interactive file. If you have a system-specific way to test,
    00187   // output the prompt only for the interactive case.
    00188   for (output << "> "; std::getline(input, line); output << "> ") {
    00189     std::istringstream input(line);
    00190     parser p(input);
    00191     try {
    00192       double x;
    00193       while (p.get_expr(x))
    00194         output << x << '\n';
    00195     } catch(parse_error const& ex) {
    00196       output << ex.what() << '\n';
    00197     } catch(std::exception const& ex) {
    00198       output << "exception: " << ex.what() << '\n';
    00199     }
    00200   }
    00201 }