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](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/09/66f515f7b009e_97566f515f72f025.jpg)
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
Get step-by-step solutions from verified subject matter experts
