The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
+17 votes

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:

asked in Compiler Design by Boss (18.3k points)
edited by | 2.5k views
can any one describe it more ?

2 Answers

+43 votes
Best answer

Since, Activation records are created at procedure entry time and destroyed at procedure exit time.
therefore here Calling sequence is given as ,
$Main \rightarrow A1 \rightarrow A2 \rightarrow A21 \rightarrow A1$
now $A1$ and $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$. 

answered by Active (2.1k points)
edited by
consider a different program where  A21 is enclosed under A1, which in turn is enclosed under Main.

If A21 is called directly form main, only activation records for Main and A21 will exist. So my question is will A21 access link point to main then? Because Main is the closest enclosing procedure.
Wat about a21 ?? i think there should be a line between a1 to a21 ?? anyone ??
Procedure A2;
    Var ...

    Procedure A21;
      Var ...
      Call A1;
    End A21

    Call A21;
  End A2

here A21 come inside A2 thats y only scope not goes outside it.

Actually from where procedure started and ended inside that procedure if there is any nested procedure or calling any function, every thing will be nested with activation record of that procedure
i didn't understand why there is no link from A1 to A21. Please explain?
Because A1 is not Defined under A21.. it is being simply called this time .

Procedure A1 and A2 are defined under main hence there is an access link between them .
0 votes

From main() there are three function calling sequence

1) A1 -> A2

2) A2 ->  A21  ->  A1

3) A1

These 1,2,3 are access links.

Now match with the given answer calling chains:


It shows a linear chain(only one function call from main()) which isn't correct and doesn't follow above sequence at all.


It is false because main() unable to call A1 directly.


It shows there is only two function call made by main(). That is not true and Frame pointer will also get updated by new A1 address block not will be old one.


main() has three function calling sequence present and Frame Pointer is holding the new A1 block address. That is true.

answered by Active (1.5k points)

Related questions

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true

40,903 questions
47,558 answers
62,306 users