Simplified Form of CFG

2 min read Updated Tue Apr 28 2026 07:56:31 GMT+0000 (Coordinated Universal Time)

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 G=(V,Σ,S,P)G=(V, \Sigma, S, P), an equivalent CFG G1=(V,Σ,S,P1)G_1=(V,\Sigma,S,P_1) (with no null-productions) can be derived using the following steps:

  • Initialize P1=PP_1 = P
  • Find all nullable non-terminals (V\subseteq V) of GG using FindNull algorithm
  • For each AαA\rightarrow \alpha in PP:
    • Add all productions that can be obtained by deleting one or more occurences of nullable non-terminals in α\alpha, to P1P_1
  • Remove Λ\Lambda-productions and AAA\rightarrow A productions from P1P_1

Ambiguity is preserved after the elimination of null productions. May increase the number of productions significantly.

Unit Productions

Rules of the form ABA \Rightarrow^* B where A,BA,B are non-terminals.

Does not add new structure to derivations. Can be removed by substitution.

Removal of unit productions

For a given CFG G=(V,Σ,S,P)G=(V, \Sigma, S, P), an equivalent CFG G1=(V,Σ,S,P1)G_1=(V,\Sigma,S,P_1) (with no unit-productions) can be derived using the following steps:

  • Initialize P1=PP_1=P
  • For each AVA \in V:
    • Find all non-terminals derivable from AA (set of AA^*)
    • For each BAB \in A^*:
      • For each BαPB \rightarrow \alpha \in P, add AαA \rightarrow \alpha to P1P_1
  • Delete all unit productions from P1P_1