Name: Dalibor Labudovic Course: CS 4150 Professor: Dr.Gayler Assignment: #2 The purpose of this assignment is to reinforce scope concepts. Specifically, the assignment is to do problem 12 on page 240 of the text. 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 sequences and assuming that dynamic scop- ing is used, what variables are visible during execution of the last subpro- gram 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. Answer: a x w in sub3, sub1 calls sub2, sub2 calls sub3 b. main calls sub1; sub1 calls sub3. Answer: a x q in sub3, y z in sub1 c. main calls sub2; sub2 calls sub3; sub...
Comments
Post a Comment