# Ambiguous Grammar to Unambiguous Grammar

I'm wondering if somebody can please help me to understand how I go about converting this grammar to an unambiguous grammar. If you can point me in the right direction, I would greatly appreciate it.

S -> AB | aaB

A -> a | Aa

B -> b

• What have you tried and where did you get stuck? have you checked out other questions about formal-grammars+ambiguity?
– Raphael
Oct 30, 2014 at 9:41

It is quite simple, basically your CFG is ambiguous because of production $$S\rightarrow aaB$$. We can remove it but CFG must derive this means if we remove and CFG does not generate $$aab$$ then our approach will be waste so you just remove it and after removing you grammar will be like \begin{align} &S\rightarrow AB\\ &A\rightarrow a \mid Aa\\ &B\rightarrow b\\ \end{align} Now there is no ambiguity, you can check and suggest me if I'm wrong.