1 // $Id: exprtest.cc 18 2007-08-19 19:51:52Z tb $
6 #include "ObCompiler.H"
7 #include "expression.h"
9 int main(int argc, char *argv[])
12 objectbuilder::ObCompiler obCompiler(calc);
13 bool readfile = false;
15 for(int ai = 1; ai < argc; ++ai)
17 if (argv[ai] == std::string ("-p")) {
18 obCompiler.trace_parsing = true;
20 else if (argv[ai] == std::string ("-s")) {
21 obCompiler.trace_scanning = true;
25 // read a file with expressions
27 std::fstream infile(argv[ai]);
30 std::cerr << "Could not open file: " << argv[ai] << std::endl;
34 calc.clearExpressions();
35 bool result = obCompiler.parse_stream(infile, argv[ai]);
38 std::cout << "Expressions:" << std::endl;
39 for (unsigned int ei = 0; ei < calc.expressions.size(); ++ei)
41 std::cout << "[" << ei << "]:" << std::endl;
42 std::cout << "tree:" << std::endl;
43 calc.expressions[ei]->print(std::cout);
44 std::cout << "evaluated: "
45 << calc.expressions[ei]->evaluate()
54 if (readfile) return 0;
56 std::cout << "Reading expressions from stdin" << std::endl;
59 while( std::cout << "input: " &&
60 std::getline(std::cin, line) &&
63 calc.clearExpressions();
64 bool result = obCompiler.parse_string(line, "input");
68 for (unsigned int ei = 0; ei < calc.expressions.size(); ++ei)
70 std::cout << "tree:" << std::endl;
71 calc.expressions[ei]->print(std::cout);
72 std::cout << "evaluated: "
73 << calc.expressions[ei]->evaluate()