Homework 7

This homework is based on homework 5 and 6. This version includes some simplifications made on Sat 08 May 2021 10:28:44 AM PDT.

Problem

You are asked to implement in Haskell the prettyprinter and interpreter of the "while language" of homework 5 and 6.

Prettyprint and execute the factorial program proposed by the instructor and another program of your choice (can be the same as that of homework 5 and/or 6, or another one).

Submit the same items as homework 5 and 6: (1) your code and (2) a trace of prettyprinting and executing your "while programs."

Hints and Simplifications

Exclude the Output statement from the language.

The function for interpreting a "while program" is likely to have more arguments than in the OO solution. In particular, you should both pass as an argument and return the symbol table holding the bindings of the "while program" variables. This provides the same information as the Output statement.

The function for prettyprinting a program should construct a string represention of the "while program" and output it as follows:

          putStrLn (prettyPrint factorial) 
where putStrLn is a library function available to your program. For example, try the following in the Haskell interpreter:
          putStrLn "line1\n  line2"