Given the following Ada program: procedure Main is X, Y: Integer; procedure Sub1 is Y, Z:...
Consider the following program, written in JavaScript-like syntax: // main program var x, y, z; function sub1() { var a, y, z; . . . } function sub2() { var a, b, z; . . . } function sub3() { var a, x, w; . . . } Given the following calling sequences and assuming that dynamic scoping is used, what variables are visible during execution of the last subprogram activated? Include with each visible variable the name of the...
Consider the following JavaScript skeletal program: //the main program var x: function sub1 () { var x: function sub2 () { } } function sub3 () { } Assume the execution of this program is in the following unit order: main calls sub1 sub1 calls sub2 sub2 calls sub3 a. Assuming static scoping, which declaration of x is the correct one for a reference to x in: i. sub1 ii. sub2 iii. sub3 b. Repeat part a, but assume dynamic...
x: integer -- global procedure second x: integer --local x:= 2 second --main program x:= 0 first write_integer (x) //What does this program print if the language uses static scoping? //What does it print if the language uses dynamic scoping?
8. (10%) Consider the following JavaScript program: // The main program var x,y; function f10{ var y, z; function f20{ var x, Z, P; function f30{ var x, z, ; Assume that the execution of this program is in the following unit order: main calls f3, f3 calls f1, f1 calls 12. a) Assuming that static scoping is in effect, indicate which version of each of the following variables will be visible in f2 by filling in each blank with...
3- (3 pts) Consider the following Pascal program skeleton program main var a, b, c: integer; procedure Sl; var x, b, c: integer procedure S2; var n, m, k: integer; end; end; procedure S3; var x, a, l: integer; end; end; List all of the variables, along with the program units where they are declared, that are visible in the bodies of S1, S2, and S3, assuming static scoping.
Show the stack with all activation record instances, including static and dynamic chains, when execution reaches position 1 in the following ske- letal program. Assume Bigsub is at level 1. procedure Bigsub is MySum : Float; procedure A is X : Integer; procedure B(Sum : Float) is Y, Z : Float begin -of B C(Z) end; -- of B begin -of A B (X)i end -- of A procedure C (Plums Float) is begin - of c end; -- of...
(24) (2 marks) Consider the following skeletal program, written in a lan- guage with static scope. procedure Main; procedure A procedure B: procedure C begin C end C begin B end B procedure D procedure E begin E end E begin D end D begin A end A begin ain end Nain Imagine that the following procedure calls have taken place: Main calls A A calls D D calls E E calls B B calls C i. Drawthe run time...
Consider the following pseudocode Xinteger procedure set x(n global integer) Xin procedure print x write integer(x) procedure first set x(1) print x procedure second xinteger set x(2) print x set x(e) first() print x second print x What does this program print if the language uses static scoping? What does it print with dynamic scoping? Why?
3. Show the stack with all activation record instances, including static and dynamic chains, when execution reaches position 1 in the following skeletal program. Assume Bigsub is at level 1 procedure Bigsub is procedure A (Flag procedure Bis Boolean) is A (false) end; -of B begin -- of A if flag then B; else C; end; -of A procedureCis procedure D is end; -of D end; -- of dC begin of Bigsub A(true); of Bigsub end; -- The calling sequence...
For the given program determine what is printed after each write statement assuming static scoping, deep binding and parameters are passed-by-value-result. program main; var X: integer; procedure Q(var I: integer; function R(J: integer):integer); var X: integer; begin X:=4; write(“In Q, before call of R, I=”, I, “X=”, X); I=R(I); write(“In Q, after call of R, I=”, I, “X=”, X); end; procedure P; var I: integer; ...