simplify method

  1. @override
Expression simplify()
override

Possible simplifications:

  1. a + 0 = a
  2. 0 + a = a
  3. 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)
}