Question

4. Consider the following program, written in JavaScript-like syntax: // main program var x, y, z...

4. 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 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. 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

Homework Answers

Answer #1

a. main calls sub1; sub1 calls sub2; sub2 calls sub3

   = axw in sub3.b , z in sub2, y in sub1

b. main calls sub1; sub1 calls sub3

     = axw in sub3, yz in sub1

c. main calls sub2; sub2 calls sub3; sub3 calls sub1

   = ayz in sub1, xw in sub3, b in sub2

d. main calls sub3; sub3 calls sub1

   = ayz in sub1, xw in sub3

e. main calls sub1; sub1 calls sub3; sub3 calls sub2

= abz in sub2, xw in sub3, y in sub1

f. main calls sub3; sub3 calls sub2; sub2 calls sub1

   = ayz in sub1, b in sub2, xw in sub3

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
2. Consider the following program written in C syntax: void swap(int a, int b) {   ...
2. Consider the following program written in C syntax: void swap(int a, int b) {    int temp;    temp = a;    a = b;    b = temp; } void main() {    int value = 2, list[5] = {1, 3, 5, 7, 9};    swap(value, list[0]);    swap(list[0], list[1]);    swap(value, list[value]); } For each of the following parameter-passing methods, what are all of the values of the variables value and list after each of the three...
##4. What will the following program display? ##def main(): ## x = 1 ## y =...
##4. What will the following program display? ##def main(): ## x = 1 ## y = 3.4 ## print(x, y) ## first printing ## change_us(x, y) ## print(x, y) ##second printing ## ##def change_us(a, b): ## a = 0 ## b = 0 ## print(a, b) ## ##main() ## ##Yes, yes, main() displays ##1 3.4 ##0 0 ##1 3.4 ## The question is: why x and y are still the same while the second printing of (x,y)? ## It seems...
You will write a program that loops until the user selects 0 to exit. In the...
You will write a program that loops until the user selects 0 to exit. In the loop the user interactively selects a menu choice to compress or decompress a file. There are three menu options: Option 0: allows the user to exit the program. Option 1: allows the user to compress the specified input file and store the result in an output file. Option 2: allows the user to decompress the specified input file and store the result in an...
Hi, I'm writing a Java program that prints a grid with circles and squares that have...
Hi, I'm writing a Java program that prints a grid with circles and squares that have letters in them and it is also supposed to print the toString() function to the console window each time the application runs. This toString() function is supposed to show the tile's shape, letter, and color component (or components). Could someone please review and debug my code to help me figure out why my toString() function is not working? import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JButton;...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT