CS 360
Winter 2018
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)

Instructor:
Geoffrey Mainland
mainland@drexel.edu
Office: University Crossings 106
Office hours: Mondays 4pm–7pm; Thursdays 5pm–6pm.
Teaching Assistant:
Xiao Han
CLC office hours: Tuesday 12pm–2pm; Thursday 6pm–8pm
Allen Yang
CLC office hours: Wednesday 6pm–8pm
Warning! This material is for an old version of the course.

Homework 5: Implementing Semantics

Due Monday, February 26, 11:59:59PM EST.

Accept this assignment on GitHub Classroom here. The standard homework instructions apply.

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 src subdirectory.

This assignment is worth 50 points. There are 51 possible points.

Notes

Problem 1: Implement operational semantics (10 points)

Complete the definition of the function evalS, the Haskell implementation of the operational semantics for $\While$ statements, in the file src/While/Interpreter.hs.

Problem 2: Handle errors in your interpreter (20 points)

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 src/While/ErrorInterpreter.hs.

Problem 3: Add support for logging intermediate states to your interpreter (20 points)

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 src/While/LoggingInterpreter.hs.

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.

Problem 4: Homework Statistics (1 point)

How long did spend on each problem? Please tell us in your README.md. You may enter time using any format described here.