[antlr-interest] Grammar seems to produce incorrect parser
Stan Huff
stanhuff at yahoo.com
Wed Jan 21 20:15:12 PST 2004
This doesn't help. Aside from this, the documentation
states that this option is on by default anyway.
The code generated for the expression rule is:
public final void expression() throws
RecognitionException, TokenStreamException {
simpleExpression();
{
switch ( LA(1)) {
case LITERAL_is:
{
match(LITERAL_is);
match(LITERAL_null);
break;
}
case RParen:
{
break;
}
default:
{
throw new NoViableAltException(LT(1),
getFilename());
}
}
}
}
This code seems to be requiring a RParen token or the
"is null" to be following the simpleExpression,
otherwise an error is thrown. I would think that if
the "is null" were optional, then the default case
should be removed.
--- mzukowski at yci.com wrote:
> You need to set the testLiterals option to true for
> your identifier rule.
>
> Monty
>
> -----Original Message-----
> From: stanhuff [mailto:stanhuff at yahoo.com]
> Sent: Wednesday, January 21, 2004 4:59 PM
> To: antlr-interest at yahoogroups.com
> Subject: [antlr-interest] Grammar seems to produce
> incorrect parser
>
> In the following grammar, I desire to have the "is
> null" clause
> optional after the 'simpleExpression' non-terminal.
> The resultant
> parser doesn't work as expected. The parser
> generated from my little
> grammar throws exceptions if "is null" is not found.
> How can I change
> my grammar to get the desired parser?
>
>
>
>
> class ExpressionParser extends Parser;
> options {defaultErrorHandler=false;}
> expression
> : simpleExpression ("is" "null")?
> ;
>
> simpleExpression
> : Digits
> | LParen expression RParen
> ;
>
> class ExpressionLexer extends Lexer;
>
> Identifier: ('a'..'z' | 'A'..'Z' | '_') ('a'..'z' |
> 'A'..'Z'
> | '0'..'9' | '_')*;
>
> Digits: ('0'..'9')+;
>
> LParen: '(';
>
> RParen: ')';
>
> WS_ : (' ' | '\t' | '\n' | '\r')
> { _ttype = antlr::Token::SKIP; }
> ;
>
>
>
> Thanks,
> Stan
>
>
>
>
>
>
> 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/
>
>
>
>
> 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/
>
>
__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free web site building tool. Try it!
http://webhosting.yahoo.com/ps/sb/
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