GATE Computer ScienceVery hardGATE CS (PYQ pattern)
For the grammar G: S → A b | B c; A → a A | ε; B → a B | ε, the LL(1) predictive table is built. Which statement is correct?
- A. Only M[S, a] is multiply defined; G is not LL(k) for any k, yet L(G) has an LL(1) grammar
- B. M[S, a], M[A, a] and M[B, a] are multiply defined, and no LL(1) grammar generates L(G)
- C. Only M[S, a] is multiply defined, and G is LL(2) because two symbols separate A b from B c
- D. No cell is multiply defined, because FIRST(A b) = {a, b} and FIRST(B c) = {a, c} differ
Correct answer: A. Only M[S, a] is multiply defined; G is not LL(k) for any k, yet L(G) has an LL(1) grammar
FIRST(A b) = {a, b} and FIRST(B c) = {a, c} meet only in a, so M[S, a] holds both S-productions. M[A, a] holds only A → a A (FOLLOW(A) = {b}) and M[B, a] only B → a B (FOLLOW(B) = {c}). Both alternatives of S begin with an unbounded run of a's, so no fixed k of lookahead separates a^k b from a^k c: G is not LL(k). But L(G) = a*b ∪ a*c is generated by the LL(1) grammar S → a S | b | c.
More Compiler Design questions
- For G: S → a A | b B; A → c A d | ε; B → c B d d | ε, which statements are true? I. G is LL(1). II. G is LR(0). III. The canonical LR(1)…
- A scanner has two token rules, R1 = a b and R2 = b c. It always takes the longest prefix matching some rule and never backtracks over a…
- Register allocation by graph colouring is done on the loop 1: L1: v1 = v4 + 1; 2: v2 = v5 + 1; 3: v3 = v1 + 1; 4: v4 = v2 + 1; 5: v5 = v3…
- An array is declared A[L..10][−4..5] with 4-byte elements and stored in row-major order starting at address 1744. If the address of…
- For S → a A | b B; A → c A d | ε; B → c B d d | ε (augmented with S′ → S), count the reduce entries (state, terminal) in the ACTION…
- S → C C; C → c C | d is LR(0). In its LR(0) parsing table the reduce action for a complete item is written in every terminal column…