[antlr-interest] Grammar not detecting extraneous input at end
Karim Chichakly
karimc17 at gmail.com
Thu Jun 3 12:11:24 PDT 2010
Thank you Bart and Kirby, that is very helpful!
Karim
On Thu, Jun 3, 2010 at 2:47 PM, Bart Kiers <bkiers at gmail.com> wrote:
> Hi,
>
> On Thu, Jun 3, 2010 at 8:38 PM, Karim Chichakly <karimc17 at gmail.com>
> wrote:
>
> > Hi,
> >
> > I have a grammar that does not give an error (in ANTLR 3.2) if there are
> > extraneous characters at the end of the input. For example, I would
> expect
> > "(a+b))" to generate an error, but it does not. "(a+b)" is parsed fine
> and
> > the extra ")" at the end is just ignored.
> >
>
> Since "(a+b))" does not contain any illegal tokens, the parser simply stops
> after it (successfully) parses "(a+b)". You'll want to "force" the parser
> to
> go through the entire token stream by adding an 'EOF' after your 'equation'
> rule:
>
> equation
> : expr EOF
> ;
>
>
> Regards,
>
> Bart.
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe:
> http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>
More information about the antlr-interest
mailing list