GATE | GATE CS 2012 | Question 34

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 A21
  
    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 :

gatecs2012activationrecord

gatecs2012activationrecord
(A) A
(B) B
(C) C
(D) D


Answer: (D)

Explanation: Access link is defined as link to activation record of closest lexically enclosing block in program text, so the closest enclosing blocks respectively for A1 ,A2 and A21 are main , main and A2 Since, Activation records are created at procedure entry time and destroyed at procedure exit time.

Solution:
Link to activation record of closest lexically enclosing block in program text. It depends on the static program text.

nitika_36

Here Calling sequence is given as,

Main->A1->A2->A21->A1
Now A1,A2 are defined under Main…So A1,A2 Access link are pointed to main A21 is defined under A2 hence its Access link will point to A2 .

Reference:
http://www.cs.nyu.edu/courses/spring08/G22.2130-001/lectures/lecture-13.html

This solution is contributed by Nitika Bansal


Quiz of this Question



My Personal Notes arrow_drop_up


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.