You need to start looking at
Operator associativity - Wikipedia, the free encyclopedia[
^]
"+" is both left- and right- associative, so
a + b + c
can be evaluated in any order, so your evaluator would be free to assign a "fixed/variable" value to each part of the expression and rearrange it to "group" the fixed and variable parts:
100 + var1 + 200
F + V + F
therefore:
100 + 200 + var1
F + F + V
is equivalent
Exactly how you do that in your code I can't say: I have no idea of how it works. But consider adding an associativity property to your operators, and it should give you the beginnings of what you want.