[antlr-interest] ANTLR bug??? ReportError not called on "NonViableAltException"

Thomas Brandon tbrandonau at gmail.com
Tue Aug 7 21:12:11 PDT 2007


On 8/8/07, Frank Smith <fasmith718 at gmail.com> wrote:
> Hi all.  I recently uncovered a problem with my parser where i'm doing
> something illegal and ReportError is never called.  ANTLRworks' interpreter
> window shows that there is a Nonviable alt, but the breakpoint i put in
> RecognitionError is never reached on code execution.
>
> This is a big problem because I am trying to make my language fail
> immediately on parse errors, but I can't do this if they are never thrown by
> the generated antlr code!
>
> Here is the sample program - you should not be able to put a statement
> outside of a function :
> fun wave main()
>     print "main";
> end fun
> x = 1;
>
> yet this compiles without reporting an error.  However, putting it in
> ANTLRWorks' interpreter shows it to be wrong (which is what i want, darn
> it!)
>
> Here is my entire .g file.  If someone could just past it into their
> antrlworks and explain this discrepancy i would be highly highly
> appreciative.  This is for a project and I need to know if I should pass
> this off as a bug in ANTRL generated code... :-/
>
> Thanks a million times in advance!!!
>      Frank
>
> program    :    (include_stmt)*(fun_decl)+;
I think the problem is that this needs to be:
program    :    (include_stmt)*(fun_decl)+ EOF;
otherwise ANTLR will just decide the first error means the end of what
it needs to parse.
Though the difference of behaviour in the interpreter is still an issue.

Tom.


More information about the antlr-interest mailing list