[antlr-interest] Re: Grammar seems to produce incorrect parser
Lubos Vnuk
lubos.vnuk at rts.at
Fri Jan 23 07:29:35 PST 2004
Hi Stan,
I think this has something to do with the LA-sets analysis in the
recursively referencing rules. The problem, as I see it, is that
ANTLR should somehow find out where to start with the analysis (a
root or top-level rule). And obviously this is not easy if you have
nothing else but two mutually referencing rules in the grammar.
Unfortunately ANTLR does not complain about it but obviously it will
surface during debugging, depending on what your top-level rule
called from the main function is.
My hint here is to create a helper rule showing ANTLR unambiguously
it is the one:
helper_expression: expression;
HTH,
Lubos.
--- In antlr-interest at yahoogroups.com, "stanhuff" <stanhuff at y...>
wrote:
> 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/
More information about the antlr-interest
mailing list