tut7 4
TRANSCRIPT
Principles of Programming Languages
Tutorial 7Name - Binding - Scope
Question 1.In term of programming language, what alias means? Give at least 2 examples of aliases
Question 2.Given the following C assignment statement:
c = d * 120;What is the binding time of:
a. The type of variable c?
b. The convention rule to write a variable?
c. The address of variable c?
d. The meaning of operator *?
e. The order in which two operands of operator * are loaded?
Question 3.Assume the following Ada program was compiled and executed using static-scoping rules.What value of X is printed in procedure Sub1?
procedure Main i sX : Integer ;procedure Sub1 i s
begin −− of Sub1Put(X) ; −− pr in t X to conso l e
end ; −− of Sub1procedure Sub2 i s
X : Integer ;begin −− of Sub2
X := 10 ;Sub1
end ; −− of Sub2begin −− of Main
X := 5 ;Sub2
end ; −− of Main
1
Principles of Programming Languages
Question 4.Consider the following program:
procedure Main i sX, Y, Z : In t eg e r ;procedure Sub1 i s
A, Y, Z : In t eg e r ;begin −− o f Sub1
. . .end ; −− o f Sub1
procedure Sub2 i sA, B, Z : In t eg e r ;begin −− o f Sub2
. . .end ; −− o f Sub2
procedure Sub3 i sA, X, W : In t eg e r ;begin −− o f Sub3
. . .end ; −− o f Sub3
begin −− o f Main. . .
end ; −− o f Main
Given the following calling sequences and assuming that dynamic scoping is used, whatvariables are visible durin execution of the last subprogram activated? Include with eachvisible variable the name of the unit where it is declared.
A. Main calls Sub1; Sub1 calls Sub2; Sub2 calls Sub3.
B. Main calls Sub1; Sub1 calls Sub3.
C. Main calls Sub2; Sub2 calls Sub3; Sub3 calls Sub1.
D. Main calls Sub3; Sub3 calls Sub1.
E. Main calls Sub1; Sub1 calls Sub3; Sub3 calls Sub2.
F. Main calls Sub3; Sub3 calls Sub2; Sub2 calls Sub1.
2