Calculator  Step 5
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 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 }
Definition: parse.hpp:25