GATE Computer ScienceModerateGATE CS (PYQ pattern)
Nested procedures: main (depth 1) contains A (depth 2); A contains B (depth 3); B contains C (depth 4). C also calls itself recursively three times from the first call. Within the innermost recursive activation of C, how many access links must be followed to reach (i) a variable declared in A, and (ii) one declared in main?
- A. 5 and 6
- B. 2 and 3
- C. 3 and 4
- D. 2 and 2
Correct answer: B. 2 and 3
Access links follow lexical nesting, not the call chain: every C frame's link points to a B frame, so A is 4 − 2 = 2 links away and main is 4 − 1 = 3 links away, however deep the recursion is.
More Compiler Design questions
- void p(int x, int y) { x = x + 1; y = y + x; } is called as p(a, a) with a = 2. What is a after the call when the parameters are passed by…
- How many distinct LR(0) items does the grammar E → T E'; E' → + T E' | ε; T → F T'; T' → F T' | ε; F → ( E ) | id have (do not augment it…
- Dead-code elimination deletes every assignment whose target is not live immediately after it (live-variable analysis), and is repeated…
- Same function f(n) = 1 for n ≤ 2, else f(n − 1) + f(n − 2) + f(n − 3). Each activation record takes 28 bytes. What is the maximum stack…
- The SLR(1) table of S → i E t S Z | a; Z → e S | ε; E → b has one shift-reduce conflict (shift e versus reduce Z → ε), resolved as yacc…
- G: S → a A d | b B d | a B e | b A e; A → c; B → c is LR(1) but not LALR(1). Which of these changes, each made on its own, makes the…