GATE Computer ScienceModerateGATE CS (PYQ pattern)
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?
- A. 4
- B. 7
- C. 2
- D. 5
Correct answer: D. 5
Count trees by splitting the string at every possible point and multiplying the counts for each part (a CYK-style count); the total is 5.
More Compiler Design questions
- 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…
- With int i = 2 and the array A = [0, 3, 5, 7, 9, 11, 13] (indices from 0), the call f(A[i], i) is made to void f(p, q) { i = i + 1; p = p…
- How many states does the minimal complete DFA (dead state included) for the regular expression (ab | aba) over {a, b} have?
- 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…