Simplification removes unnecessary productions while preserving the language.
Λ-Productions
Aka. null productions. Allow non-terminals to derive the empty string. Null productions are removed by adding alternative productions. All combinations of nullable symbols must be considered to preserve language.
Removal of null productions
For a given CFG , an equivalent CFG (with no null-productions) can be derived using the following steps:
- Initialize
- Find all nullable non-terminals () of using FindNull algorithm
- For each in :
- Add all productions that can be obtained by deleting one or more occurences of nullable non-terminals in , to
- Remove -productions and productions from
Ambiguity is preserved after the elimination of null productions. May increase the number of productions significantly.
Unit Productions
Rules of the form where are non-terminals.
Does not add new structure to derivations. Can be removed by substitution.
Removal of unit productions
For a given CFG , an equivalent CFG (with no unit-productions) can be derived using the following steps:
- Initialize
- For each :
- Find all non-terminals derivable from (set of )
- For each :
- For each , add to
- Delete all unit productions from