Assignment 5

CS 550 Programming Languages
Instructor: Jeremy Johnson 
Due date: Thursday May 23 at 9am

Scheme Interpreter (100 points)

This assignment explores the scheme interpreter and the environment model from SICP discussed in Scheme Interpreter lecture from functional programming lecture

Background Information

Background information is obtained in lecture on functional programming and the operational semantics of scheme (scheme interpreter). As always refer to the documentation for MIT/GNU Scheme as needed.

What to do

  1. Implement an interpreter for the proposition calculus using scheme. You should use the following syntax Your interpreter should take a boolean expression and an environment and return #t or #f. If an undefined variable is encountered then return the symbol error. Your interpreter should first transform boolean operators (and and or) with more than two arguments to nested operators with just two arguments (similar to the way cond is handled in the scheme interpreter).
  2. Use your boolean expression interpreter from question 1 to prove tautologies. I.E. a boolean expression that is true for all possible values of the variables. E.G. (or P (not P)), (equiv (or P Q) (or Q P)), (equiv (or P Q) (or P (and (not P) Q))). Your prover should generate all possible values for the variables occuring in the boolean expression [all possible bindings], and using your interpreter, check to verify that the expression is true for all possible variable bindings.
  3. Trace scheme interpreter from SICP using as input the following two expressions [you will have to add =, *, - as primitive procedures for this to work].
          (define (fact n)
             (if (= n 0) 1 (* n (fact (- n 1)))))
          (fact 3)
    You should indicate exactly how the interpreter interprets this code.
  4. Modify the SICP interpreter to use dynamic instead of static scope. Provide an example where the same code provides two different answers depending on which scoping rule is used.
  5. Implement an interpreter for the mini language in scheme. Use the following representation for mini language programs.
    1. prog -> stmt-list
    2. stmt-list -> (stmt-seq)
    3. stmt-seq -> stmt | stmt stmt-seq
    4. stmt -> assign-stmt | if-stmt | while-stmt
    5. assign-stmt -> (assign identifier expr)
    6. if-stmt -> (if expr stmt-list stmt-list)
    7. while-stmt -> (while expr stmt-list)
    8. expr -> integer | identifier | (+ expr expr) | (- expr expr) | (* expr expr)

How to submit

Students should submit their solution electronically using BbVista. Submit a gzipped tar file, called A5.tar.gz. The tar file should contain source code, instructions how to run your programs, sample input and output files, and a README file. The README file should describe all files that are included, contain instructions how to build and use the code, and outline how the code works. The README file should also contain a list of all group members and the group leader for the submitted assignment. You should also indicate how you tested your code. If your program is not working, you should clearly state this in the README file. All scheme functions should be written in scheme and must work with MIT-Scheme. Code should be documented (clear specifications and comments for any tricky parts of the code). Those questions that involve hand computations or proofs should be submitted as pdf or text files whose name indicates the question.