The grammar whose productions are <stmt> → if id then <stmt> <stmt> → if id…

GATE · 1996 · CS · Question 2 subparts

The grammar whose productions are

 <stmt> → if id then <stmt>

 <stmt> → if id then  <stmt> else <stmt>

 <stmt> → id := id



is ambiguous because

  1. A.

    the sentence  if a then if b then c:= d  has two parse trees

  2. B.

    the left most and right most derivations of the sentence  if a then if b then c:= d  give rise to different parse trees

  3. C.

    the sentence  if a then if b then c:= d else c:= f  has more than two parse trees

  4. D.

    the sentence  if a then if b then c:= d else c:= f  has two parse trees

Attempted by 100 students.

Show answer

Correct answer: D

The worked solution is available to enrolled students.

Explore the full course: Iocl Engineers Officers Grade A Paper 2

Loading lesson…