[antlr-interest] The behavior.....

Gavin Lambert antlr at mirality.co.nz
Mon Jan 26 23:27:41 PST 2009


At 17:03 27/01/2009, Meena Vinod wrote:
>On the ANTLRWorks, when I give a junk input say 'zee zee', the 
>ANTLRWorks does not generate any proper output and does not evn 
>throw an exception.
>Also, the C code generated hangs when given this input.

The grammar you provided in the email shouldn't have either 
behaviour (unless you generated the code with -debug, for the 
hanging problem).

However variations on some of your rules could cause both of them.

1.
If your top-level rule permits nothing to be matched (eg. by using 
*), then ANTLR will quite happily match nothing and report 
success, when given invalid input.  ANTLR will not complain about 
having "extra" unconsumed input; it assumes that you're going to 
do something else with it (such as passing it to a different 
lexer).

If you want ANTLR to complain about not matching all the input, 
then your top-level rule should end with EOF, thereby explicitly 
trying to match "end of file/input".

2.
If a top-level lexer rule permits nothing to be matched (again, 
eg. by using *), then it will get into an infinite loop, as it can 
always successfully match nothing.  Make sure you don't do that.



More information about the antlr-interest mailing list