CS 342 Additonal Homework for Chapter 1 Due Mon: Feb 10 1. (to make up for problem 1 on page 18) Do problem 2 on page 18 of Kamin's book. 2. (to make up for problem 4 on page 18) Do problem 6 on page 19 of Kamin's book. For this problem, you may assume that the argument will be a nonnegative number that is not too big. 3. 4. (to make up for problem 7 on page 19). Translate the following Pascal Program into a series of "inputs" in the the langauge of chapter 1. program P(input, output); var i: integer; function CallsQ (i,j: integer): integer; begin Q; j := i*i; CallsQ := j end; procedure Q; begin i := i+1 end; begin i:= 3; writeln(CallsQ(1,i)); end. What output do you get when you run your translation using the chapter 1 interpreter? 5. (these were extra credit suggestions) 6. 7. (To make up for the "for loop problem", exercise 9 on page 19). Add a control operation called "localize" to the language of chapter 1. (localize variable+) should put the variables named in the list after "localize" in the local environment with their values from the global environment. As an example, the following session shows what happens. -> (set x 3) 3 -> (set y 4) 4 -> (set z 5) 5 -> (define foo () (localize x) (set x 10) (set y (* x x))) -> (foo) 100 -> x 3 -> y 100 If you execute (localize v) when v does not have a value, you should give the same error message Undefined variable: v as occurs when evaluating a variable that has no value. Print out only the parts of the code that have to be changed for this (use the Unix diff command), and be sure to describe in English the differences, and to test your program. You will find the source for the interpreter in /home/cs342/public/src/chap.1/chap1.p Make a copy using the Unix cp command and then edit your copy. (Note, this interpreter does not have the ``load'' command, it's exactly the same as in the book.)