CS37 -- Laboratory 11

Due: Thursday, Nov. 19 by 11:59 pm

Email solutions to cfk@cs.swarthmore.edu by Thursday, Nov 19, 11:59 pm. Provide code and evidence of testing. Just provide parts that are different from the clab 29 code provided.


Make your interpreter able to handle programs like this sample:
MC-EVAL==>
(begin
(sum := 0)
(sumsqs := 0)
(i := 1)
(while (< i 6)
(display i)
(sum := (+ sum i))
(display " ")
(isq := (* i i))
(sumsqs := (+ sumsqs isq))
(display isq)
(newline)
(i := (+ i 1))
)
(display "sum is: ") (display sum)
(newline)
(display "sum of squares is: ") (display sumsqs) " "
) ;;; end of the program

1 1 ;;; beginning of the output
2 4
3 9
4 16
5 25
;;; end of while loop
sum is: 15
sum of squares is: 55
MC-EVAL==>

The above program is written in OASwatScheme (Only at Swarthmore Scheme). To your interpreter, you need to add
1) an infix assignment operator :=. You may assume that there is always a space before and after := and that its left operand is a simple symbol. The := operator should be able to define a variable if it does not already exist or mutate a variable if it does already exist.
2) sequence ( begin ) if you have not already done so.
3) newline and display as primitive procedures.
4) strings as self-evaluating. There is a predicate, string?, in Drscheme that helps.
5) the while iteration construct. The semantics of the OASwatScheme while construct (while <pred> <body>) are as follows. You may assume that <pred> is a legal OASwatScheme predicate (i.e. it evaluates to #t or #f). <body> is a nonempty sequence of legal OASwatScheme expressions. The while construct evaluates the predicate <pred> If <pred> evaluates to #t, then <body> is evaluated sequentially. Then <pred> is evaluated again. If <pred> evaluates to #t, then <body> is evaluated again. This is repeated until <pred> evaluates to #f at which time the while statement terminates.

Your task is to modify our interpreter as requested and to email me the changes necessary and some test runs. Do not email me the whole interpreter, just send me what is new.

As of 1 Oct, the final exam for CS37 has been scheduled by the registrar for Wednesday 12/16/2009, 9:00am-12:00pm in SC240. Plan to attend.