Question: Consider the following pseudocode, assuming nested subroutines and static scope: (a) What does this program print? (b) Show the frames on the stack when A

Consider the following pseudocode, assuming nested subroutines and static scope:
procedure main() g: integer procedure Bla : integer) x: integer procedure Aln : integer) g:=n procedure R(m : integer) write integer(x) x/:= 2 -- integer division if x > 1 RIm + 1) else Alm) -- body of B X:= a x a R(1) -- body of main B(3) writeinteger(g)

(a) What does this program print?

procedure main() g: integer procedure Bla : integer) x: integer procedure Aln

(b) Show the frames on the stack when A has just been called. For each frame, show the static and dynamic links.

(c) Explain how A finds g.

procedure main() g: integer procedure Bla : integer) x: integer procedure Aln : integer) g:=n procedure R(m : integer) write integer(x) x/:= 2 -- integer division if x > 1 RIm + 1) else Alm) -- body of B X:= a x a R(1) -- body of main B(3) writeinteger(g)

Step by Step Solution

3.54 Rating (164 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

a 9 4 2 3 b c It dereferences its static link to find the stack frame of ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Language Pragmatics Questions!