Compiler Design MCQs - Runtime Environments and Symbol Tables (Set 5)

Compiler Design MCQs - Runtime Environments and Symbol Tables (Set 5) - CodingHumans

This set examines what happens when a compiled program runs. It covers activation records and their links, static, stack and heap storage, the activation tree, static versus dynamic scoping, and parameter-passing modes such as call by value, reference, value-result and name, with short code traces. Symbol table organisation is also tested. It helps GATE CSE aspirants, university exam candidates and interviewees for compiler and systems roles.

How to practise: read each question and tap the option you think is correct. You will see right away whether you got it, along with a short explanation, and your score is tracked at the bottom of the screen. This set has 18 questions.

Compiler Design MCQ series: Set 1 | Set 2 | Set 3 | Set 4 | Set 5 | Set 6

Topics covered in this set

  • Activation records, control links and access links
  • Static, stack and heap allocation
  • Activation trees and control stacks
  • Static and dynamic scoping
  • Parameter passing modes with traces
  • Displays and nested procedures
  • Symbol table organisation and scope handling

Compiler Design MCQs with answers and explanations

Q1. Which of the following is NOT normally stored in a procedure's activation record?

a) The control link

b) Saved machine status such as the return address

c) The compiler's symbol table for the source program

d) Local variables of the procedure

Q2. The control link (dynamic link) in an activation record points to

a) the activation record of the lexically enclosing procedure

b) the start of the heap

c) the code of the called procedure

d) the activation record of the caller

Q3. In a language with nested procedures and static scoping, the access link is used to

a) return control to the caller

b) locate non-local variables declared in lexically enclosing procedures

c) allocate space on the heap

d) pass parameters by reference

Q4. Which language feature cannot be supported if all storage is allocated statically at compile time?

a) Global variables

b) Fixed-size arrays

c) Constant literals

d) Recursive procedure calls

Q5. Heap allocation, rather than stack allocation, is required when

a) a procedure has only integer locals

b) a procedure is called exactly once

c) a variable is declared constant

d) data must outlive the activation of the procedure that created it

Q6. Assume both parameters are passed by reference. What value of a is printed?

void f(int x, int y) {
    x = x + 1;
    y = y + x;
}

main:
    a = 2;
    f(a, a);
    print(a);

a) 2

b) 6

c) 3

d) 5

Q7. Call by name is typically implemented by passing

a) a thunk, a small routine that evaluates the argument expression in the caller's environment each time it is used

b) the address of the argument evaluated once at the call

c) a copy of the argument's value

d) the symbol table entry of the argument

Q8. Using call by value-result, what two values are printed, in order?

int g = 10;
void p(int x) {
    x = 20;
    print(g);
}

main:
    p(g);
    print(g);

a) 10 then 10

b) 20 then 20

c) 10 then 20

d) 20 then 10

Q9. A dangling reference most commonly arises when

a) a function returns a pointer to one of its own local variables

b) a global variable is never used

c) a heap object is still reachable

d) a parameter is passed by value

Q10. What is printed when the program below runs under dynamic scoping?

int x = 1;
void show() { print(x); }
void test() { int x = 5; show(); }

main:
    test();
    show();

a) 1 1

b) 5 5

c) 1 5

d) 5 1

Q11. With a display used for non-local access, reaching a variable declared k nesting levels out requires

a) exactly k access-link traversals

b) a constant number of memory accesses, independent of k

c) a search of the symbol table at runtime

d) k squared memory accesses

Q12. Which data structure gives the fastest average-case lookup for identifiers in a compiler's symbol table?

a) Unsorted linear list

b) Hash table

c) Singly linked list sorted by insertion time

d) Binary search tree built from sorted input

Q13. Which symbol table organisation most naturally supports nested block scopes?

a) A single list with no scope information

b) One global hash table that never removes entries

c) A stack or chain of tables, one per scope, searched from the innermost outward

d) A sorted array of all identifiers in the program

Q14. A procedure at nesting depth 3 calls a procedure declared at nesting depth 2. How many access links must be followed from the caller to set the callee's access link?

a) 0

b) 2

c) 1

d) 3

Q15. In a typical runtime memory layout, how are the stack and heap arranged?

a) They grow towards each other through a shared free area

b) Both grow in the same direction from the code area

c) The heap is placed inside the stack

d) Their sizes are fixed at compile time

Q16. Which garbage collection technique, used on its own, fails to reclaim cyclic data structures that are no longer reachable?

a) Reference counting

b) Mark and sweep

c) Copying collection

d) Generational tracing collection

Q17. How many activations of fib occur, that is, how many fib nodes are in the activation tree, for the call fib(3)?

int fib(int n) {
    if (n < 2) return n;
    return fib(n - 1) + fib(n - 2);
}

a) 5

b) 3

c) 4

d) 8

Q18. Which piece of information is NOT normally kept in a compiler's symbol table entry for a variable?

a) Its name

b) Its data type

c) The variable's value at each step of program execution

d) Its scope or nesting level

Quick revision notes

  • Activation record: actual parameters, return value, control link, access link, saved machine status, local data, temporaries.
  • Control (dynamic) link points to the caller's record; access (static) link points to the lexically enclosing procedure's record.
  • Static allocation cannot support recursion or dynamically sized data.
  • Call by reference passes addresses; call by value-result copies in and copies back on return; call by name re-evaluates the argument at each use (via thunks).
  • Calling from depth np to a procedure at depth nx: follow np - nx + 1 access links.
  • A display gives constant-time access to non-locals at any depth.
  • Reference counting cannot reclaim cyclic garbage.
  • Hash tables give average O(1) symbol lookup; nested scopes use a stack or chain of tables.

Frequently asked questions

What is the difference between a control link and an access link?

The control link points to the activation record of the caller and is used to restore the stack on return. The access link points to the record of the lexically enclosing procedure and is used to reach non-local variables under static scoping.

How does call by value-result differ from call by reference?

Call by value-result copies the argument into a local on entry and copies it back on return, so the caller's variable changes only at exit. With call by reference, every assignment inside the callee immediately changes the caller's variable, which matters when aliases or globals are involved.

Why can't static allocation support recursion?

Static allocation gives each procedure a single fixed area for its locals at compile time. A recursive call would need a second copy of those locals while the first activation is still alive, which a single fixed area cannot provide.

Comments

Answered 0/0Correct 0