hw7 - c. Suppose static scoping is used. What is the value...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
COP4020 Spring 2011 Homework Assignment 7 1. Consider the following pseudo-code program: sum : integer // a global variable procedure add(amount : integer) sum := sum + amount procedure p(x : integer, adder : procedure) integer sum sum := x adder(x) // invoke procedure that was passed as argument write_integer(sum) begin // main program sum := 0 p(1, add) end a. Suppose dynamic scoping with shallow binding is used by the interpreter to execute this code. What is the value printed by the program? b. Suppose dynamic scoping with deep binding is used by the interpreter to execute this code. What is the value printed?
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: c. Suppose static scoping is used. What is the value printed by the program? 2. What is the value printed by the following pseudo-code program for each of the four parameter passing modes call-by-value , call-by-reference , call-by-value/result , and call-by-name ? That is, for each of the four parameter passing modes assume that both the x and y parameters use that mode. Show how each program is evaluated in that mode and show the final value printed: a : integer // a global variable procedure p(x : integer, y : integer) x := x + 1 a := y begin // main program a := 2 p(a, a) write_integer(a) end...
View Full Document

Ask a homework question - tutors are online