#include <istream>
#include <locale>
#include <ostream>
#include <stdexcept>
#include <string>
#include <vector>
#include "variables.hpp"
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 267 of file parse.cpp.
References parser::get_expr().
00268 { 00269 std::string line; 00270 // No portable way to test whether the console is an interactive terminal 00271 // vs. a non-interactive file. If you have a system-specific way to test, 00272 // output the prompt only for the interactive case. 00273 for (output << "> "; std::getline(input, line); output << "> ") { 00274 std::istringstream input(line); 00275 parser p(input); 00276 try { 00277 double x; 00278 while (p.get_expr(x)) 00279 output << x << '\n'; 00280 } catch(parse_error const& ex) { 00281 output << ex.what() << '\n'; 00282 } catch(std::exception const& ex) { 00283 output << "exception: " << ex.what() << '\n'; 00284 } 00285 } 00286 }