Question: Consider the following pseudo-code: x : integer; procedure set_x (n: integer) x = n; procedure print_x -- write_integer (x); else procedure foo (S, P:
Consider the following pseudo-code: x : integer; procedure set_x (n: integer) x = n; procedure print_x -- write_integer (x); else procedure foo (S, P: procedure; n : integer) x : integer; if n in (1,3) global else S (n); if n in (1,2) print_x; set_x (n); P; main program set_x (0); foo (set_x, print_x, 1); print_x; set_x (0); foo (set_x, print_x, 2); print_x; set_x (0); foo (set_x, print_x, 3); print_x; set_x (0); foo (set_x, print_x, 4); print_x; Assume that the language uses dynamic scoping. What does this program print if the language uses shallow binding? Why? What does it print with deep binding? Why? Note: At exactly one point during execution in the deep binding case, the program will attempt to print an uninitialized variable. Simply write a "?" for the value printed at that point.
Step by Step Solution
3.46 Rating (156 Votes )
There are 3 Steps involved in it
In the provided pseudocode we have a global variable x and a set of procedures setx printx and foo We need to understand the output of the program assuming dynamic scoping is used as well as the behav... View full answer
Get step-by-step solutions from verified subject matter experts
