Module 4 CNF
Module 4 CNF
Simplification of CFGs
• Useless productions: The productions that can never
take part in derivation of any string.
S -> AB, A -> a, B -> b, C -> dc (useless symbol)
Steps:
1. Elimination of useless symbols
2. Elimination of ε production
3. Elimination of Unit production
(Refer Class notes for solution)
Chomsky Normal Form
• A way to simplify a context-free grammar
– Start symbol can have ε production. S → ε
E.g.1 S (L) | a
LL,S|S
E.g.2 A AC | Aad | bd | ε
E.g.3 A2 A2 A2 A1 | 0A1 | 1
(Refer Class notes for complete solution)
GREIBACH NORMAL FORM (GNF)
• Greibach Normal Form (GNF) is a form of a context-
free grammar where every production rule follows
the format:
A→aα
where
A is a non-terminal,
a is a terminal, and
α is a (possibly empty) sequence of non-
terminals.
Procedure for Converting CFG to GNF
Step 1. If the given grammar is not in CNF, convert it to CNF.
Step 2. Change the names of non terminal symbols to A1 till AN in
same sequence. (A1 => Start Symbol)
Step 3. Ai Ajβ 3 cases i < j, i > j,
i=j
Case 1: if Ai Ajβ and i < j, Leave the production as such
Case 2: if Ai Ajβ and i > j, Replace Aj with its production
bodies
Case 3: if Ai Ajβ and i = j, Eliminate Left Recursion, ε –
production and introduce new variable B.
Step 4. Repeat Step 3 until we reach the production of the form
A→aα
CFG to GNF
S → AA | 0
A → SS | 1
Union: L3 = L1 U L2
Intersection: L3 = L1.L2