ANTLR how to detect rubbish data at end of input
antlr, input, parsing
Solution
As Scott already answered on the ANTLR mailing list:
Hello,
When using grammars written in ANTLR, the parser correctly recognizes data from an input stream, but if I have some rubbish text at the end of the input (which rubbish text is not supposed to be parsed by the grammar) the parser does not complain.
I guess this behavior is all right (I mean the parser did its job and parsed whatever I said it should parse), but is there any trick to detect when there is any data left in the input after the parser has done its job?
Thanks, Gabi.
Add an EOF token to the end of your start rule
-- Scott
Problem
When using grammars written in ANTLR, the parser correctly recognizes data from an input stream, but if I have some rubbish text at the end of the input (which is not supposed to be parsed by the grammar) the parser does not complain. I guess this behavior is all right (I mean the parser did its job and parsed whatever I said it should parse), but is there any trick to detect when there is any data left in the input after the parser has done its job? Thanks.