GATE | Gate IT 2005 | Question 87
Q 83_Part B
Consider the context-free grammar
E → E + E
E → (E * E)
E → id
where E is the starting symbol, the set of terminals is {id, (,+,),*}, and the set of non-terminals is {E}.
For the terminal string id + id + id + id, how many parse trees are possible?
(A) 5
(B) 4
(C) 3
(D) 2
Answer: (A)
Explanation: Background Required to solve the question – Parse Tree Construction.
Explanation : In order to produce the yield id + id + id + id , we only required 3 productions of type E → E + E as 3 ‘+’ are required in the final string. This can be done in 5 ways as shown in the picture given below:
This explanation has been provided by Pranjul Ahuja.
Quiz of this Question
Please Login to comment...