Homework #1: Extending AE
Out: Tuesday, January 10th, Due: Friday, January 20th, 4:30pm


Administrative

This homework is for individual work and submission.

In this submission as well as future homeworks, you are required to have tests that cover your whole code, otherwise your submission will be penalized.

The language for this homework is:

#lang plait

For this problem set, make sure you enable Syntactic test suite coverage: <ctrl>-L to bring up the customization panel and choose Syntactic test suite coverage under Dynamic Properties. With this enabled, uncovered branches in your code will be highlighted.

Submitted code should have comments that describe the function and its type, as well as enough test cases for complete coverage (DrRacket indicates covered expressions with colors for covered and uncovered source code, unless your code is completely covered). Your tests should have the following form:

(test <expression> <expected>)
Important: Your tests should cover your whole code, otherwise the marker will penalize your submission. You should not have any uncovered expressions after you hit run. Note that appeasing the automatic coverage testing is a minimum requirement, and usually more tests are needed

See also the marking rubric for assignments.


1. Infix AE

In class, we have seen the implementation of the AE language. The code is available as ae interpreter. We mentioned the fact that we’re using an intermediate S-expression format for input code, and that this helps in making the syntax and the semantics independent. In this section you will modify only the parser, and leave the evaluator unchanged. Make the language use infix syntax (still fully parenthesized, for simplicity). You will need to change both the BNF definition (the topmost comment) and the code in the parser. Make sure you properly comment your change to the parser. (Hint: this is extremely easy; if you find yourself writing new code, then you’re probably off track.) Your modified interpreter should pass (at least) the following tests
(test (run `3)  3)
(test (run `{3 + 4})  7)
(test (run `{{3 - 4} + 7})  6)
(test (run `{8 * 9})  72)
(test (run `{8 / 2})  4)

2. Divide by Zero

As it stands, the AE evaluator reflects Racket’s behavior for all arithmetic operations. For example, if you try to evaluate:
(run `{5 / 0})
you get a Racket “division by zero” error. Modify the function eval to return +inf.0 (positive infinity) or -inf.0 (negative infinity) as appropriate when attempting to divide by zero. Your modified interpreter should pass (at least) the following tests
(test (run `{-8 / 0})  -inf.0)
(test (run `{8 / {5 - 5}})  +inf.0)
(test (run `{1 / {1 / 0}}) 0.0)

3. Finally

Remember that to be able to submit your solution without penalty, you will need to add enough test cases that cover the code completely.

Define minutes-spent as the number of minutes you spent on your homework.