Convert the grammar below into Chomsky Normal Form. Give all the intermediate steps.
S -> AB | aB
A -> aab|lambda
B -> bbA
Ok so the first thing I did was add a new start variable S0
so now I have
S0 -> S
S -> AB | aB
A -> aab|lambda
B -> bbA
then I removed all of the lambda rules:
S0 -> S
S -> AB | aB | B
A -> aab
B -> bbA | bb
Then I checked for S->S and A->B type rules which did not exist. And that was the answer I came up with, do I need to do anything further or did I do anything wrong?
Wikipedia says:
Continuing your work:
Instead of using
|to denote different choices, split a rule into multiple rules.Create new rules
Y -> aandZ -> bbecause we will need them soon.S -> aBis not of the formS -> BCbecauseais a terminal. So changeaintoY:Do the same for the
B -> bbrule:For
A -> aab, createC -> YY; forB -> bbA, createD -> ZZ:For
S -> B, duplicate the one rule whereSoccurs on the right hand side and inline the rule:Deal with the rules
S0 -> BandS0 -> Sby joining the right hand side to the left hand sides of other rules. Also, delete the orphaned rules (where the LHS symbol never gets used on RHS):And we’re done. Phew!