Consider the following pseudo-code: x : integer; procedure set_x (n: integer) x = n; procedure print_x...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
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. 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. 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.
Expert Answer:
Answer rating: 100% (QA)
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 the full answer
Related Book For
Posted Date:
Students also viewed these programming questions
-
If the resultant force acting on the hook is F R = {? 200i + 800j + 150k} lb, determine the magnitude and coordinate direction angles of F. 30 F= 600 ib
-
Using the information in E20.19, prepare a worksheet inserting January 1, 2019, balances, showing December 31, 2019, balances, and the journal entry recording postretirement benefit expense. Service...
-
P Company owns 80% of the outstanding stock of S Company. The 2020 sales of S Company included revenue of $390,000 consisting of consulting services billed to P Company at cost plus 30%. P Company...
-
In 2014, political consulting firm Cambridge Analytica developed an app designed to create digital profiles of individuals via their information. Cambridge Analytica collected the data by inviting...
-
Tiffany Martin is an audit manager in a medium-sized public accounting firm. Tiffany graduated from college seven years ago with a degree in accounting. She obtained her CPA certification soon after...
-
Mr. Amar is 30 year old, newly married and a successful actor in the Indian film industry. Right from his struggling days, Amar always saved a part of his income and invested in safe instruments like...
-
Refer to the first 100 minutes of the computer simulation of the current operation of Herr Cutter's barber shop presented in Figure 12.7 and summarized in Figure 12.8. Now consider the alternative of...
-
The Japanese girl, Miho, in the earlier bagel case, estimates that she would need to invest about $50,000 to purchase the necessary supplies and equipment. She has $20,000 in savings, but still needs...
-
What is the historical context in which unions developed?
-
Unemployment is a more serious economic problem than inflation and it should be the focus of the Feds monetary policy. Evaluate this statement and explain why the Feds primary policy goal is price...
-
What is the history of bankruptcy law in the United States?
-
What are the various techniques of corporate expansion?
-
Explain for each event whether it changes the quantity of real GDP demanded or aggregate demand in Japan. The Japanese price level rises. A depreciation of the yen attracts more tourists to Japan. ...
-
A periodic function f(x) is defined by f (r) = r2 +3 for - 2
-
Write a paper by answer the following question: Should Recycling Be Mandatory?
-
Suppose that every monitor has a separate mutual exclusion lock, so that different threads can run in different monitors concurrently, and that we want to release exclusion on both inner and outer...
-
Explain how to obtain the effect of Fortran 90s allocate statement for one-dimensional arrays using pointers in C. You will probably find that your solution does not generalize to multidimensional...
-
We noted in Section 13.3.2 that several processors, including the ARM, MIPS, and Power, provide an alternative to compare_and_swap (CAS) known as load_linked/store_conditional (LL/SC). A load_linked...
-
a. The equation of the Phillips curve from 1970 to 1995 is: \[\pi_{t}-\pi_{t-1}=7.4 \%-1.2 u_{t}\] Calculate and define the natural rate of unemployment using this curve. b. The equation of the...
-
Suppose that the mark-up of goods prices over marginal cost is \(5 \%\), and that the wage-setting equation is: \[W=P(1-u)\] where \(u\) is the unemployment rate. a. What is the real wage, as...
-
How can a lockdown result in stagflation? A lockdown can have three different effects: a. The first happens when demand during the lockdown decreases so that actual output, \(Y_{t}\), falls exactly...
Study smarter with the SolutionInn App