Removing epsilon productions from a Context-free Grammar

6.1k Views Asked by At

There is just one part of the grammar I am having trouble with, it reads:

$$C\to CBA\mid\epsilon$$

After removing the epsilon production, I get:

$$C\to CBA\mid BA\mid CB\mid B$$

I'm confused as to whether this is correct or not. Does the latter grammar have to also include all other possible combinations from $CBA$, such as $CA$ and/or $A$?

1

There are 1 best solutions below

5
On BEST ANSWER

Removing the $\epsilon$ production from $C\to CBA\mid\epsilon$ gives you $C\to CBA\mid BA$, where the production $C\to BA$ represents the possibility of a derivation $C\Rightarrow CBA\Rightarrow BA$ using the original $C$ productions. It does not give you $C\to CB$ or $C\to B$: there is no derivation from $C$ to $CB$ or to $B$ that uses only the original $C$ productions $C\to CBA$ and $C\to\epsilon$.

If the grammar originally had a production $A\to\epsilon$, removing that $\epsilon$ production would force you to include $C\to CB$, and then removing $C\to\epsilon$ would force you to add $C\to B$ as well, but neither is needed just to compensate for removing $C\to \epsilon$.