Out: Saturday, 12 April 2008
Due: 5 PM Friday, 18 April 2008
Submission: Individual
This assignment is to be done individually, not in pairs.
The main goal of this assignment is to give you some practice on a few problems that would have made good questions for the final exam.
The first two tasks involve adding features to the SIMPLE programming language by modifying an interpreter. You should submit a single interpreter that contains all of the modifications you made for the first two tasks.
For the other tasks, you will not make any changes to any interpreters; you will merely answer questions.
Program | ::= |
Definition … Expression | a-program (defns exp1) |
Definition | ::= |
define Identifier = proc (
Identifier … ) Expression |
proc-definition (id bvars body) |
Expression | ::= |
Number | const-exp (num) |
::= |
Identifier | var-exp (var) |
|
::= |
null |
null-exp () |
|
::= |
Unop( Expression) |
unop-exp (op exp1) |
|
::= |
Binop( Expression
, Expression) |
binop-exp (op exp1 exp2) |
|
::= |
if Expression
then Expression
else Expression |
if-exp (exp1 exp2 exp3) |
|
::= |
( Expression
Expression …
) |
call-exp (rator rands) |
|
Unop | ::= |
car |
op-car () |
::= |
cdr |
op-cdr () |
|
::= |
null? |
op-null? () |
|
Binop | ::= |
+ |
op-plus () |
::= |
- |
op-minus () |
|
::= |
* |
op-times () |
|
::= |
< |
op-less() |
|
::= |
= |
op-equal () |
|
::= |
> |
op-greater () |
|
::= |
cons |
op-cons () |
expval
datatype:
;;; an expressed value is either a number, a boolean, a procval, ;;; an empty list, or a pair whose cdr is a list. ;;; ;;; a list is one of ;;; - an empty list ;;; - a pair whose cdr is a list (define-datatype expval expval? (num-val (value number?)) (bool-val (boolean boolean?)) (proc-val (proc proc?)) (null-val) (pair-val (ar expval?) (dr (letrec ((list? (lambda (e) (and (expval? e) (cases expval e (null-val () #t) (pair-val (a d) (list? d)) (else #f)))))) list?))))
cons
and null
alone. Add a list-constructing syntax to the interpreter for
your extension of the SIMPLE language from the previous task.
This syntax consists of the word list
followed by a possibly empty sequence of expressions that are
separated by commas and enclosed in parentheses.
There is no limit to the number of expressions.
Here is an example:
list(list(), list(1,2), list(1,2,3,4), list(1,2,3,4,5,6))That example is equivalent to:
cons(null, cons(cons(1,cons(2,null)), cons(cons(1,cons(2,cons(3,cons(4,null)))), cons(cons(1,cons(2,cons(3,cons(4,cons(5,cons(6,null)))))), null))))
τ ::= int ::= bool ::= list[τ] ::= ( -> τ ) ::= ( α -> τ ) α ::= τ ::= τ * αAnswer the following questions:
null
?cons
?null
, cons
,
and the definition you wrote for Task 3.
If you answered "no" to any of the three questions in Task 4,
then describe an extension to the notation that would be able
to express the types of null
, cons
,
and the procedure you defined for Task 3.
You are given three different interpreters for the SIMPLE programming language:
You may use any of those three interpreters as your starting point for Tasks 1 and 2. By now, you should know how to copy the code for one of those interpreters into one of your own directories.
tests.scm
file that includes the tests you wrote for Tasks 1 and 2.
Those tests should be run when the top.scm
file is required.
mp10.txt
that contains your answers
for Tasks 3, 4, and 5.
Last modified: 13 April 2008