Note
Note
Algorithm 1 Derivable(G, A)
1: Input: CFG G = (V, T, R, S) and a variable A ∈ V .
2: Output: Set W of A-derivable variables in the grammar G.
3: W ← ∅, W 0 ← ∅
4: for (each production A → B ∈ R) do
5: W = W ∪ {B}
6: end for
7: while (W 0 6= W ) do
8: W0 = W
9: for (each C ∈ W 0 ) do
10: for (each C → B ∈ R such that B 6= A) do
11: W = W ∪ {B}
12: end for
13: end for
14: end while
15: Return (W )
1
• If G = (V, T, R, S) is a CFG with no null production, then we can design a algo-
rithm (see Algorithm 2) to find a CFG G1 = (V, T, R1 , S) having no unit production
such that L(G1 ) = L(G).
1. Eliminate -productions.
2
Further, G has no useless symbols. Such a grammar is said to be Chomsky Normal
Form, or CNF.
To put a grammar in CNF, start with one that satisfies the following restrictions:
Theorem: If G is a CFG whose language contains at least one string other than
, then there is a grammar G1 in Chomsky Normal Form, such that L(G1 ) =
L(G) − {}.
1
If A → α is a production, then the part α is said to be body of that production.