Question: Do the following problems from Chapter 5 (Problem Set): #6 (1) Consider the following JavaScript skeletal program: // The main program var x; function sub1()

Do the following problems from Chapter 5 (Problem Set):

#6 (1)

Consider the following JavaScript skeletal program: // The main program var x; function sub1() { var x; function sub2() { . . . } }

function sub3() { . . . }

Assume that the execution of this program is in the following unit order: main calls sub1 sub1 calls sub2 sub2 calls sub3

1. Assuming static scoping, in the following, which declaration of x is the correct one for a reference to x? 1. sub1 2. sub2 3. sub3

#8

Consider the following JavaScript program: var x, y, z; function sub1() { var a, y, z; function sub2() { var a, b, z; . . . } . . . } function sub3() { var a, x, w; . . . }

List all the variables, along with the program units where they are declared, that are visible in the bodies of sub1, sub2, and sub3, assuming static scoping is used.

#9

Consider the following Python program: x = 1; y = 3; z = 5; def sub1(): a = 7; y = 9; z = 11; . . . def sub2(): global x; a = 13; x = 15; w = 17; . . . def sub3(): nonlocal a; a = 19; b = 21; z = 23; . . . . . . List all the variables, along with the program units where they are declared, that are visible in the bodies of sub1, sub2, and sub3, assuming static scoping is used.

#10

Consider the following C program: void fun(void) { int a, b, c; /* definition 1 */ . . . while (. . .) { int b, c, d; /*definition 2 */ . . . <------------- 1 while (. . .) { int c, d, e; /* definition 3 */ . . . <------------- 2 } . . . <-------------- 3 } . . . <---------------- 4 } Question: 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.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!