]> www.ginac.de Git - ginac.git/commitdiff
[bugfix] parser::parse_literal_expr(): don't forget to consume the token...
authorAlexei Sheplyakov <varg@theor.jinr.ru>
Sat, 13 Sep 2008 22:36:16 +0000 (02:36 +0400)
committerAlexei Sheplyakov <varg@theor.jinr.ru>
Fri, 19 Sep 2008 09:15:49 +0000 (13:15 +0400)
... so parser won't process it twice (and get either spurious error or
wrong result).

check/parser_bugs.cpp
ginac/parser/parser.cpp

index 340fe20fb2cc4da5b038172e0e5d8204e8bbb16c..a83f668a4b620a7bcbbcb74ab75306aa4fd4127c 100644 (file)
@@ -41,6 +41,23 @@ static int check2(std::ostream& err_str)
        return 0;
 }
 
+/// parse_literal_expr forget to consume the token, so parser get
+/// very confused.
+static int check3(std::ostream& err_str)
+{
+       const std::string srep("5-(2*I)/3");
+       parser reader;
+       ex e = reader(srep);
+       ex g = numeric(5) - (numeric(2)*I)/3;
+       ex d = (e - g).expand();
+       if (!d.is_zero()) {
+               err_str << "\"" << srep << "\" was misparsed as \""
+                       << e << "\"" << std::endl;
+               return 1;
+       }
+       return 0;
+}
+
 int main(int argc, char** argv)
 {
        std::cout << "checking for parser bugs. " << std::flush;
@@ -48,6 +65,7 @@ int main(int argc, char** argv)
        int errors = 0;
        errors += check1(err_str);
        errors += check2(err_str);
+       errors += check3(err_str);
        if (errors) {
                std::cout << "Yes, unfortunately:" << std::endl;
                std::cout << err_str.str();
index f48d37fdf5c495916d7d3c0330d92068ecdde868..6cac523c38625d8bddad69dcbc648d4b629665c4 100644 (file)
@@ -121,6 +121,7 @@ ex parser::parse_number_expr()
 /// literal_expr: 'I' | 'Pi' | 'Euler' | 'Catalan'
 ex parser::parse_literal_expr()
 {
+       get_next_tok(); // consume the literal
        if (scanner->str == "I")
                return I;
        else if (scanner->str == "Pi")