[antlr-interest] Re: lexical nondeterminism

Xue Yong Zhi seclib at seclib.com
Mon Feb 27 14:38:52 PST 2006


Ruben Laguna wrote:
> Hello,
> 
> I have the following two lexical rules
> 

> 
> which give me the following warnings when I try to compile them
> warning:lexical nondeterminism between rules BINDRULEKEYWORD and RIGHT upon
>      k==1:'r'
>      k==2:'o','r'
>      k==3:'l','o'
>      k==4:<end-of-token>,'e','r'
>      k==5:<end-of-token>,'a'
>      k==6:<end-of-token>
> 
> I've read about the linear approximate lookahead and I understand that 
> this is the problem but I haven't found which is the right way to tweak 
> the grammar file to bea ble to parse correctly "roledn" as a 
> BINDRULEKEYWORD token.

Right, what you saw is linear approximate lookahead.

> What are the ways to handle this nondeterminism?
> 
> do i need to set up two lexers one for the RIGHT rule and one for the 
> BINDRULEKEYWORD and then change the parsers rules to switch between 
> lexer with TokenStreamSelector or there is a better way to handle this?
> 

That's overkill.

A easy fix can be:
Make BINDRULEKEYWORD and RIGHT "protected".

Then add a new one:
BINDRULEKEYWORD_OR_RIGHT
:BINDRULEKEYWORD {$setType(BINDRULEKEYWORD);}
| RIGHT {$setType(RIGHT);}
;

-- 
Xue Yong Zhi
http://seclib.blogspot.com



More information about the antlr-interest mailing list