GATE Computer ScienceModerateGATE CS (PYQ pattern)
Procedures are nested as follows: main contains P (nesting depth 2); P contains Q (depth 3) and S (depth 3); Q contains R (depth 4). main's own variables are at depth 1. At run time main calls P, P calls Q, Q calls R and R calls S. When S starts, how many access links are followed from R's frame to build S's access link, and how many links does S then follow to reach a variable declared in main?
- A. 3 and 2
- B. 2 and 2
- C. 2 and 3
- D. 1 and 2
Correct answer: B. 2 and 2
S is declared in P, so its access link must point to P's frame: R (depth 4) → Q (3) → P (2) is 2 hops. From S (depth 3) a variable in main (depth 1) is 3 − 1 = 2 links away.
More Compiler Design questions
- Which of the following is/are true? I. An LL(1) grammar can contain ε-productions. II. An LL(1) grammar is never ambiguous. III. If FIRST…
- For G: S → A S | b; A → S A | a, which statements are true? I. FOLLOW(A) ⊂ FOLLOW(S) (proper subset). II. The LL(1) table has exactly two…
- An LL(1) parser for S → A B C; A → a A | ε; B → b B | ε; C → c | ε reads the input "a b a c". At the moment it first detects the syntax…
- The ambiguous grammar E → E − E | E E | id derives "2 − 3 4 − 5 1" (each number is an id). How many distinct parse trees does the string…
- A yacc-generated parser for E → E op E | num uses the precedence declarations %right '+' '-'; %left ''; later declarations bind tighter…
- How many distinct LR(0) items does the grammar E → E + T | T; T → T F | F; F → ( E ) | id have (do not augment it; an ε-production gives…