1 /** @file parser_bugs.cpp
3 * Check for some silly bugs in the parser. */
6 * GiNaC Copyright (C) 1999-2020 Johannes Gutenberg University Mainz, Germany
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 using namespace GiNaC;
33 // - a - b was misparsed as -a + b due to a bug in parser::parse_unary_expr()
34 static int check1(ostream& err_str)
36 const string srep("-a-b");
39 ex a = reader.get_syms()["a"];
40 ex b = reader.get_syms()["b"];
42 ex d = (e - g).expand();
44 err_str << "\"" << srep << "\" was misparsed as \""
51 /// Parser was rejecting the valid expression '5 - (3*x)/10'.
52 static int check2(ostream& err_str)
54 const string srep("5-(3*x)/10");
57 ex x = reader.get_syms()["x"];
59 ex d = (e - g).expand();
61 err_str << "\"" << srep << "\" was misparsed as \""
68 /// parse_literal_expr forget to consume the token, so parser get
70 static int check3(ostream& err_str)
72 const string srep("5-(2*I)/3");
75 ex g = numeric(5) - (numeric(2)*I)/3;
76 ex d = (e - g).expand();
78 err_str << "\"" << srep << "\" was misparsed as \""
85 /// parser happily accepted various junk like 'x^2()+1'
86 static int check4(ostream& err_str)
88 const string junk("x^2()+1");
93 err_str << "parser accepts junk: \"" << junk << "\"" << endl;
95 } catch (parse_error& err) {
96 // Ok, parser rejects the nonsense.
101 int main(int argc, char** argv)
103 cout << "examining old parser bugs" << flush;
104 ostringstream err_str;
106 errors += check1(err_str); cout << '.' << flush;
107 errors += check2(err_str); cout << '.' << flush;
108 errors += check3(err_str); cout << '.' << flush;
109 errors += check4(err_str); cout << '.' << flush;
111 cout << "Yes, unfortunately:" << endl;
112 cout << err_str.str();
114 cout << "Not found. ";