Calculator Step 5

- Main Page
- Classes
- Files

- File List
- File Members

Functions
parse.cpp File Reference
`#include <cstdlib>`
`#include <iterator>`
`#include <sstream>`
`#include "calc_error.hpp"`
`#include "node.hpp"`
`#include "parse.hpp"`
`#include "variables.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 421 of file parse.cpp.

References parser::get_statement().

Referenced by BOOST_AUTO_TEST_CASE(), and main().

422 {
423 std::string line{};
424 // No portable way to test whether the console is an interactive terminal
425 // vs. a non-interactive file. If you have a system-specific way to test,
426 // output the prompt only for the interactive case.
427 for (output << "> "; std::getline(input, line); output << "> ") {
428 std::istringstream input{std::move(line)};
429 parser p(input);
430 try {
431 while (p.get_statement(output)) {
432 /* empty */
433 }
434 } catch(calc_error const& ex) {
435 output << ex.what() << '\n';
436 } catch(std::exception const& ex) {
437 output << "exception: " << ex.what() << '\n';
438 }
439 }
440 }
calc_error
Definition: calc_error.hpp:11
parser
Definition: parse.hpp:25