1 /// @file parser_a_b.cpp Check for some silly bugs in the parser.
9 // - a - b was misparsed as -a + b due to a bug in parser::parse_unary_expr()
10 static int check1(std::ostream& err_str)
12 const std::string srep("-a-b");
15 ex a = reader.get_syms()["a"];
16 ex b = reader.get_syms()["b"];
18 ex d = (e - g).expand();
20 err_str << "\"" << srep << "\" was misparsed as \""
21 << e << "\"" << std::endl;
27 /// Parser was rejecting the valid expression '5 - (3*x)/10'.
28 static int check2(std::ostream& err_str)
30 const std::string srep("5-(3*x)/10");
33 ex x = reader.get_syms()["x"];
35 ex d = (e - g).expand();
37 err_str << "\"" << srep << "\" was misparsed as \""
38 << e << "\"" << std::endl;
44 /// parse_literal_expr forget to consume the token, so parser get
46 static int check3(std::ostream& err_str)
48 const std::string srep("5-(2*I)/3");
51 ex g = numeric(5) - (numeric(2)*I)/3;
52 ex d = (e - g).expand();
54 err_str << "\"" << srep << "\" was misparsed as \""
55 << e << "\"" << std::endl;
61 /// parser happily accepted various junk like 'x^2()+1'
62 static int check4(std::ostream& err_str)
64 const std::string junk("x^2()+1");
69 err_str << "parser accepts junk: \"" << junk << "\"" << std::endl;
71 } catch (parse_error& err) {
72 // Ok, parser rejects the nonsense.
77 int main(int argc, char** argv)
79 std::cout << "checking for parser bugs. " << std::flush;
80 std::ostringstream err_str;
82 errors += check1(err_str);
83 errors += check2(err_str);
84 errors += check3(err_str);
85 errors += check4(err_str);
87 std::cout << "Yes, unfortunately:" << std::endl;
88 std::cout << err_str.str();
90 std::cout << "Not found. ";