1
Kingdom of Saudi Arabia ةكلمملا ةيدوعسلا ةيبرعلا Ministry of Education ميلعتلا ةرازو
Umm AlQura University ىرقلا مأ ةعماج
Adham University College مضأب ةيعماجلا ةيلكلا
Computer Science Department للآا بساحلا مسق
Summer Semester of 2018 Academic Year
BONUS Homework
-Solutions-
Last Delivery Date: Tuesday, 25 / 07 / 2018 – 12 / 11 / 1439 H
The Question: 1.5 Mark
Sebesta R.W., Concepts of Programming Languages, 10th Edition, Addison-Wesley Chapter Five, problem Set, page 236, exercise number 12.
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 sequence 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.
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.
Programming Languages Course, 6803331-4
2
Kingdom of Saudi Arabia ةكلمملا ةيدوعسلا ةيبرعلا Ministry of Education ميلعتلا ةرازو
Umm AlQura University ىرقلا مأ ةعماج
Adham University College مضأب ةيعماجلا ةيلكلا
Computer Science Department للآا بساحلا مسق
The Answer:
b.
Unit Name Visible Variables
sub3 a, x, w
sub1 y, z
c.
Unit Name Visible Variables
sub1 a, y, z
sub3 x, w
sub2 b
d.
Unit Name Visible Variables
sub1 a, y, z
sub3 x, w
e.
Unit Name Visible Variables
sub2 a, b, z
sub3 x, w
sub1 y
f.
Unit Name Visible Variables
sub1 a, y, z
sub2 b
sub3 x, w
Remember, “Success is 1% inspiration and 99% perspiration”😉 If you have any questions, feel free to ask me through my email
T.Mariah Sami Ahmed Khayat Teacher Assistant @ Adam University College