TrikkStar/ProgLangAssignments

Implement arithmetic operators

Closed this issue · 0 comments

  • Add a new exprC type variant ArithC that takes a "string" for the operator symbol, and two exprCs for the two operands.
  • Implement a new "helper method" called arithEval with type string -> value -> value -> value that takes the operator and two values. If the two values are not both Nums then it should raise an interpreter exception. If they are then it should perform the appropriate operation and return a "value" of the result. The operators we will allow will be "+", "-", "*" and "/". It should throw an interpreter error if the operator symbol is not one of these. It should also throw an interpreter error about division by zero if the operator is division and the denominator is 0. Remember that in our arithmetic world, all numbers are floating point numbers.
  • Add a new case in interp to handle ArithC cases by evaluating the two operands in the correct order, then calling the arithEval helper method.
  • Add tests to ensure these cases are handled properly.
  • Add a new exprS type variant ArithS that models ArithC.
  • Add a new case in the desugarer to convert ArithS to ArithC.
  • Add tests for the desugaring.