[antlr-interest] Advice with backtracking/ambiguity

Jim Idle jimi at temporal-wave.com
Wed Jun 2 13:12:16 PDT 2010


And turn of the backtracking option of course..

Jim

> -----Original Message-----
> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> bounces at antlr.org] On Behalf Of Jim Idle
> Sent: Wednesday, June 02, 2010 1:11 PM
> To: antlr-interest at antlr.org
> Subject: Re: [antlr-interest] Advice with backtracking/ambiguity
> 
> Remember antlr.markmail.org as it will give you lots of examples of
> this. You need:
> 
> fragment DIGITS : ('0'..'9')+ ;
> DATE
> : DIGITS
>   (
>       (SLASH DIGITS SLASH DIGITS)=> SLASH DIGITS SLASH DIGITS
>     | {$type = DIGITS; }
> ;
> 
> SLASH : '/' ;
> 
> 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 1:04 PM
> > To: antlr-interest at antlr.org
> > Subject: [antlr-interest] Advice with backtracking/ambiguity
> >
> > Hi,
> >
> > Here's a simple grammar demonstrating something I'm working with:
> >
> > ------------------------------
> > grammar testg;
> >
> > options {
> >     backtrack=true;
> >     memoize=true;
> >     output=AST;
> > }
> >
> > cite    :    token+ EOF ;
> >
> > token    :    DATE | SLASH | DIGITS ;
> >
> > DATE    :    DIGITS SLASH DIGITS SLASH DIGITS ;
> >
> > WS    :    ( ' ' | '\t'| '\f' | '\n' | '\r' ) {skip();} ;
> >
> > SLASH    :    '/' ;
> > DIGITS    :    ('0'..'9')+ ;
> > --------------------------------
> >
> >
> > As you can see, there's an ambiguity with DATE.  What I'm trying to
> do
> > is to
> > use the DATE rule when it can succeed, and use DATE & SLASH
> otherwise.
> 
> 
> 
> 
> 
> 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