[antlr-interest] Re: how do i generate an error if input is not fully consumed
fedot
fedot at stockworm.com
Thu Mar 20 13:58:30 PST 2003
Brian,
Thank you for the tip. I really should have thought about it myself,
since most ANTLR examples include an EOF at the end of start rules.
By the way, I also had to add {options defaultErrorHandler =
false; } to my Parser, otherwise errors where simply echoed to
System.out, without giving me an opportunity to do anything about it.
--- In antlr-interest at yahoogroups.com, Brian Smith <brian-l-
smith at u...> wrote:
> I have been tripped up by this before. From memory, I believe that
you
> just need to make sure your start rules explicitly end with EOF.
You
> probably have a start rule that looks like this:
>
> myRule: A B C;
>
> Change it to:
>
> myRule: A B C EOF;
>
> Then, myRule will only be matched if nothing follows it.
>
> - Brian
>
>
>
> fedot wrote:
> > I have the following java code (approximately) to go with some
> > simple calculator grammar:
> >
> > MyLexer lexer = new MyLexer(new StringReader(string));
> > MyParser parser = new MyParser(lexer);
> > parser.start(); // start variable
> > System.out.println(parser.getAST().toStringList());
> >
> > If input string is such that only beginning of it matches lexer
and
> > parser rules, an AST is properly constructed for the beginning
of
> > the string and the remainder is silently ignored.
> >
> > I need to detect such a state (syntactically invalid input
remaining
> > unconsumed) and "raise an error flag". What are my options?
> >
> > Thank you in advance!
> >
> >
> >
> >
> > Your use of Yahoo! Groups is subject to
http://docs.yahoo.com/info/terms/
> >
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list