[antlr-interest] Grammar not detecting stray syntax after

Gary Miller gary at sumwise.com
Tue Apr 5 18:21:54 PDT 2011


This one also bit me a while back.

The other thing you can do is to turn off error recovery.
The trailing '}' is be swallowed.

Regards
Gary


> Date: Tue, 5 Apr 2011 14:44:45 -0400
> From: David Daeschler <david.daeschler at gmail.com>
> Subject: Re: [antlr-interest] Grammar not detecting stray syntax after
>        certain valid blocks
> To: Bart Kiers <bkiers at gmail.com>
> Cc: antlr-interest at antlr.org
> Message-ID: <BANLkTin4wgGQzb6d_Zw6-Z83OSMKMOEU5w at mail.gmail.com>
> Content-Type: text/plain; charset=ISO-8859-1
>
> Thank you Bart!
>
> That of course did the trick. I dont know why I didnt think of that.
>
> I appreciate the quick response, have a nice week!
> --
> David Daeschler
>
>
>
> On Tue, Apr 5, 2011 at 2:31 PM, Bart Kiers <bkiers at gmail.com> wrote:
>
> > This is enough to demonstrate the problem. When I create a program such
> as:
> >>
> >> state hello
> >> {
> >>
> >> }
> >> }
> >>
> >> The trailing close bracket is not detected as an error.
> >> <http://www.antlr.org/mailman/options/antlr-interest/your-email-address
> >
> >
> >
> > Try to "anchor" it by adding an EOF at the end of your entry-rule:
> >
> > public prog
> >   :  globalStmt+ EOF
> >   ;
> >
> >
> > That way, you force the parser to go through the entire token stream, and
> > not stop prematurely.
> >
> > Regards,
> >
> > Bart.
> >
> >
>
>


More information about the antlr-interest mailing list