Question: Procedure A has static depth 3 and defines a variable which is visible in a nested subprocedure B . The nesting depth between procedure A

Procedure A has static depth 3 and defines a variable which is visible in a nested subprocedure B. The nesting depth between procedure A and procedure B is 1 (that is, B is directly nested inside A). What is the static depth of B?

3

1

4

2

Consider the following program: procedure Main is

A : Integer;

B : Integer;

procedure Sub1(X: Integer) is B, C : Integer;

begin

B := 2;

C := 3;

A := B + C;

end;

begin

A := 1;

B := 1;

Sub1(B);

end;

What is the reference to B in the expression A : = B + C (in terms of chain-offset/local offset)?

(0,3)

(1,4)

(1,3)

(0,4)

In a static scoped language that uses static chaining as an implementation technique, references to non-local variables can be represented as:

Static chain length/Local offset

Static depth/Local offset

Chain offset/Local offset

Chain offset/Static depth

When the system uses static chain to access nonlocal variables, which of the following are true?

References to variables in scopes beyond the static parent cost more than references to locals

References to variables in scopes beyond the static parent cost less than references to locals

Both local and nonlocal variables are stored in the same activation record instance

Nonlocal variables are stored in activation record instances of static ancestors

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!