Context-Free Languages: Simplification & Normal Forms

why normal forms exist

Imagine you are handed a thick recipe book where every cook wrote in their own style. One says 'add a pinch of salt', another writes a chemical formula, a third draws a picture. To build a machine that follows any recipe automatically, you would first rewrite them all into one rigid template: each line is exactly one action on at most two ingredients. The recipes still make the same dishes, but now a simple machine can read them. A normal form for a grammar is exactly this kind of template: a fixed, predictable shape that every rule must fit into.

A context-free grammar (CFG) is a set of rules like A -> aB or S -> AB | a, where capital letters are variables (nonterminals) you can keep rewriting and lowercase letters are terminals you cannot. In its raw form a grammar lets you write a rule of almost any shape, which is convenient for humans but awful for machines and for proofs. A normal form restricts the allowed rule shapes so that every rule looks the same. Two famous ones are Chomsky normal form (CNF), where each rule is A -> BC or A -> a, and Greibach normal form (GNF), where each rule starts with a terminal, A -> a alpha. The key fact is that every CFG can be rewritten into these forms while generating exactly the same language (apart from the empty string, handled separately).

Normal forms exist because uniform shapes make mechanical reasoning possible. CNF's neat binary-branching parse trees are what let the CYK algorithm fill a table in O(n^3) time and what make the context-free pumping lemma and many proofs by induction go through cleanly. GNF guarantees a terminal is consumed at every derivation step, which bounds derivation length and bridges to predictive parsing and to a tidy pushdown-automaton construction. The honest cost: the conversion can enlarge the grammar and it changes the parse trees, so any meaning attached to the original rules must be reattached afterward.

The same language {a^n b^n : n >= 1} can be written messily as S -> aSb | ab, or in CNF as S -> AX, X -> SB, S -> AB, A -> a, B -> b. Both generate exactly aabb, aaabbb, and so on; only the second fits a uniform template a machine can chew through.

Same language, two shapes: a normal form trades human readability for machine-friendly uniformity.

A normal form does not give a grammar more expressive power: it still generates a context-free language, no more and no less. It only standardizes the shape of the rules.

Also called
standard formcanonical grammar shape正規形式標準形式