[antlr-interest] Making a distinction between float and int calculation
stevenraemaekers at gmail.com
Sat Jan 23 08:36:59 PST 2010
In my grammar there should be an evaluator for numeric expressions. These
numeric expressions should return an integer, or a float, depending on the
contents of the expression.
3 + 2.0: should return float
3 + 2: should return integer
2.0 + 3.0: should return float
1 / 3: should return float
4 / 2: should return int
In my grammar there is only one rule for a numeric expression. I do not know
whether I should duplicate the entire operator precedence rules for the
distinction between float and int.
The following statements are part of my grammar:
: numericexpression (BOOL^ numericexpression)*
: mult ((PLUS^ | MINUS^) mult)*
: atom ((MULTIPLY^ | DIVIDE^) atom)*
| LEFTPAREN expression RIGHTPAREN
-> ^(EXPRESSION expression)
Does anybody have a idea how I should take care of this distinction between
float and int? Or is this distinction even necessary?
More information about the antlr-interest