[antlr-interest] newbie problem about expressions & number representations

Jim Idle jimi at temporal-wave.com
Fri Dec 11 17:48:33 PST 2009


This is ANTLR 2.7, so it is different. However it isn't always longest match, the order of rules can also affect things. Basically it is always better to left factor, just a matter of getting used to the idea.

Jim

> -----Original Message-----
> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> bounces at antlr.org] On Behalf Of David-Sarah Hopwood
> Sent: Friday, December 11, 2009 4:38 PM
> To: antlr-interest at antlr.org
> Subject: Re: [antlr-interest] newbie problem about expressions & number
> representations
> 
> Gavin Lambert wrote:
> > At 13:41 11/12/2009, Duygu Altinok wrote:
> >> INT :    (DIGIT )+
> >>     ;
> >>
> >> FLOAT
> >>     :   ('0'..'9')+ '.' ('0'..'9')* (EXPONENT)?
> >>     |   '.' ('0'..'9')+ (EXPONENT)?
> >>     |   ('0'..'9')+ EXPONENT
> >>     ;
> >
> > These two rules have a common left prefix, and are thus ambiguous.
> > Even ANTLR v3 with * lookahead has trouble with this; ANTLR v2's
> fixed
> > (typically small) lookahead doesn't stand a chance.
> 
> I thought lexer rules were supposed to find the longest match?
> How can they do that if they're unable to handle common left prefixes?
> 
> (I have the impression that "longest match" may not be quite accurate,
> but if so, I've never seen the actual behaviour documented precisely.)
> 
> --
> David-Sarah Hopwood  ⚥  http://davidsarah.livejournal.com






More information about the antlr-interest mailing list