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

Johan Cockx johan at sikanda.be
Wed May 6 07:41:07 PDT 2009


On Wed, May 6, 2009 at 4:30 PM, Jim Idle <jimi at temporal-wave.com> wrote:

> 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
>

What you say makes sense.  However,  my point is that I have only just
started the development of my grammar and I don't want want to spend time on
error handling yet. It is also the first time I am using ANTLR (I have used
Flex/Bison before) and I was just looking for a simple way to detect whether
or not any parsing errors have occurred.  The current behavior is quite
confusing for a first time user,  so I'd say the default display error
method should increment the error count.

Even the error count method doesn't seem to be well documented,  I only
found it by looking at the source code.

Thank's anyway,   my problem is solved.

Johan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20090506/912e23b9/attachment.html 


More information about the antlr-interest mailing list