[antlr-interest] non-determinism warnings again
Tarun Khanna
tarunkhanna at gmail.com
Fri Jul 8 09:24:18 PDT 2005
Thanks for your help.
Here is the complete grammar. It is not a lot more than a calculator, but I
need to handle java/c++ type class variables also. Hence the (DOT IDENT)*.
exp
:
T ((PLUS | MINUS) T)*
;
T
:
F (TIMES | DIV | "mod") F)*
;
F
:
NUM
|
(LPAREN exp RPAREN) (DOT IDENT)* (DOT TAB)?
|
IDENT (DOT IDENT)* (DOT TAB)?
|
TAB
;
On 7/8/05, John B. Brodie <jbb at acm.org> wrote:
>
> Tarun Khanna asked (in part):
>
> >Hi All,
>
> Greetings!
>
> >I am getting a non-determinism warning between alt 1 and the exit branch.
> >
> >k=3D1 DOT and k=3D2 IDENT.
> >I have a look-ahead of 2.
>
> ...snip...
>
> ...apparently this is the rule causing the problem...
>
> >F
> >:=20
> >NUM
> >|
> >(LPAREN e=3Dexp RPAREN) (DOT IDENT)* (DOT TAB)?
> >|
> >IDENT (DOT IDENT)* (DOT TAB)?
> >|
> >TAB
> >;
> ...(is this in the Lexer? no, can't be, refers to a parser rule, exp)...
>
> Perhaps I misunderstand your question. I tried this small grammar:
>
> //begin test.g
> class testParser extends Parser;
>
> options { k = 2; }
>
> f :
> NUM
> | (LPAREN exp RPAREN) (DOT IDENT)* (DOT TAB)?
> | IDENT (DOT IDENT)* (DOT TAB)?
> | TAB
> ;
>
> exp : FOO ;
> //end test.g
>
> and received no complaints at all.
>
> is it possible that there is some interaction amongst your rules?
>
> maybe you could post the smallest complete grammar that displays the
> ambiguity and then we could try to fix that...
>
> Hope this helps...
> -jbb
>
>
--
Tarun Khanna
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20050708/17f0b951/attachment.html
More information about the antlr-interest
mailing list