CS558 Homework #4
Due 8:00 AM, Monday, Feb 1, 2016

Homework must be submitted via D2L. All submitted files (5 for this assignment sol4A1.e3 , sol4A2.e3, sol4A3.e3, sol4A.hs, and sol4B.e4) must be submitted in the appropriate D2L directory in the drop box HW4.It is your responsibility to submit the homework in the proper format with the proper names. For example.

-- Homework 4  Tom Smith   tom_smith@gmail.com

All programs mentioned can be downloaded from the this document

Questions in this homework are based upon two different languages. The first part (A) is based upon the E3 language from Homework 3. The second part (B) is based upon the language E4 (which is like E3 with 'local'; constructs for characters; and constructs for raising and handling exceptions). Its "concretized" abstract syntax is given by the following grammar:

prog := '(' { def } ')' exp
def := globaldef | fundef
globaldef := '(' 'global' var exp ')'
fundef := '(' 'fun' fname '(' { var } ')' exp ')'
exp := var
| int
| '(' ':=' var exp ')'
| '(' 'while' exp exp ')'
| '(' 'if' exp exp exp ')'
| '(' 'write' exp ')'
| '(' 'block' { exp } ')'
| '(' '@' fname { exp } ')'
| '(' '+' exp exp ')'
| '(' '-' exp exp ')'
| '(' '*' exp exp ')'
| '(' '/' exp exp ')'
| '(' '<=' exp exp ')'
| '(' 'pair' exp exp ')'
| '(' 'fst' exp ')'
| '(' 'snd' exp ')'
| '(' 'ispair' exp ')'

| '(' 'local' '(' { var exp } ')' exp ')'
| '(' 'try' exp { '(' '@' hname { exp } exp ')' } ')'
| '(' 'raise'  hname { exp } ')'

| char
|  '(' '=' exp exp ')'
|  '(' 'ischar' exp ')'


fname := letter { letter | digit }
var := letter { letter | digit }
hname := letter { letter | digit }

As before, comments may be included by enclosing them between comment braces '{-' and '-}' characters, and they may be nested.