#include <sstream>
#include "parse.hpp"
Go to the source code of this file.
Functions | |
void | parse_loop (std::istream &input, std::ostream &output) |
void parse_loop | ( | std::istream & | input, | |
std::ostream & | output | |||
) |
Parse loop. Read expressions from input
and print results to output
.
input | The input stream. | |
output | The output stream. |
Definition at line 182 of file parse.cpp.
Referenced by BOOST_AUTO_TEST_CASE(), and main().
00183 { 00184 std::string line; 00185 // No portable way to test whether the console is an interactive terminal 00186 // vs. a non-interactive file. If you have a system-specific way to test, 00187 // output the prompt only for the interactive case. 00188 for (output << "> "; std::getline(input, line); output << "> ") { 00189 std::istringstream input(line); 00190 parser p(input); 00191 try { 00192 double x; 00193 while (p.get_expr(x)) 00194 output << x << '\n'; 00195 } catch(parse_error const& ex) { 00196 output << ex.what() << '\n'; 00197 } catch(std::exception const& ex) { 00198 output << "exception: " << ex.what() << '\n'; 00199 } 00200 } 00201 }