You are on page 1of 13

Chomsky Normal Form

• Definition Chomsky Normal Form (CNF)


A CFG is in Chomsky Normal Form if all productions are of the form
A→ a X

with a € T (terminals )and X € V*(non-terminals)

This means, all productions start with a terminal on the PRODUCTION and
have only variables following.

1
Chomsky Normal Form (CNF)
Theorem:

•Every CFG G with L(G) exists with an equivalent grammar G' in CNF

•Chomsky Normal Form is straightforward ways of improving grammar without


changing resultant language

2
Chomsky Normal Form
Conversion of the given grammar into Chomsky NF:
• Start with a grammar G = ( V, T, P, S)
•Eliminate useless variables that cannot become terminals.
•Eliminate useless variables that cannot be reached.
•Eliminate λ-productions.
•Eliminate unit productions.

Then, this grammar will be converted into an equivalent grammar in Chomsky


NF.

3
Eliminate useless variables
Eliminate useless variables that cannot become terminals
Consider below grammar
S → aA |bB
A → aA | a
B → bB
In this grammar S →B from B cannot become terminals
So B from production S →B are useless and can be eliminated

4
Eliminate useless variables
Eliminate useless variables that cannot be reached
Consider below grammar
S → aA |bB
A → aA | a
B → bB
D → ab |Ea
E → aC | d
In this grammar D and E variables that cannot be reached
So B from production D → ab |Ea and E → aC | d
are useless and can be eliminated
5
Nullable Variables

Nullable Variables
A variable A in a CFG G = (V, Σ, S, P) is defined as nullable if:
Base case: P contains the production A → λ

6
Eliminating null productions
• Eliminating λ-productions
Initialize P 1 = P

Find set of all nullable variables N in G

–Example: A → BBCD
B→λ
B is null able leads to (B → λ)
A → BCD | BCD | CD Clean up
Delete all λ-productions from P 1 –Delete any duplicate productions
A → BCD | CD

7
Eliminating unit productions
• Making CNF grammar First eliminate λ-productions

• Then eliminate unit productions

8
Eliminating unit productions
Eliminate unit productions New grammar:
S → AB S → AB
A→ a A→a
B→C|b B→D|b
D → E | bc
C→D
E → d | Ab
D →E| bc
E → d | Ab

9
Chomsky Normal Form
The given grammar is converted into Chomsky NF using following:

• Start with a grammar G = ( V, T, P, S)


•Eliminate useless variables that cannot become terminals.
•Eliminate useless variables that cannot be reached.
•Eliminate λ-productions.
•Eliminate unit productions.

10
•   Identify the unit productions from the following grammar

S -> AB
A -> a
B -> C / b
C -> D
D -> E
E -> a

11
•  Identify the unit productions from the following grammar
S -> AB
A -> a
B -> C / b
C -> D
D -> E
E -> a

Solution:
There are 3 unit production in the grammar
B -> C
C -> D
D -> E

12
Thank you

13

You might also like