GateAI
Runtime Environments

GATE CSE 2012 · Q36

MCQ2 marksMedium

Time

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 →\rightarrow A1 →\rightarrow A2 →\rightarrow A21 →\rightarrow A1 The correct set of activation records along with their access links is given by

Select one answerSingle correct

Pick an option to check

Solution

Step-by-step verified solution

Official answer: D)

Runtime Environments

In a block-structured language with lexical (static) scoping, an activation record's access link (or static link) points to the activation record of its immediate enclosing lexical scope (the procedure where it is statically declared), not the caller.

Let's analyze the lexical nesting in the given code:

  • main is the outermost program scope.

  • Procedure A1 is declared inside main, so any activation of A1 has its access link pointing to the activation record of main [d1].

  • Procedure A2 is declared inside main, so any activation of A2 has its access link pointing to main [d1].

  • Procedure A21 is declared inside A2, so any activation of A21 has its access link pointing to A2 [d1].

For the calling sequence Main→A1→A2→A21→A1\text{Main} \rightarrow \text{A1} \rightarrow \text{A2} \rightarrow \text{A21} \rightarrow \text{A1}:

  1. Main\text{Main}: Base activation record.

  2. A1\text{A1} (called by Main\text{Main}): Access link →Main\rightarrow \text{Main}.

  3. A2\text{A2} (called by A1\text{A1}): Access link →Main\rightarrow \text{Main}.

  4. A21\text{A21} (called by A2\text{A2}): Access link →A2\rightarrow \text{A2}.

  5. A1\text{A1} (called by A21\text{A21}): Access link →Main\rightarrow \text{Main}.

This exact configuration of access links corresponds to option (D) [d1].

Try the question first, then check your work.

Think the official key or this write-up is wrong?

Report error or challenge

Examiner trap

The misconception this question tests

This Runtime Environments previous year question is Q36 of the GATE CSE 2012 paper. Find more GATE CSE PYQs on Runtime Environments in Compiler Design, or browse all GATE CSE PYQs.

Free diagnostic

Where do you stand for GATE?

Take the 20-minute diagnostic: the 3 topics that cost you the most marks, and a rank range. Or sit 5 related Runtime Environments PYQs now with no account.

One GATE CSE PYQ every morning

An official question by email at 7 AM IST, with a link to its verified solution. Unsubscribe in one click.

Runtime Environments in GATE CSE

Runtime Environments has 7 GATE CSE PYQs across 7 papers from 2012 to 2023. 3 of them are 2-mark MCQs like this one, and it is the only one in GATE CSE 2012.

How GATE tests Runtime Environments

More from GATE CSE 2012

Share this solution

A plain-text card for WhatsApp or Telegram study groups.

GateAI solution cardGATE CSE 2012 · Q36 · MCQ

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 → A1 → A2 → A21 → A1 The correct set of activation records along with their access links is given by

Topic-wise GATE CS PYQs with verified steps

Independent practice explanation verified by the GateAI team. GATE is conducted by the IITs; question text follows the official paper.