1 2 3 4 5 6 7 8 9 10 11 12 Rules: S –> AB A –> aAA A –> aA A –> a B –> bB B –> b 13 14 15 16 A leftmost derivation E=>E*E =>I*E =>3*E+E =>3*I+E =>3*2+E =>3*2+I =>3*2+5 Another leftmost derivation E=>E+E =>E*E+E =>I*E+E =>3*E+E =>3*I+E =>3*2+I =>3*2+5 17 E=>E*E =>I*E =>3*E+E =>3*I+E =>3*2+E =>3*2+I =>3*2+5 E E I * E E + E E 3 Another leftmost derivation E=>E+E =>E*E+E =>I*E+E E =>3*E+E =>3*I+E =>3*2+I I =>3*2+5 3 + E * E I I 2 5 E I 5 I 2 18 Ambiguous grammar: E -> I E -> E + E E -> E * E E -> (E) I -> ε | 0 | 1 | … | 9 19 20 Rules: S -> AB | C A -> aAb | ab B -> cBd | cd String aabbccdd belongs to two different parts of the language: L ={anbncmdm | n≥1, m ≥ 1} {anbmcmdn | n ≥ 1, m ≥ 1} C -> aCd | aDd D -> bDc | bc Derivation 2 of aabbccdd: S => C => aCd => aaDdd => aa bDc dd => aabbccdd 21 22