Computer Science EngineeringHardISRO SC
With the ambiguous grammar E -> E + E | E * E | id, how many distinct parse trees does the string id + id * id + id * id + id * id have?
- A. 132
- B. 134
- C. 131
- D. 36
Correct answer: A. 132
With n=6 binary operators, the number of full binary bracketings is the Catalan number C_6 = 132; precedence is not encoded in the grammar.
Practise more Theory of Computation, Compilers & Digital Logic (ISRO CS) questionsTheory of Computation, Compilers & Digital Logic (ISRO CS): notes and key points
More Theory of Computation, Compilers & Digital Logic (ISRO CS) questions
- The grammar S -> aS | Sa | a is ambiguous. How many parse trees does a^5 have?
- For the dangling-else grammar S -> i S e S | i S | a (i = if, e = else, a = other statement), how many parse trees derive iiiaeaea?
- The CYK algorithm runs on a string of length 10 with a grammar in Chomsky normal form. Counting each (cell, split point) pair as one step…
- A grammar in Chomsky normal form derives a string of length 9. The number of derivation steps (rule applications) in any derivation is
- Consider the grammar E -> E+T | T; T -> TF | F; F -> (E) | id. The canonical LR(0) collection (with the augmented production S' -> start…
- For the grammar E -> E+T | T; T -> TF | F; F -> (E) | id, how many total LR(0) items (all dotted positions over all productions, excluding…