Programming Language Concepts
CS 360-001 Tuesday/Thursday 15:30-16:50 (Rush 209)
CS 360-002 Tuesday/Thursday 14:00-15:20 (Rush 209)
CS 360-003 Tuesday 18:30-21:20 (UCross 151)
Office: University Crossings 106
Office hours: Mondays 4pm–7pm; Thursdays 5pm–6pm.
CLC office hours: Tuesday 12pm–2pm; Thursday 6pm–8pm Allen Yang
CLC office hours: Wednesday 6pm–8pm
Due Monday, February 26, 11:59:59PM EST.
In this assignment, you will implement the $\While$ language from lecture.
You must implement the functions as specified. You may write other helper functions and define test data in your file, but you may not change the functions’ names or the number or order of arguments.
Your changes should be made to the files we have provided as described in each problem below. We have included a non-functional version of every function you must write, so you can also grep the source we have provided to find the function we have asked you to implement.
Note that source files are located in the
This assignment is worth 50 points. There are 51 possible points.
Unlike in lecture, where we represented the interpreter’s state as a function from variables to integers, the code for this homework represents the interpreter’s state as an association list of variables and integer values.
You will need to refer to the lecture slides, the text, and/or your notes for the operational semantics of $\While$ statements.
Complete the definition of the function
evalS, the Haskell implementation of the operational semantics for $\While$ statements, in the file
Modify your interpreter so that it handles the case where a non-existent variable’s value is needed. In the original interpreter, this resulted in the entire interpreter aborting with a call to Haskell’s
error function. Now, your interpreter should return
Nothing when a non-existent variable is looked up in the state. Keep in mind that the non-existent variable could be used deep in some statement, so error handling has to be propagated through the entire interpreter. This is painful! Make your changes in the file
In this problem you will modify the interpreter to log intermediate states during the execution of statements. Evaluating a statement will then produce not only the final state, but a list of all intermediate states. Make your changes in the file
Just like error handling, this change has to be propagated through the entire interpreter. Also painful!
In lecture, we will see new language abstractions that allow us to avoid this pain in both cases.
How long did spend on each problem? Please tell us in your
README.md. You may enter time using any format described here.