Runtime Environment · Compiler Design
10 questions · asked in 9 of 27 years (2000–2026)
MCQ 101-mark 8 · 2-mark 2
2000Questions per year2026
Questions 6–10 of 10
Consider the program given below, in a block-structured pseudo-language with lexical scoping and nesting of procedures permitted.
Consider the calling chain: Main A1 A2 A21 A1
The correct set of activation records along with their access links is given by
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
Answer: (D)
An access link points to the activation record of the procedure that lexically encloses it.
- A1 and A2 are both declared in Main, so each one has its link to Main.
- A21 is declared inside A2, so it has its link to A2.
- The second A1, called from A21, is still declared in Main, so it has its link to Main. Access links follow the nesting in the program, not the calling order.
This matches figure (D). In (A) and (B) the last A1 links to A21, and (C) shows only four records, with no record for the second call of A1.
Answer: (D)
- A1 and A2 are both declared in Main, so each one has its link to Main.
- A21 is declared inside A2, so it has its link to A2.
- The second A1, called from A21, is still declared in Main, so it has its link to Main. Access links follow the nesting in the program, not the calling order.
This matches figure (D). In (A) and (B) the last A1 links to A21, and (C) shows only four records, with no record for the second call of A1.
Answer: (D)
Which languages necessarily need heap allocation in the runtime environment?
Answer: (C)
- (A) A stack is enough for recursion. Each call gets an activation record that is removed when the call returns.
- (B) Dynamic scoping decides which variable a name means by looking along the chain of calls (deep access), or through a table of names (shallow access). Both work with stack frames, so no heap is needed.
- (D) Global variables are kept in static memory, so they need nothing more.
Dynamic data structures are different. Linked lists and trees are built at run time with malloc/new. Their memory must stay alive after a call ends, so it cannot depend on function calls. This means a heap is needed.
Answer: (C)
- (B) Dynamic scoping decides which variable a name means by looking along the chain of calls (deep access), or through a table of names (shallow access). Both work with stack frames, so no heap is needed.
- (D) Global variables are kept in static memory, so they need nothing more.
Dynamic data structures are different. Linked lists and trees are built at run time with malloc/new. Their memory must stay alive after a call ends, so it cannot depend on function calls. This means a heap is needed.
Answer: (C)
Which of the following are true?
I. A programming language which does not permit global variables of any kind and has no nesting of procedures/functions, but permits recursion can be implemented with static storage allocation
II. Multi-level access link (or display) arrangement is needed to arrange activation records only if the programming language being implemented has nesting of procedures/functions
III. Recursion in programming languages cannot be implemented with dynamic storage allocation
IV. Nesting procedures/functions and recursion require a dynamic heap allocation scheme and cannot be implemented with a stack-based allocation scheme for activation records
V. Programming languages which permit a function to return a function as its result cannot be implemented with a stack-based storage allocation scheme for activation records
I. A programming language which does not permit global variables of any kind and has no nesting of procedures/functions, but permits recursion can be implemented with static storage allocation
II. Multi-level access link (or display) arrangement is needed to arrange activation records only if the programming language being implemented has nesting of procedures/functions
III. Recursion in programming languages cannot be implemented with dynamic storage allocation
IV. Nesting procedures/functions and recursion require a dynamic heap allocation scheme and cannot be implemented with a stack-based allocation scheme for activation records
V. Programming languages which permit a function to return a function as its result cannot be implemented with a stack-based storage allocation scheme for activation records
Answer: (A)
I. False. Recursion needs a fresh activation record for every call, and the number of calls is not known at compile time. So static allocation cannot work, even without globals and nesting.
II. True. Access links (or a display) are used to reach the variables of enclosing procedures. They are needed only when procedures can be nested. Without nesting, a non-local name is a global and is reached directly.
III. False. Recursion is implemented with dynamic allocation: each call pushes a new activation record.
IV. False. Nesting and recursion work with a stack of activation records. Access links connect a record to the records of its enclosing procedures, so no heap is needed.
V. True. A function returned as a result may still use the local variables of the function that returned it. Those locals must live after the call ends, but a stack pops the activation record on return. So a stack alone is not enough.
Only II and V are true.
Answer: (A)
II. True. Access links (or a display) are used to reach the variables of enclosing procedures. They are needed only when procedures can be nested. Without nesting, a non-local name is a global and is reached directly.
III. False. Recursion is implemented with dynamic allocation: each call pushes a new activation record.
IV. False. Nesting and recursion work with a stack of activation records. Access links connect a record to the records of its enclosing procedures, so no heap is needed.
V. True. A function returned as a result may still use the local variables of the function that returned it. Those locals must live after the call ends, but a stack pops the activation record on return. So a stack alone is not enough.
Only II and V are true.
Answer: (A)
Early binding refers to a binding performed at compile time and late binding refers to a binding performed at execution time. Consider the following statements:
i. Static scope facilitates w1 bindings.
ii. Dynamic scope requires w2 bindings.
iii. Early bindings w3 execution efficiency.
iv. Late bindings w4 execution efficiency.
The right choices of wl, w2, w3 and w4 (in that order) are
i. Static scope facilitates w1 bindings.
ii. Dynamic scope requires w2 bindings.
iii. Early bindings w3 execution efficiency.
iv. Late bindings w4 execution efficiency.
The right choices of wl, w2, w3 and w4 (in that order) are
Answer: (D)
Static scoping allows early binding, which happens at compile time. Early binding raises efficiency.
Dynamic scoping needs late binding, which happens at execution time. Late binding lowers efficiency because the binding must be done at runtime (but it gives more flexibility).
So the answer is (D).
Dynamic scoping needs late binding, which happens at execution time. Late binding lowers efficiency because the binding must be done at runtime (but it gives more flexibility).
So the answer is (D).
In the C language
Answer: (B)
Each function call pushes one activation record on the stack.
(A) False. If main calls f, f calls g and g calls h, then f and g are both between h and main. Calls can be nested to any depth.
(B) True. The number of records between the current one and main equals the depth of calls at that moment, so it depends on the actual calling sequence.
(C) False. C uses static (lexical) scoping, so which global variables are visible is fixed by the program text, not by who called whom.
(D) False. A recursive call is treated like any other call. Its record is pushed on the same stack, and no separate stack is needed.
Answer: (B)
(A) False. If main calls f, f calls g and g calls h, then f and g are both between h and main. Calls can be nested to any depth.
(B) True. The number of records between the current one and main equals the depth of calls at that moment, so it depends on the actual calling sequence.
(C) False. C uses static (lexical) scoping, so which global variables are visible is fixed by the program text, not by who called whom.
(D) False. A recursive call is treated like any other call. Its record is pushed on the same stack, and no separate stack is needed.
Answer: (B)
Keep practising
Topics in Compiler Design
Lexical AnalysisParsingSyntax-directed Translation
Runtime EnvironmentYou are here
Assemblers, Linkers and LoadersIntermediate Code GenerationMatching