#include <istream>
#include <locale>
#include <ostream>
#include <stdexcept>
#include <string>
Go to the source code of this file.
Classes | |
class | parse_error |
class | parser |
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 272 of file parse.cpp.
References node::evaluate(), and parser::get_expr().
00273 { 00274 std::string line; 00275 // No portable way to test whether the console is an interactive terminal 00276 // vs. a non-interactive file. If you have a system-specific way to test, 00277 // output the prompt only for the interactive case. 00278 for (output << "> "; std::getline(input, line); output << "> ") { 00279 std::istringstream input(line); 00280 parser p(input); 00281 try { 00282 node n; 00283 while (p.get_expr(n)) 00284 output << n.evaluate() << '\n'; 00285 } catch(parse_error const& ex) { 00286 output << ex.what() << '\n'; 00287 } catch(std::exception const& ex) { 00288 output << "exception: " << ex.what() << '\n'; 00289 } 00290 } 00291 }