X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=blobdiff_plain;f=ginac%2Fparser%2Fparser.cpp;h=6411ba1416e740a85705ceee3153815b33e9364f;hp=f48d37fdf5c495916d7d3c0330d92068ecdde868;hb=1261c54df6548cf558405a118b2134805f63376d;hpb=05157f89a3db97fff79e33fd53156b380107011f diff --git a/ginac/parser/parser.cpp b/ginac/parser/parser.cpp index f48d37fd..6411ba14 100644 --- a/ginac/parser/parser.cpp +++ b/ginac/parser/parser.cpp @@ -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") @@ -137,6 +138,13 @@ ex parser::operator()(std::istream& input) scanner->switch_input(&input); get_next_tok(); ex ret = parse_expression(); + // parse_expression() stops if it encounters an unknown token. + // This is not a bug: since the parser is recursive checking + // whether the next token is valid is responsibility of the caller. + // Hence make sure nothing is left in the stream: + if (token != lexer::token_type::eof) + Parse_error("expected EOF"); + return ret; }