[antlr-interest] Re: Newbie question (not seeing expected error)
derek_kusiak
derek_kusiak at yahoo.com
Thu Dec 2 11:13:30 PST 2004
Thank you very much, Arnar. So simple I'm embarrassed. :)
--- "Arnar Birgisson" <arnarb at o...> wrote:
> Hello Derek,
>
> > So far so good. However, I don't get the expected error
> > if my mistake is in the SECOND sphere:
> >
> > sphere 10
> > 20 sphere
> >
> > Now the first statement is parsed correctly, but there is
> > no error on the second one. It's just silently ignored
> > and my ouput is this:
> >
> > Sphere(radius=10)
> >
> > Why is there no error about the second sphere? Clearly the
> > "20 sphere" line is wrong, so why does my parser bail
> > silently after the error?
>
> After parsing the first line, the parser is at the end of your
> start rule. From there, it doesn't expect to see NUMBER (20) so
> it assumes that it's done parsing and the rest of the input is
> just some garbage (which is sometimes allowed in language
> definitions). This is normal behaviour when you are at the end
> of the start-rule, I think.
>
> If you want to parse the whole file, you need to add the token
> EOF (end-of-file) to the end of your start rule:
>
> class P extends Parser;
> start : (shape)+ EOF;
>
> Given the above example you should get an error in the lines of
> "Unexpected token NUMBER, expecting SPHERE or EOF."
>
> Hope this helps. :o)
>
> Arnar
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/antlr-interest/
<*> To unsubscribe from this group, send an email to:
antlr-interest-unsubscribe at yahoogroups.com
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list