[antlr-interest] Parser stopping before matching the whole input
Edson Tirelli
tirelli at post.com
Mon Jul 2 07:36:10 PDT 2007
All,
I'm facing a problem I didn't found info on the archives. Being short,
the parser is stopping to parse before the end of the input stream when it
founds an unexpected token. For instance, my top level rule is:
compilation_unit
: prolog
statement+
;
So, if the parser finds a valid prolog, and at least one valid statement,
and after that finds a token it does not recognize, it simply stops parsing
without any error message. Example:
==========
package a.b.c;
import x.y.z;
xxxxxx
import r.s.t;
===========
In the example above, the "package" is a valid prolog, the "import" is a
valid statement and both are parsed correctly. But when the parser finds
"xxxxxx" it does not recognize it and simply stops parsing without any
error. I understand the behavior from a parsing rule perspective, but I want
to force the parser to parse the whole input, reporting errors for
unrecognized tokens and recovering whenever possible.
How can I do that?
I imagine that if I had a mandatory "end of stream" token, I could simply
do:
compilation_unit
: prolog
statement+
MY_END_OF_STREAM_TOKEN
;
But I don't have such token and can't add it to the language.
Any ideas?
Thank you in advance,
Edson
--
Edson Tirelli
Software Engineer - JBoss Rules Core Developer
Office: +55 11 3529-6000
Mobile: +55 11 9287-5646
JBoss, a division of Red Hat @ www.jboss.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20070702/2dcda32c/attachment.html
More information about the antlr-interest
mailing list