Prove that the following grammar is ambiguous a b

Prove that the following grammar is ambiguous:

          <exp> ::= <exp> + <exp>

          | <exp> * <exp>

          | ( <exp> )

          | a | b | c

Solution

exp => exp + exp

=>exp * exp + exp ( exp -> exp*exp)

=>a * exp + exp (exp ->a)

=>a*b+exp (exp->b)

=> a*b+c (exp->c)

exp =>exp + exp

=>exp+exp * exp (exp->exp * exp)

=>a +exp * exp (exp->a)

=>a+b*exp (exp->b)

=>a+b*c (exp->c)

thus this grammer defines two different derivations / parse trees.
So that it is said ambiguouse grammer.

Prove that the following grammar is ambiguous: <exp> ::= <exp> + <exp> | <exp> * <exp> | ( <exp> ) | a | b | cSolutionexp =&

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site