GATE Computer ScienceVery hardGATE CS (PYQ pattern)
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 multiply-defined cells, M[S, b] and M[A, a]. III. G is ambiguous. IV. G is SLR(1).
- A. I and II only
- B. II and III only
- C. I, II and III only
- D. I, II, III and IV
Correct answer: C. I, II and III only
FIRST(S) = {a, b} = FIRST(A). FOLLOW(S) = {$} ∪ FIRST(A) = {$, a, b} (S → A S makes S end S; A → S A puts FIRST(A) after S); FOLLOW(A) = FIRST(S) ∪ FOLLOW(A) = {a, b}; $ never follows A, so I holds. S → A S and S → b both go to M[S, b]; A → S A and A → a both to M[A, a]. a b a b has two trees, so G is ambiguous and cannot be SLR(1).
More Compiler Design questions
- 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…
- int f(int n) { if (n <= 2) return 1; return f(n − 1) + f(n − 2) + f(n − 3); } How many calls to f (including the first) does f(8) make as…
- For S → A B; A → a A | ε; B → b B | ε (augmented), in how many states of the LR(0) automaton is there a conflict, and is the grammar SLR(1)?