GATE Computer ScienceModerateGATE CS (PYQ pattern)
The grammar S → i S | i S e S | a is ambiguous. How many distinct parse trees does the string "i i i a e a e a" have?
- A. 3
- B. 6
- C. 5
- D. 4
Correct answer: A. 3
Count trees by splitting the string at every possible point and multiplying the counts for each part (a CYK-style count); the total is 3.
More Compiler Design questions
- int A(int m, int n) { if (m == 0) return n + 1; if (n == 0) return A(m - 1, 1); return A(m - 1, A(m, n - 1)); } Each activation record…
- For S → id | id [ E ] | id ( E ); E → id (augmented with S′ → S), how many states do the LR(0) and the canonical LR(1) automata have?
- The grammar S → A B; A → a A | a; B → a B | a is ambiguous. How many distinct parse trees does the string "a a a a a a" have?
- For the declaration grammar D → T L; T → int | float; L → L , id | id (augmented with D′ → D), how many states does the LR(0) automaton…
- Build the SLR(1) table of S → A a | b A c | d c | b d a; A → d (augmented). Which option describes all of its conflicts?
- Compute FIRST of every non-terminal of S → A B | B C; A → a A | ε; B → b B | ε; C → c C | c, treating ε as a member of FIRST when the…