[antlr-interest] Why doesn't this work?
Gavin Lambert
antlr at mirality.co.nz
Wed Apr 8 12:34:33 PDT 2009
At 03:12 9/04/2009, Indhu Bharathi wrote:
>INT_FLOAT_PATTERN
> : (NUMBER DOT NUMBER LETTER ) => NUMBER DOT NUMBER LETTER
> { $type=PATTERN; }
>
> | ( NUMBER DOT NUMBER ) => NUMBER DOT NUMBER
> { $type=FLOAT_LIT; }
>
> | (NUMBER) => NUMBER
> { $type=INT_LIT; }
>
> ;
I'm not sure why that isn't working, but you might want to
left-factor it a bit more than you have:
INT_FLOAT_PATTERN /* or you could just make this INT_LIT */
: NUMBER { $type = INT_LIT; }
( (DOT NUMBER) => DOT NUMBER { $type = FLOAT_LIT; }
(LETTER { $type = PATTERN; })?
)?
;
This should be more efficient (because it will only do the
lookahead-backtracking once), and hopefully it'll actually work
(though I haven't tested it).
More information about the antlr-interest
mailing list