[antlr-interest] Please advice about float
Martin Probst
mail at martin-probst.com
Mon Sep 19 13:11:35 PDT 2005
Hi,
> I understand your point and agree that perhaps the implication is not
> ideal. However in my parser I want to sometimes parse INT's and other
> times REAL's and not NUMBER's that can be either.
You can set the type of a token within the rule, e.g.:
NUMBER:
INT ( FLOATPART { $setType(FLOAT);})?
FLOATPART:
'.' INT { $setType(FLOAT); }
So if you just have an INT, then the corresponding token will be a
NUMBER, but if it goes on into the FLOATPART parentheses the type will
be set to FLOAT. I made the rule FLOATPART public with a type setter so
that it's also possible to parse ".5" as a FLOAT.
Martin
More information about the antlr-interest
mailing list