Consider the context-free grammar G below for arithmetic expressions :…
2023
Consider the context-free grammar G below for arithmetic expressions :
E→E+E|E×E| id
Which of the following statements is TRUE:
- A.
The string "id +id×id " has no parse tree according to G
- B.
The string "id +id× id" has only one parse tree according to G
- C.
The string "id +id×id " has exactly two parse trees according to G
- D.
The string "id +id×id " has more than two parse trees according to G
Attempted by 85 students.
Show answer & explanation
Correct answer: C
The given grammar E→E+E|E×E|id is ambiguous. For the string 'id + id × id', there are two distinct parse trees: one grouping as (id+id)×id and another as id+(id×id). Since multiple parse trees exist for the same string, the grammar is ambiguous.
