The original version of the
tests.scm
file provided for this assignment had an incorrect
result for the multiple-shadowing-in-rhs
test.
The correct result of that test is 3, not 15.
The test has been corrected in the current version of the
tests.scm
file.
Please use the corrected file.
Out: Saturday, 5 April 2008
Due: 5 PM Friday, 11 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 experience with continuation-passing interpreters.
The first three 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 three tasks.
For the last two tasks, you will not make any changes to any interpreters; you will merely answer questions. Your answers may include a small amount of code, but not a complete program.
let
expressions that bind one variable.
(Hint: For Task 2, you will modify
let
expressions to bind any number of variables,
so you can complete Task 1 just by completing Task 2.
Nonetheless we recommend an incremental software development
process in which you complete Task 1 before Task 2.)
let
expressions that bind any number
of variables.
return
expressions.
The full syntax of the language you will implement is
let
and return
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) |
|
::= |
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) |
|
::= |
let Identifier
= Expression
Expression |
let-exp (ids exps body) |
|
::= |
return Expression |
return-exp (exp1) |
|
Binop | ::= |
+ |
op-plus () |
::= |
- |
op-minus () |
|
::= |
* |
op-times () |
|
::= |
< |
op-less() |
|
::= |
= |
op-equal () |
|
::= |
> |
op-greater () |
return expwith continuation cont is the semantics of
exp
with the continuation that was most recently used
to evaluate the procedure body within which the
return
expression appears;
hence return exp
ignores
its normal continuation cont.
If a return
expression is executed outside
the body of any procedure, then an error must be
signalled and the program's execution terminated.
define executeSimple = proc (n) …is the definition of a SIMPLE procedure that
n
is the Gödel
number of a well-typed SIMPLE program of type int
;
int
,
and that SIMPLE program returns r as its result,
then executeSimple
also returns r;
int
,
and that SIMPLE program does not terminate,
then executeSimple
also does not terminate;
int
,
then executeSimple
does not terminate.
choose
expressions,
consider whether it is possible to define a boolean-valued procedure that
int
;
(executeSimple n)
returns an integer;
choose
expressions,
consider whether it is possible to define a boolean-valued procedure that
int
;
(executeSimple n)
returns an integer;
You are given three different interpreters for the
SIMPLE programming language,
and you are also given an interpreter for the SIMPLE language
extended with try/catch
and throw
:
You may use any of those four interpreters as your starting point
for Tasks 1, 2, and 3. (Hint:
If you use the interpreter that implements
try/catch
and throw
, you will need to
remove those two features.)
By now, you should know how to copy the code for one of those
interpreters into one of your own directories.
You are also given a set of tests for Tasks 1, 2, and 3.
tests.scm
file that includes the tests you wrote for Tasks 1, 2, and 3.
Those tests should be run when the top.scm
file is required.
mp9.txt
that contains your answers
for Tasks 4 and 5.
Last modified: 7 April 2008