[antlr-interest] Lexer.getNumberOfSyntaxErrors not reliable; is this a bug?

Jim Idle jimi at temporal-wave.com
Wed May 6 07:30:52 PDT 2009


Johan Cockx wrote:
> Hi,
>
> I am using ANTLR 3.1.3.
>
> The class BaseRecognizer has a method getNumberOfSyntaxErrors() that 
> is supposed to return the number of syntax errors detected.
>
> The count is maintained in BaseRecognizer.reportError(...).
>
> However,  the Lexer class overrides this method and does not update 
> the syntax error count when a lexer error is reported.  As a result,  
> the syntax error count is not reliable in the lexer.
Take a look through past posts for advice on this, but basically you 
should code your lexer so that it cannot give syntax errors really. You 
should code it so that it intercepts things that go wrong and generates 
sensible errors.

If you want the simpler behavior, then you should indeed override the 
display error method. Whether the default one should increment the error 
count is a good question though. But it is unlikely that the default 
error message displayRecognitionError (which is what you normally 
override) would ever be what you want to display anyway of course.

Jim



More information about the antlr-interest mailing list