[antlr-interest] Re: Is it because of buggy antlr?

Terence Parr parrt at jguru.com
Mon Jan 20 22:43:35 PST 2003


On Monday, January 20, 2003, at 09:44 PM, rmsanjivp 
<rmsanjivp at yahoo.com> wrote:

> Thanks Loring,
>
> But that was a typo from my side. I really had hard time figuring
> out the problem with the following grammar:
>
>
> expr
>  : e1 ((PLUS | MINUS) e1)*
>  ;
>
>  e1
>   : e0 ( POWER e1)? // to make POWER tree as right associative
>   ;
>
> e0: ID;
>
> If it is a small example like this then it works fine because in the
> c++ code generated by ANTLR does not throw an exception if the next
> token is the EOF.

EOF is added to FOLLOW any rule that is not referenced by any other 
rule...it is by definition a possible start rule.

>
> But I have a grammar where I have a number of tokens and at least 11
> levels of descent like..
>
> e1: e2 (OP1 e2)*;
> e2: e3 (OP2 e3)*
> ...
> e10: e11 (OP10 e10)?;
> e11: ID;
>
> On Observing the code generated for this bug grammar I figured out
> that in the method for rule e10 an exception is thrown if the next
> lookahead symbol is not any of OP1, op2, ..., OP10.

because FOLLOW(e10) is FOLLOW(e9) ... to FOLLOW(e1), which may be EOF.

>  Even when rule
> e11 can lead to the terminal the method for rule e10 throws an
> exception for EOF. And if I have "p1+p2" as an input then it
> recognizes upto p2 but then in rule e10 the next look ahead is EOF
> and hence it throws an exception.

What is the start symbol for parsing "p1+p2"?

Ter
--
Co-founder, http://www.jguru.com
Creator, ANTLR Parser Generator: http://www.antlr.org
Lecturer in Comp. Sci., University of San Francisco


 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 



More information about the antlr-interest mailing list