MCS-287 Lab Project 3: Parameter Passing
The crux of this lab is to compare interpreters for four different
variants of a programming language, which differ in how parameters are
passed (and how arrays are stored), as described in chapter six.
However, before you can make these four variant interpreters, you will
need to have a basic interpreter to build the variations on. This is
what chapter 5 accomplishes, and will be the initial focus of your
work. Thus you can and should get started long before we get to
chapter 6 in class. All the exercises drawn from chapter 5 should be
done by April 6th.
Your project report should reflect your final product, rather than
focusing on each incremental step along the way. Your project report
should explain your comparison of parameter passing
variations, and the functionality of your interpreter
procedures that allows you to make these comparisons. Don't go into
the details in English: your audience can read Scheme. You may
assume your audience is familiar with the EOPL book and
the supplemental notes that are on our course web page.
-
As a starting point I have provided you a working interpreter,
including
if and let expressions. (It is
Figure 5.3.2, with all the supporting code.) This interpreter is linked from the web version of
this lab handout. You can use the interpreter in either of two ways:
-
You can use the procedure
run, passing in a character
string which is the expression to evaluate. For example,
(run "let x = 3 in *(x, x)")
would evaluate to 9.
-
You can use the procedure
read-eval-print, with no
arguments, which starts a read-eval-print loop (REPL) going for the
interpreted language. Each time it prompts, you can type in an
expression in the language. You can split the expression over as many
lines as you like, but need to type a semicolon at the end of it. For
example,
(read-eval-print)
--> let n = 5 in *(n, n);
25
-->
where the two arrows are prompts printed by the REPL, and the 25 is
the value it prints. In Dr Scheme, the REPL takes place in a box,
with the output and input in different colors. When you are done
using the REPL, you can press the Break button to quit.
Familiarize yourself with this interpreter, trying out expressions
such as those on pages 145, 146, and 148.
-
You will need in later portions of this lab to extend the evaluator to
handle extra kinds of expressions, such as procedure creation
(
proc) in section 5.4 and variable assignment in section
5.5. The parser I have provided already understands the concrete
syntax of all these kinds of expressions and produces the
corresponding ASTs (record types). For testing and debugging you may
find it useful to just parse, or just evaluate, rather than always
doing the two together. You can just evaluate using
eval-exp, which you will be extending during the lab. To
just parse, you have two options, similar to the two options shown
above.
-
You can apply
character-string-parser to a string which
is an expression, and you will get back the AST as a record.
-
You can use the procedure
read-print, which acts like
read-eval-print except that it just shows the AST for
each expression you enter, rather than doing any evaluation.
Try these two out to make sure you understand the tools you have
available.
-
Do exercises 5.1.3 and 5.1.4 on page 145.
-
Do exercise 5.4.4 on page 155.
-
Do exercise 5.5.1 on page 156. (You won't need to alter the
let clause, contrary to what the exercise says, if you
removed it entirely in doing exercise 5.4.4.) Also, you should add
variable assignment, as in figure 5.5.1.
-
Do exercise 5.5.4 on page 158 and add some primitive procedures for
performing output.
-
Do exercise 5.5.5 on page 159, with two changes:
- Use the
add-binding-to-env! procedure I added to the
environment ADT. (Note that this won't work in MIT-scheme yet,
since mitmacros.scm fails to implement setters.)
- Always add a new binding to the global (initial) environment, even
if the binding is already present in the environment.
-
If you have time and ability, do exercise 5.6.5 on page 167. This
makes the language more pleasant, but is not needed for the project on
parameter passing mechanisms. You can earn an A- without this
exercise.
- Recheck that you have a new enough printing of the text.
Note that you may have an outdated version of chapter 6. If the
page numbers for the remaining exercises in this lab don't match up,
you should obtain in a new copy of chapter 6 from me or from the
book's
ftp site.
The 4th printing and earlier are outdated. The 6th printing of the book
and later are new. (If you have the 5th, I don't know.)
-
Do exercise 6.1.1 on page 183. Use my section 6.1 notes.
``Implement this interpreter and run some examples.''
-
Do exercise 6.1.2 on page 186. Use my section 6.1 notes.
``Implement the direct array interpreter and run some examples.''
-
Do exercise 6.2.3 on page 193. Use my section 6.2 notes, not
literally figure 6.2.1.
``Implement the interpreter of this section, which uses
call-by-reference and indirect arrays.''
-
Do exercise 6.2.4 on page 193. Again, use my notes as a guide.
``Modify the interpreter of this section to support call-by-reference
with direct arrays. What does it mean to pass an array element by
reference with the direct model?''
-
Finally, for the crux of the lab project, write an expression (in the
language of your interpreters) that has four different numerical
values, depending on which of the four interpreters of exercises
6.1.1, 6.1.2, 6.2.3, and 6.2.4 you use. Explain (using diagrams) how
the four different values are arrived at, and demonstrate using your
interpreters that these four values are indeed produced.