[antlr-interest] Newbie Help

Gavin Lambert antlr at mirality.co.nz
Wed Jan 14 01:42:16 PST 2009


At 09:50 14/01/2009, Mike Gering wrote:
>I'm learning Antlr (version 2.7.7) and cannot figure out how to 
>disambiguate a simple grammar:
[...]
>a
>         : (STAR simple_name )*
>                 (SLASH simple_name)*
>         ;
[...]
>The generator complains that the "a" rule above is 
>nondeterministic upon STAR. I understand (I think) why -- when 
>matching programmatic_unit/a, it is ambiguous whether to use "a" 
>or "b" when STAR is the next token. But how do I repair the 
>grammar? Any advice would be very welcome.

Setting the option k=2 should do the trick.  ANTLR needs to look 
ahead two tokens (ie. to the token following the STAR) to figure 
out whether it's a NAME_FRAG or an INT (and hence which path it 
should take).



More information about the antlr-interest mailing list