Homework Assignment 7

Syntactic Abstractions


CS 3540
Programming Languages and Paradigms
Spring Semester 2018


Due: Thursday, March 8 at 8:00 AM


Introduction

For this assignment, you will write code to process simple programs in our little language. It should help you to understand the idea of syntactic abstraction better and to see how much control we can exert over the languages we use at the level of the processor. For this assignment:

Little Language
This assignment works with a version of the little language we saw for the first time in Session 12, processed in Session 13, and extended in Session 15. I have extended it once more, with a simple Racket-like if expression.
Source Files
Download the zipped directory that contains two files, the syntax procedures for the little language and all of the functions we have written for processing programs written in the language. You will extend these files with code you you write for this assignment. Be sure to:
  • update the header block with your personal information,
  • indicate the sections of the code you write or change with comments, and
  • add the names of new syntax procedures you write to the provide clause at the top of that file.
As before, write tests for all the code you write. Put them in a new file homework07-tests.rkt that requires the files of syntax procedures and processors, similar to the test files for previous assignments. The tests are part of the assignment.
Extra Credit Opportunity
I am tired of saying and typing the little language all the time. We could call it LL, but that is boring. Earn an extra-credit point or two by proposing a better name!



Problems

  1. Add constructors to the syntax procedures for the little language. There should be a constructor for each type of expression, with a name that begins with make-. Each constructor should take the parts of the expression and return the corresponding form. For example:
         > (make-varref 'x)
         'x
         > (make-lambda 'arg 'body)
         '(lambda (arg) body)
         > (make-app 'function 'arg)
         '(function arg)
         > (make-let 'var 'val 'body)
         '(let (var val) body)
         > (make-if 'a 'b 'c)
         '(if a b c)
         > (make-lambda 'f (make-app 'f 'x))
         '(lambda (f) (f x))
         > (make-let 'y (make-app 'f 'x) (make-app 'f 'y))
         '(let (y (f x)) (f y))
    

  2. Modify preprocess to use your constructors instead of Racket list expressions.



  3. For Problems 3 and 4, you will extend the little the language to include two new syntactic abstractions, and and or:

              <exp> ::= <varref>
                      | <boolean>
                      | (lambda (<var>) <exp>)
                      | (<exp> <exp>)
                      | (if <exp> <exp> <exp>)
                      | (let (<var> <exp>) <exp>)
                      | (and <exp> <exp>)
                      | (or <exp> <exp>)
    



  4. Write syntax procedures for the new kinds of expression: for each, a type predicate, a constructor, and accessors for the parts of the expression. Name the accessors and->arg1, and->arg2, or->arg1, and or->arg2.

  5. Modify preprocess to translate and and or expressions into equivalent if expressions, following the definitions you saw in your reading. Test your translations by passing programs that contain and and or expressions to the preprocessor, and then passing those expressions to the static analysis functions in the processor.rkt file.



  6. Write a structurally recursive function named (free-vars exp) that takes as input an expression in the little language, exp, and returns a list of all of the variables that occur free in exp. As always, use the syntax procedures for the little language to manipulate expressions in the language.


Deliverables

By the due time and date, submit the following files:

If you have a file of utility functions, you may submit that as well.

Be sure that your submission follows the submission requirements.



Eugene Wallingford ..... wallingf@cs.uni.edu ..... March 4, 2018