[antlr-interest] Advice with backtracking/ambiguity

Jim Idle jimi at temporal-wave.com
Wed Jun 2 14:41:38 PDT 2010


This isn't left factored, it is doing the lookahead that you require to distinguish the two. In v4 this will be different, but for now, this is what you will need to do.

Or, don't try to do it in the lexer at all and construct parser rules for it.

Jim

> -----Original Message-----
> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> bounces at antlr.org] On Behalf Of Ken Williams
> Sent: Wednesday, June 02, 2010 2:29 PM
> To: antlr-interest at antlr.org
> Subject: Re: [antlr-interest] Advice with backtracking/ambiguity
> 
> Jim Idle (ji... at temporal-wave.com) wrote:
> 
> > You need:
> >
> > fragment DIGITS : ('0'..'9')+ ;
> > DATE
> > : DIGITS
> >   (
> >       (SLASH DIGITS SLASH DIGITS)=> SLASH DIGITS SLASH DIGITS
> >     | {$type = DIGITS; }
> > ;
> >
> > SLASH : '/' ;
> 
> Thanks.  But it seems like it'll get nasty pretty quick when I put this
> back
> into the "real" grammar I'm working on.  If I have to left-factor
> everything
> I'll be rather confused.
> 
> Is there not a way besides factoring?  In TheBook on page 299 it talks
> about
> "rather than left-factor the grammar, making it less readable...", and
> I
> tend to agree in this case.
> 
> --
> Ken Williams
> Sr. Research Scientist
> Thomson Reuters
> Phone: 651-848-7712
> ken.williams at thomsonreuters.com
> 
> 
> 
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-
> email-address





More information about the antlr-interest mailing list