Question: 1 2 3 Problem 2 [9pt] Consider the following pseudo-code, with the assumption that the language uses static scoping and has one scope for each

 1 2 3 Problem 2 [9pt] Consider the following pseudo-code, with

1 2 3 Problem 2 [9pt] Consider the following pseudo-code, with the assumption that the language uses static scoping and has one scope for each function (including the main function), and it allows nested functions (hence, nested scopes). main() { int g; int x = 4; function B (int a) { int x = a + 2; C(1); } function A (int n) { g = n; } 4 5 6 7 8 9 10 1/2 11 { 12 13 14 15 16 function C (int m) print x; x = x/2; if (x > 1) C (m + 1); else A (m); } // body of main B(1); print g; 17 18 19 20 21 22 } a) (3pt) Draw the symbol table tree with 4 tables, one table for each of the 4 scopes (namely main, B, A, C) in this program. Assume each table contains two columns: name and kind (e.g, id, fun, para). b) (1pt) What does the program print? c) (3pt) Draw a picture of the run-time stack when A has just been called. For each frame, show the static and dynamic links. You do not have to show the storage for any other information. d) (2pt) Refer to the run-time stack, briefly explain how function A finds variable g. 1 2 3 Problem 2 [9pt] Consider the following pseudo-code, with the assumption that the language uses static scoping and has one scope for each function (including the main function), and it allows nested functions (hence, nested scopes). main() { int g; int x = 4; function B (int a) { int x = a + 2; C(1); } function A (int n) { g = n; } 4 5 6 7 8 9 10 1/2 11 { 12 13 14 15 16 function C (int m) print x; x = x/2; if (x > 1) C (m + 1); else A (m); } // body of main B(1); print g; 17 18 19 20 21 22 } a) (3pt) Draw the symbol table tree with 4 tables, one table for each of the 4 scopes (namely main, B, A, C) in this program. Assume each table contains two columns: name and kind (e.g, id, fun, para). b) (1pt) What does the program print? c) (3pt) Draw a picture of the run-time stack when A has just been called. For each frame, show the static and dynamic links. You do not have to show the storage for any other information. d) (2pt) Refer to the run-time stack, briefly explain how function A finds variable g

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!