[antlr-interest] Advice with backtracking/ambiguity
Jim Idle
jimi at temporal-wave.com
Wed Jun 2 13:11:09 PDT 2010
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.
More information about the antlr-interest
mailing list