GATE Computer ScienceHardGATE CS (PYQ pattern)
For E → T R; R → + T R | − T R | ε; T → F P; P → ^ T | ε; F → ( E ) | id, compute FOLLOW of every non-terminal ($ counts as a member). What is the sum of the sizes of the five FOLLOW sets?
- A. 15
- B. 17
- C. 13
- D. 19
Correct answer: B. 17
FOLLOW(E) = {$, )} = FOLLOW(R). FOLLOW(T) = {+, −} ∪ FOLLOW(R) = {+, −, $, )}. P → ^ T gives FOLLOW(T) ⊇ FOLLOW(P) and T → F P gives FOLLOW(P) ⊇ FOLLOW(T), so FOLLOW(P) = FOLLOW(T). FOLLOW(F) = {^} ∪ FOLLOW(T) (P nullable) = 5 symbols. Sum 2 + 2 + 4 + 4 + 5 = 17.
More Compiler Design questions
- A basic block is converted to a DAG using value numbering, treating + and as commutative, reusing an existing node when the same operator…
- Minimal SSA form is built for 1: if p > 0 goto L2; 2: L1: x = x + 1; 3: if x > n goto L3; 4: L2: y = y + x; 5: if y < m goto L1; 6: L3…
- L is the set of strings over {a, b} that contain abab as a substring but do not end with abab. How many states does the minimal complete…
- An LR parser for E → T E′; E′ → + T E′ | ε; T → F T′; T′ → F T′ | ε; F → ( E ) | id parses "id + id id". How many reductions does it make…
- For each choice of terminals x, y ∈ {a, b, c} consider G(x, y): S → A x B; A → a A | ε; B → b B | y. Of the nine grammars, how many are…
- The grammar S → a S | S a | b is ambiguous. How many distinct parse trees does the string "a a a b a a" have?