A context-free grammar is in Chomsky normal form when every production rule has one of the formswhere are nonterminal symbols and is a terminal symbol. If the language contains the empty word, one may additionally permit , with the start symbol absent from all right-hand sides.
The standard conversion of a context-free grammar to Chomsky normal form proceeds as follows:
Add a fresh start symbol with .
Find the nullable nonterminals, add the variants obtained by omitting nullable occurrences, and remove all epsilon productions. Omit as well because the requested language excludes .
Remove every unit production by copying the non-unit productions reachable from to .
Remove nonterminals that are unreachable from or cannot derive a terminal word.
In every right-hand side of length at least two, replace a terminal by a fresh nonterminal with .
Replace each right-hand side of length greater than two by a chain of binary productions using fresh nonterminals.
Find the nullable nonterminals, add the variants obtained by omitting nullable occurrences, and remove all epsilon productions. Omit as well because the requested language excludes .
Remove every unit production by copying the non-unit productions reachable from to .
Remove nonterminals that are unreachable from or cannot derive a terminal word.
In every right-hand side of length at least two, replace a terminal by a fresh nonterminal with .
Replace each right-hand side of length greater than two by a chain of binary productions using fresh nonterminals.
Each remaining production is of the required binary or terminal form, and these transformations preserve every nonempty generated word. Thus .
The original grammar generatesbecause each use of adds one on the left and one on the right, and terminates the derivation.
Introduce nonterminals and useEvery production is in Chomsky normal form. The production completes one matched pair, while either start-like symbol terminates with , so the grammar generates exactly the same language. These productions are a valid .
Articles by others on the same topic
There are currently no matching articles.