[antlr-interest] strict parsing

Thomas Brandon tbrandonau at gmail.com
Wed Jun 25 23:58:39 PDT 2008


You want to override the error reporting routines from the BaseRecognizer
class. I believe the wiki has an example showing which methods you need to
override. You could have them throw a exception (you can't add a throws
clause so it needs to be a runtime exception) to drop out of parsing
immediately. Or you may be better to record errors and then abort further
analysis if there are errors. That way you can report multiple errors in one
go rather than having to go through the errors one at a time. The drawback
to this is that you may have multiple error messages resulting from a single
underlying error. Or you could combine the two and throw an exception for
some types of error and simply record others.

Tom.

On Thu, Jun 26, 2008 at 4:23 PM, Gerard van de Glind <
g.vandeglind at beinformed.nl> wrote:

>  Hi there,
>
>
>
> I have a grammar that recognizes simple arithmetic expressions.
>
> So something like 'x + 2' is a valid expression.
>
> However the expression '[x + 2' is also accepted, in my log file I see the
> following message:
>
>
>
> line 1:0 no viable alternative at character '['
>
>
>
> '[' is not valid token in my grammar, so it's ignored.
>
> I want to make my grammar stricter that it doesn't accept these kind of
> expressions anymore.
>
> Does anyone have a clue how I can do this?
>
>
>
> Thanks for your help!
>
>
>
> Cheers,
>
> Gerard
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080626/89bfe0a2/attachment.html 


More information about the antlr-interest mailing list