All grammars are not always optimized, which means the grammar may consist of some extra symbols (non-terminals) which increase the length of grammar.
So, we have to reduce the grammar by removing the useless symbols.
The properties to reduce grammar are explained below −
The diagram given below depicts the use of reduce grammar−
The productions of type S-> ε are called ε productions
These types of production can only be removed from the grammars that do not generate ε
First find all null-able non terminals which derive.
For each production A->a construct all productions A. where X is obtained from 'a' by removing 1 or more non-terminals from step 1.
Now combine the result of step 2 with the original production and remove ε production.
While removing ε production we are deleting the rule X-> ε and Y-> ε
To preserve the meaning of CFG we are placing ε at right hand side wherever X and Y appear
If the first X at the right hand side is ε
Similarly, if the last X at the right hand side is ε
If Y= ε,
If both Y and X are ε,
If both x are replaced,
Now let us consider,
If we replace ε at right hand side for X then,
The CFG with removal of epsilon production as follows,