simplify method
Possible simplifications:
- a + 0 = a
- 0 + a = a
- a + -(b) = a - b
Implementation
@override
Expression simplify() {
final Expression firstOp = first.simplify();
final Expression secondOp = second.simplify();
if (_isNumber(firstOp, 0)) {
return secondOp;
}
if (_isNumber(secondOp, 0)) {
return firstOp;
}
if (secondOp is UnaryMinus) {
return firstOp - secondOp.exp; // a + -(b) = a - b
}
return Plus(firstOp, secondOp);
//TODO -a + b = b - a
//TODO -a - b = - (a+b)
}