Marist-CMPT331-TOPL / adder

Adder is a small but usable subset of the Python language. It is named for the Blackadder comedy series, much as the Python language is named for Monty Python.
MIT License
0 stars 2 forks source link

Interpreter support for binary operations #35

Open Tientuine opened 1 year ago

Tientuine commented 1 year ago

@Marist-CMPT331-TOPL/students

The interpreter should be able to handle binary operations by implementing the corresponding semantic rule(s) to compute an Answer. This is one part of a multi-part task that should be divided up among several people, coordinated carefully.

  1. [ ] Declare a helper function called valueOfBop that takes a BinaryOp and two expressed values and returns an appropriate expressed value. Initially leave this function undefined, so that each case may be implemented by various people.
  2. [ ] Add a case to valueOf for BinaryExpr that relies on the helper valueOfBop function. This implementation should compute the values of the two operand expressions, accounting for state changes appropriately, and then pass the values into the helper function.
Tientuine commented 1 year ago

@Stubeans It turns out that I approved and merged your PR prematurely. Can you make the changes described below and then open another PR? Thanks.

  1. Fix the pattern for binary expression on the left-hand side of your valueOf rule. The correct constructor name is BinaryExpr, not BinaryExp.
  2. Fix the return value on the right-hand side of your valueOf rule. It needs to be an Answer, which is a pair containing a value and a store. Right now you're just returning the value, and the store is missing.
  3. Finally, move the undefined case for valueOf to below your case, otherwise the interpreter will never reach your case.

With these few fixes, this will be done.

Tientuine commented 1 year ago

@Stubeans Bump.

@Stubeans It turns out that I approved and merged your PR prematurely. Can you make the changes described below and then open another PR? Thanks.

1. Fix the pattern for binary expression on the left-hand side of your `valueOf` rule. The correct constructor name is `BinaryExpr`, not `BinaryExp`.

2. Fix the return value on the right-hand side of your `valueOf` rule. It needs to be an `Answer`, which is a pair containing a value and a store. Right now you're just returning the value, and the store is missing.

3. Finally, move the `undefined` case for `valueOf` to below your case, otherwise the interpreter will never reach your case.

With these few fixes, this will be done.