CONCEPTS OF PROGRAMMING LANGUAGE
Consider the following program skeleton
Procedure Main is
X, Y, Z: Integer;
procedure Sub1 is
A, Y, Z: Integer;
begin -- of Sub1
...
end; -- of Sub1
procedure Sub2 is
A, B, Z: Integer;
begin -- of Sub2
...
end; -- of Sub2
procedure Sub3 is
A, X, W: Integer;
begin -- of Sub3
...
end; -- of Sub3
begin - of Main
...
end; -- of Main
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 unit where it is declared.
(a) Main calls Sub1; Sub1 calls Sub2; Sub2 calls Sub3.
(b) Main calls Sub2; Sub2 calls Sub3; Sub3 calls Sub1.
(c) Main calls Sub1; Sub1 calls Sub3; Sub3 calls Sub2.
(a) Main calls Sub1; Sub1 calls Sub2; Sub2 calls Sub3.
In the last function call variables are visible
|
Y |
declared in sub1 procedure |
|
B,Z |
declared in sub2 procedure |
|
A,X,W |
declared in sub3 procedure |
--
b) Main calls Sub2; Sub2 calls Sub3; Sub3 calls Sub1.
In the last function call variables are visible
|
B |
declared in sub2 procedure |
|
X,W |
declared in sub3 procedure |
|
A,Y,Z |
declared in sub1 procedure |
--
(c) Main calls Sub1; Sub1 calls Sub3; Sub3 calls Sub2.
In the last function call variables are visible
|
Y |
declared in sub1 procedure |
|
X,W |
declared in sub3 procedure |
|
A,B,Z |
declared in sub2 procedure |
--
ALL THE BEST
CONCEPTS OF PROGRAMMING LANGUAGE Consider the following program skeleton Procedure Main is X, Y, Z: Integer;...
CONCEPTS OF PROGRAMMING LANGUAGE Consider the following skeleton program skeleton. List all the variables, along with the program units where they are declared, that are visible in the bodies of Sub1, Sub2, and Sub 3, assuming static scoping is used. Procedure Main is X, Y, Z: Integer; procedure Sub1 is A, Y, Z: Integer; begin -- of Sub1 ... end; -- of Sub1 procedure Sub2 is A, X, W: Integer; procedure Sub3 is A, B, Z: Integer; begin -- of...
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...
Given the following Ada program: procedure Main is X, Y: Integer; procedure Sub1 is Y, Z: Integer; begin -- of Sub1 point 1 Sub2; end; -- of Sub1 procedure Sub2 is X: Integer; procedure sub3 (B: Integer) is W: Integer; begin -- of Sub3 point 2 end; -- of Sub3 begin -- of Sub2 point 3 Sub3 (X); end; -- of Sub2 begin -- of Main point 4 Sub1; end; -- of Main For each of the four marked points,...
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...
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.
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...
programming languages in #f language
QUESTION 4 Consider the following skeletal C program: void funi(void); /* prototype */ void fun2(void); /* prototype */ void fun3(void); /* prototype */ void main() { int a, b, c; void fun1(void) { int b, c, d; void fun2 (void) { int c, d, e; void fun3(void) { int d, e, f, Assuming that dynamic scoping is used, what variables are visible during execution of the last function called in following calling sequence: main calls...
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?
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?
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...