Based on the context of the leftmost part of an expression I would like to change what occurs in the rest of the expression.
left + middle + right
| \
left middle + right
| | |
middle + right
If left is a string literal, the '+' equates to exactly a '+'.
If left is a number, the + is used as BigDecimal.add(BigDecimal).
All numbers picked up by the parser are being converted into BigDecimal numbers. Big Decimal does not allow the following:
(new BigDecimal(1))+(new BigDecimal(1))
Instead, BigDecimal requires the use of .add():
(new BigDecimal(1)).add((new BigDecimal(1)))
This becomes a problem when I am concatenating strings and numbers. If I just make every '+' between two numbers a number1.add(number2) then concatenating them wouldn't work as intended.
My grammar cyntax:
write "hello " + 1 + 2
Desired output:
System.out.println("hello "+(new BigDecimal(1))+(new BigDecimal(2)));
This will print:
hello 12
I also want to be able to do math with my #'s. When I see 1+2 without a string in the rest of the expression I would like to do BigDecimal addition:
(new BigDecimal(1)).add((new BigDecimal(2)))