You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.1 KiB

  1. /*!! Expression */
  2. /*! # Addition */
  3. /*!- Header */
  4. package expression;
  5. /*!
  6. An `Addition` consists of a `leftHandSide` and a `rightHandSide` expression, which are supposed to be added.
  7. For example
  8. new Addition(new Identifier("x"), new Int(2))
  9. represents the code
  10. x + 2
  11. */
  12. public class Addition extends Expression {
  13. public final Expression leftHandSide;
  14. public final Expression rightHandSide;
  15. public Addition(Expression leftHandSide, Expression rightHandSide) {
  16. this.leftHandSide = leftHandSide;
  17. this.rightHandSide = rightHandSide;
  18. }
  19. /*!- String serialization */
  20. @Override
  21. public String toString() {
  22. return "(" + leftHandSide + " + " + rightHandSide + ")";
  23. }
  24. /*!- Generated equals implementation */
  25. @Override
  26. public boolean equals(Object o) {
  27. if (this == o) return true;
  28. if (o == null || getClass() != o.getClass()) return false;
  29. Addition addition = (Addition) o;
  30. if (!leftHandSide.equals(addition.leftHandSide)) return false;
  31. return rightHandSide.equals(addition.rightHandSide);
  32. }
  33. }