GATE Computer ScienceHardGATE CS (PYQ pattern)
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?
- A. 6
- B. 32
- C. 5
- D. 10
Correct answer: D. 10
Every tree peels one a off the left (S → a S) or the right (S → S a) at each step until b remains. The three left a's must be peeled by a S steps and the two right a's by S a steps, in any interleaving: C(5, 2) = 10 orders, each a different tree.
More Compiler Design questions
- 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…
- The ambiguous grammar E → E − E | E E | id derives "2 − 3 4 − 5 1" (each number is an id). How many distinct parse trees does the string…