[antlr-interest] lexer: matching float vs int

John B. Brodie jbb at acm.org
Tue Sep 9 10:02:26 PDT 2008


Greetings!

On Tuesday 09 September 2008 12:19:30 pm Olya Krachina wrote:
> I still get the same error, even with your suggestion.
>
> Quoting Chris Rebert <cvrebert at gmail.com>:
> > I think you might need to left-factor here.
> > Have you tried:
> >
> > FLOAT: INT? '.' INT;
...snipped...
> > On Sep 8, 2008, at 9:01 PM, Olya Krachina <okrachin at purdue.edu> wrote:
...snipped...
> > > INT:      ('0'..'9')+;
> > > FLOAT:    ('0'..'9')*('.')('0'..'9')+ ;

you might try:

INT : DIGIT_SEQ ( '.' DIGIT_SEQ { $type = FLOAT; } )? ;
FLOAT : '.' DIGIT_SEQ ;
fragment DIGIT_SEQ : ( '0' .. '9' )+ ;



More information about the antlr-interest mailing list