Calculator Step 3

- Main Page
- Classes
- Files

- File List
- File Members

Functions
parse.cpp File Reference
`#include <sstream>`
`#include "node.hpp"`
`#include "parse.hpp"`

Go to the source code of this file.

## 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 272 of file parse.cpp.

References node::evaluate().

Referenced by BOOST_AUTO_TEST_CASE(), and main().

273 {
274 std::string line{};
275 // No portable way to test whether the console is an interactive terminal
276 // vs. a non-interactive file. If you have a system-specific way to test,
277 // output the prompt only for the interactive case.
278 for (output << "> "; std::getline(input, line); output << "> ") {
279 std::istringstream input{std::move(line)};
280 parser p{input};
281 try {
282 node n;
283 while (p.get_expr(n))
284 output << n.evaluate() << '\n';
285 } catch(parse_error const& ex) {
286 output << ex.what() << '\n';
287 } catch(std::exception const& ex) {
288 output << "exception: " << ex.what() << '\n';
289 }
290 }
291 }
node
Definition: node.hpp:16
parser
Definition: parse.hpp:30
parse_error
Definition: parse.hpp:13
node::evaluate
double evaluate() const
Definition: node.cpp:50