[antlr-interest] Difference in the following rules

Tarun Khanna tarunkhanna at gmail.com
Tue Jul 12 06:10:05 PDT 2005


Thanks Paul and Ric, I appreciate your help. I didn't know of the 
-diagnostic option. It helps greatly as it lists down the FIRST and FOLLOW 
sets, which I used to generate by manually for debugging.

Although it is still not clear that even after a lookahead of 2, the above 
warnings are generated because I thought that the after looking ahead two 
tokens the parser would be able to decide concretely as to which rule to 
follow. I guess the diagnostic files may help...

Thanks again.
Tarun
On 7/12/05, Ric Klaren <ric.klaren at gmail.com> wrote:
> 
> On 7/12/05, Paul Johnson <gt54-antlr at cyconix.com> wrote:
> > Ric Klaren wrote:
> > > On 7/11/05, Tarun Khanna <tarunkhanna at gmail.com> wrote:
> > >>The attached grammar produces a non-determinism warning in the 
> following
> > >>production
> > >> factor :
> > >> ( ( LPAREN exp RPAREN ) | IDENT ) (DOT IDENT)* (DOT TAB)?
> > >> |
> > >> TAB
> > >> ;
> > >
> > > Notice that the (DOT IDENT)* may match the empty word e.g. nothing.
> > > Add to that that (DOT TAB)? may also match nothing. Add to that that
> > > the start of both may be a DOT. So antlr has a hard time choosing
> > > between the closure (DOT IDENT)* and the optional part (DOT TAB)?.
> >
> > But what if k is 2, as Tarun said in his original post?
> 
> Not sure didn't follow the first part of the thread, didn't see the
> complete grammar. It may come from surrounding rules, maybe in
> combination with the alternative that only matches a TAB. Would have
> to check all the lookahead sets generated with -diagnostic. When you
> have parts that match nothing or complete rules that match nothing you
> get really unintuitive behaviour in the lookahead sets, that's why we
> have ANTLR to tell us if we might have missed something. Although
> antlr is sometimes a bit overzealous. (version 3 will make life quite
> a bit better...)
> 
> Anycase left factoring is usually a good solution to getting rid of
> those warnings. Also
> in this case you get better performance thanks to the left factoring
> since antlr can decide things by looking ahead one token in stead of
> two (or more).
> 
> Cheers,
> 
> Ric
> 



-- 
Tarun Khanna
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20050712/053e6111/attachment.html


More information about the antlr-interest mailing list