8. Consider the following Ada Skeletal program: Procedure Main is X: integer; Pr
ID: 648583 • Letter: 8
Question
8. Consider the following Ada Skeletal program:
Procedure Main is
X: integer;
Procedure Sub3; -- This is a declaration of Sub3
- -It allows sub1 to call it
Procedure Sub is
X : Interger;
Procedure Sub2 is
begin - - of Sub2
. . .
end; - - of Sub2
begin - - of Sub1
. . .
end; - - of Sub1
Procedure Sub3 is
begin - - of Sub3
. . .
end; - - of Sub3
begin - - of Main
. . .
end; - - of Main
Assume that the execution of this program is in the following unit order :
Main calls Sub1
Sub1 calls Sub2
Sub2 calls Sub3
Assuming static scoping, in the following which declaration of X is the correct one for a reference to X?
Sub1
Sub2
Sub3
B. Repeat part a, but assume dynamic scoping.
9. Assume the following Ada program was compiled and executed using static-scoping rules. What value of X is printed in procedure Sub1?
Under dynamic-scoping rules, what value of X is printed in procedure Sub1?
Procedure Main is
X : Integer;
Procedure Sub1 is
Begin - - of Sub1
Put(X);
End; - - of Sub1
Procedure Sub2 is
X : Integer;
Begin - - of Sub2
X := 10;
Sub1
End; - - of Sub2
Begin - - of Main
X :=5;
Sub2 - - of Main
12. Consider the following C program:
Void fun(void) {
Int a, b, c; /* definition 1*/
. . .
While (. . .) {
Int b, c, d; /*definition 2*/
. . . <- - - - - - - - - - - - - - - 2
}
. . . <- - - - - - - - - - - - - - - 3
}
. . . <- - - - - - - - - - - - - - - 4
}
For each of the four marked points in this function, list each visible variable, along with the number of the definition statement that defines it.
Explanation / Answer
(8)
Sub1 gets its value of X from Sub1
Sub2 gets its value of X from Sub1
Sub3 gets its value of X from Main
(a)Assume the static scoping in the following points of execution of X is
i. Sub1 gets the value of X from Sub1
ii. Sub2 gets the value of X from Sub1
iii. Sub3 gets the value of X from Main
(b)
b) Let (a) for dynamic scoping
i. Sub1 gets the value of X from Sub1
ii. Sub2 gets the value of X from Sub1
iii. Sub3 gets the value of X from Sub1
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.