Chomsky Normal Form and Grammar Cleanup

Convert productions to binary steps while preserving the generated nonempty strings and handling the empty string separately.

Source
Anbloq
Language
English
Created
Updated
Chapters
2
Reading time
1 min
In this article2 chapters
  1. Eliminate rules that hide missing or repeated steps
  2. Isolate terminals and combine pairs

Eliminate rules that hide missing or repeated steps

First choose a fresh start symbol so the original start can appear on right-hand sides without affecting special empty-string handling. Compute nullable variables by a fixed point, then add productions omitting nullable occurrences where appropriate. Remove epsilon productions except an optional fresh start rule. Eliminate unit productions such as \(A\to B\) by copying reachable non-unit alternatives into \(A\). Useless symbols can then be discarded.

Isolate terminals and combine pairs

Replace terminals appearing inside multi-symbol right-hand sides with variables such as \(T_a\to a\). Replace a long production \(A\to BCD\) with \(A\to BX,X\to CD\) using a fresh \(X\). The resulting nonempty grammar uses \(A\to BC\) or \(A\to a\), apart from the permitted start exception. This structural conversion preserves membership but may change parse provenance. CYK relies on exactly the single split made by each binary rule. Grammar ambiguity explains why membership alone may be insufficient for an application.[1][2]

References

  1. John Hopcroft, Rajeev Motwani and Jeffrey Ullman, Context-Free Grammars and Languages ↩
  2. Michael Sipser, Introduction to the Theory of Computation ↩