Calculator Step 1

- Main Page
- Classes
- Files

- File List
- File Members

Functions
parse.cpp File Reference
`#include <sstream>`
`#include <utility>`
`#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 183 of file parse.cpp.

Referenced by BOOST_AUTO_TEST_CASE(), and main().

184 {
185 std::string line;
186 // No portable way to test whether the console is an interactive terminal
187 // vs. a non-interactive file. If you have a system-specific way to test,
188 // output the prompt only for the interactive case.
189 for (output << "> "; std::getline(input, line); output << "> ") {
190 std::istringstream input{std::move(line)};
191 parser p{input};
192 try {
193 double x{};
194 while (p.get_expr(x))
195 output << x << '\n';
196 } catch(parse_error const& ex) {
197 output << ex.what() << '\n';
198 } catch(std::exception const& ex) {
199 output << "exception: " << ex.what() << '\n';
200 }
201 }
202 }
parser
Definition: parse.hpp:17
parse_error
Definition: parse.hpp:11