GATE Computer ScienceVery hardGATE CS (PYQ pattern)
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 LL(1), and how many are SLR(1)?
- A. 4 LL(1), 4 SLR(1)
- B. 6 LL(1), 6 SLR(1)
- C. 4 LL(1), 6 SLR(1)
- D. 5 LL(1), 9 SLR(1)
Correct answer: C. 4 LL(1), 6 SLR(1)
FOLLOW(A) = {x}, so x = a clashes with A → a A in M[A, a], and for LR the parser must decide to reduce A → ε before shifting a that may belong to A or be x: all three x = a grammars fail both tests. For x ∈ {b, c}: y = b makes B → b B | b clash in M[B, b] (not LL(1)) but an LR parser simply shifts b and decides at the next symbol, so it stays SLR(1). LL(1): x ∈ {b, c}, y ∈ {a, c} = 4; SLR(1): x ∈ {b, c}, any y = 6.
More Compiler Design questions
- 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?
- For S → b A d | c A e | b B e; A → x; B → x (augmented), how many ACTION cells of the SLR(1) table are multiply defined, and how many…
- 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)…
- 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…