There are a lot of things going wrong in your Java code:
leftVal.getType().toString() == "DOUBLE"
Never do string equality checks using ==
!
Read this: How do I compare strings in Java?, and truly understand it.
But you shouldn't compare the strings to begin with. Compare the integer types instead:
leftVal.getType() == ExpressionParser.DOUBLE
And this makes little sense to me:
String i = "100";
if (i.contains(".")){
...
The fact that you get a no viable alternative message is because your input "10"
is being tokenized as an ID
. This is because the ID
token matches only digits, just like the DIGIT
rule:
ID: [a-zA-Z0-9]+;
...
DIGIT: [0-9]+ ;
and since ID
is defined before DIGIT
, it get precedence. Either include ID
as an numExpr
alternative, or let the ID
token start with a letter:
ID: [a-zA-Z] [a-zA-Z0-9]*;