CS 341 - Principles of Programming Languages
Homework #7

Due: at the beginning of class 13

Note: This work is to be done in pairs.  Each pair will submit one assignment.  Although you may divide the work, both team members should be able to present/describe their partner's work upon request. 

To submit this homework, change into the directory containing all necessary files: MiniScheme2.jj and supporting abstract syntax tree .java files, and enter the command "submit341 ms2".

MiniScheme Project Phase 2

In this phase of the project, you will extend phase 1 to include Scheme variables, define, set!, and let.  Again, we will restrict ourselves at this stage to having only integers.  All specifications for variable names, and basic syntactic structures conform to the R5RS specification.  Additionally, the following error cases will need to be handled as follows.

(define a 1)
(define a 2)  ; This is treated as (set! a 2). (R5RS p.16)
(let ()
  (define a 3) ; This creates a local variable a.
  (define a 4) ; This line is the only problem.
  a)
(let ((a 1)
      (a 2))
  a)

Grammar

Grammar notes:

<program> --> { <definition> | <expression> }*

<definition> --> ( define <variable> <expression> )

<variable> --> <any <identifier> that isn't also a keyword>
<identifier> --> <initial> { <subsequent> }*
<initial> --> [a-z!$%&*/:<=>?^_~]
<subsequent> --> <initial> | <digit> | [+-.@]
<digit> --> [0-9]

<expression> --> <variable>
| <literal>
| <assignment>
| <derived expression>

<literal> --> <integer>
<integer> --> { + | - }? { <digit> }+

<body> --> { <definition> }* { <expression> }+

<assignment> --> ( set! <variable> <expression> )

<derived expression> --> ( read )
| ( write <expression> )
| ( newline )
| ( + <expression> <expression> )
| ( - <expression> <expression> )
| ( * <expression> <expression> )
| ( quotient <expression> <expression> )
| ( let ( { <binding spec> }* ) <body> )

<binding spec> --> ( <variable> <expression> )