Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

2. Consider the following program:procedure Main is X, Y, Z : Integer; procedure

ID: 3633080 • Letter: 2

Question

2. Consider the following program:procedure Main is

X, Y, Z : Integer;

procedure Sub1 is

A, Y, Z: Integer;

procedure Sub2 is

A, B, Z : Integer;

begin – of Sub2

end; -- of Sub2

begin – of Sub1…end;-- of Sub1

procedure Sub3 isA, X, W: Integer;

begin – of Sub3…end; -- of Sub3

begin – of Main…end. – of Main

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. You may use a table as following:

Variable                                   Where

DeclaredIn Sub1: var1               Main

var2                                        Main

In Sub2 …

Explanation / Answer

Unit

Var

Where Declared

sub1

a, y, x, z

sub1

main

sub2

a, b, z, x, y

sub2

main

sub3

a, x, w, y, z

sub3

main

Unit

Var

Where Declared

sub1

a, y, x, z

sub1

main

sub2

a, b, z, x, y

sub2

main

sub3

a, x, w, y, z

sub3

main