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:

  1. A.

    The string "id +id×id " has no parse tree according to G

  2. B.

    The string "id +id× id" has only one parse tree according to G

  3. C.

    The string "id +id×id " has exactly two parse trees according to G

  4. 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.

image.png

Explore the full course: Isro