]> www.ginac.de Git - ginac.git/blobdiff - ginac/parser/parser.cpp
parser: add necessary checks to operator() to stop accepting nonsense.
[ginac.git] / ginac / parser / parser.cpp
index 6cac523c38625d8bddad69dcbc648d4b629665c4..6411ba1416e740a85705ceee3153815b33e9364f 100644 (file)
@@ -138,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;
 }