GATE Computer ScienceHardGATE CS (PYQ pattern)
The grammar S → S S S | a is ambiguous. How many distinct parse trees do the strings a⁷ (seven a's) and a⁶ (six a's) have, respectively?
- A. 12 and 5
- B. 55 and 12
- C. 12 and 0
- D. 42 and 0
Correct answer: C. 12 and 0
Each use of S → S S S adds two leaves, so derivable strings have odd length: a⁶ has no tree. Parse trees of a⁷ are full ternary trees with 3 internal nodes, counted by the ternary Catalan number C(9, 3)/(2·3 + 1) = 84/7 = 12.
More Compiler Design questions
- Build the SLR(1) table of the ambiguous grammar E → E + E | E E | id (augmented with S′ → E). How many LR(0) states are there, and how…
- For S → A a A b | B b B a; A → ε; B → ε (augmented), how many ACTION cells are multiply defined in the LR(0), SLR(1) and LALR(1) tables…
- For G: S → a A c | a B d | B c; A → z; B → z, which statements are true? I. The canonical LR(1) automaton has the same number of states as…
- S → a S | b S | c is LR(0). In its LR(0) parsing table the reduce action for a complete item is written in every terminal column including…
- For the production A → B C D (A.i, B.i, C.i, D.i inherited; A.s, B.s, C.s, D.s synthesised), which rule set makes the SDD L-attributed?
- Productions are numbered (1) S → ( L ); (2) S → x; (3) L → S; (4) L → L , S. A shift-reduce parser parses "( x , ( x ) )". In which order…