Calculator  Step 4
Classes | Functions
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
inputThe input stream.
outputThe output stream.

Definition at line 338 of file parse.cpp.

Referenced by BOOST_AUTO_TEST_CASE(), and main().

339 {
340  std::string line{};
341  // No portable way to test whether the console is an interactive terminal
342  // vs. a non-interactive file. If you have a system-specific way to test,
343  // output the prompt only for the interactive case.
344  for (output << "> "; std::getline(input, line); output << "> ") {
345  std::istringstream input{std::move(line)};
346  parser p{input};
347  try {
348  while (p.get_statement(output)) {
349  /* empty */
350  }
351  } catch(calc_error const& ex) {
352  output << ex.what() << '\n';
353  } catch(std::exception const& ex) {
354  output << "exception: " << ex.what() << '\n';
355  }
356  }
357 }
Definition: parse.hpp:25