Consider the program given below, in a block-structured pseudo-language with…

2012

Consider the program given below, in a block-structured pseudo-language with lexical scoping and nesting of procedures permitted.

Program main;
Var ...
Procedure A1;
Var ...
Call A2;
End A1
Procedure A2;
Var ...
Procedure A21;
Var ...
Call A1;
End A21
Call A21;
End A2
Call A1;
End main.

Consider the calling chain: \(Main \to A1 \to A2 \to A21 \to A1\)

The correct set of activation records along with their access links is given by

Attempted by 27 students.

Show answer & explanation

Correct configuration and reasoning:

Key rule: an activation record’s access link points to the most recent active activation of its lexically (statically) enclosing procedure. It does not point to the dynamic caller.

  • Main: top-level, no access link needed (or null).

  • First A1 activation (called from Main): access link -> Main (A1 is declared in Main).

  • A2 activation: access link -> Main (A2 is declared in Main).

  • A21 activation: access link -> A2 (A21 is declared inside A2).

  • Second A1 activation (called from A21): access link -> Main (A1 is still declared in Main).

Therefore the correct picture shows both A1 activations and A2 linking to Main, A21 linking to A2, and the top Main having no parent. Any diagram that links a frame to its dynamic caller (for example making the new A1 link to A21) is incorrect under lexical scoping.

Explore the full course: Gate Guidance By Sanchit Sir

Loading lesson…