Using the given grammar, there are two left most derivations for the string if b then if b then a else a
as follows.
Derivation 1:
if expr then stmt stmt'
if b then stmt stmt'
if b then if expr then stmt stmt' stmt'
if b then if b then stmt stmt' stmt'
if b then if b then a stmt' stmt'
if b then if b then a stmt'
if b then if b then a else stmt
if b then if b then a else a
Derivation 2:
if expr then stmt stmt'
if b then stmt stmt'
if b then if expr then stmt stmt' stmt'
if b then if b then stmt stmt' stmt'
if b then if b then a stmt' stmt'
if b then if b then a else stmt stmt'
if b then if b then a else a stmt'
if b then if b then a else a
The parse trees remains same for most part. But after deriving if b then if b then a stmt' stmt'
, the order of nodes changes thus affecting the structure of the tree. Hence the given grammar is ambiguous.