0% found this document useful (0 votes)
138 views7 pages

Chomsky Chomsky Normal Form Conversion

The document discusses Chomsky normal form (CNF), which is a normalized form for context-free grammars. There are two main types of normalized forms: CNF and Greibach normal form. Not all context-free grammars are CNF, but all CNF grammars are context-free. The document outlines the four steps to convert a context-free grammar into CNF: 1) remove null productions, 2) remove unit productions, 3) convert mixed terminals and variables to capital letters, and 4) reduce the number of variables to two. It provides examples applying these steps to convert sample grammars into CNF.

Uploaded by

Taufeeq Rind
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
138 views7 pages

Chomsky Chomsky Normal Form Conversion

The document discusses Chomsky normal form (CNF), which is a normalized form for context-free grammars. There are two main types of normalized forms: CNF and Greibach normal form. Not all context-free grammars are CNF, but all CNF grammars are context-free. The document outlines the four steps to convert a context-free grammar into CNF: 1) remove null productions, 2) remove unit productions, 3) convert mixed terminals and variables to capital letters, and 4) reduce the number of variables to two. It provides examples applying these steps to convert sample grammars into CNF.

Uploaded by

Taufeeq Rind
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Chomsky Normal Form (CNF)

Solution

What is CNF?
Chomsky normal form is the normalized form of Context free Grammar

Types of Normalized Form of CFG’s

There are 2 types:

1. CNF (Chomsky Normal Form)


2. GNF (Greibach Normal Form)

All CFG’s are CNF?

No, All CFG’s May or May Not CNF but all CNF’s are always CFG’s.

Steps of Conversion from CFG to CNF

There are 4 steps:

1. Remove/Kill all Null Productions


2. Remove all Unit Productions
3. Convert all Mix Terms (Terminals + Variables )into Capitals ; If Terms are not mixed then
check if there are 2 or more terminals then convert them into capitals ; if there is only
one single terminal don’t convert it into capital.
4. Reduce the number of variables upto 2 variables.
Example Question 1: Covert the following given CFG into its respective CNF form.

1. S->abAB
2. A->bAB
3. A->Λ
4. B->BAa
5. B->A
6. B->Λ

Solution

Step # 1: Remove/Kill all Null Productions


1. S->abAB 1. S->abAB
2. A->bAB S->abB (Place Λ in A)
3. A->Λ S->abA (Place Λ in B)
4. B->BAa S->ab (Place Λ in both A , B)
5. B->A 2. A->bAB
6. B->Λ A->bB (Place Λ in A)
A->bA (Place Λ in B)
A->b (Place Λ in both A , B)
4. B->BAa
B->Ba (Place Λ in A)
B->Aa (Place Λ in B)
B->a (Place Λ in both A , B)
5. B->A
So after removing all Null Productions we will
get above mentioned 13 Productions
Step # 2: Remove all Unit Productions
1. S->abAB 1. S->abAB
2. S->abB 2. S->abB
3. S->abA 3. S->abA
4. S->ab 4. S->ab
5. A->bAB 5. A->bAB
6. A->bB 6. A->bB
7. A->bA 7. A->bA
8. A->b 8. A->b
9. B->BAa 9. B->BAa
10. B->Ba 10. B->Ba
11. B->Aa 11. B->Aa
12. B->a 12. B->a
13. B->A 13. B->a (Converted into small a)
14. A->a (Add Rule as we converted Capital A
into small a to remove unit production)
Step # 3: Convert all Mix Terms (Terminals + Variables )into Capitals ; If Terms are not mixed
then check if there are 2 or more terminals then convert them into capitals ; if there is only
one single terminal don’t convert it into capital.
1. S->abAB 1. S->ABAB
2. S->abB 2. S->ABB
3. S->abA 3. S->ABA
4. S->ab 4. S->AB
5. A->bAB 5. A->BAB
6. A->bB 6. A->BB
7. A->bA 7. A->BA
8. A->b 8. A->b
9. B->BAa 9. B->BAA
10. B->Ba 10. B->BA
11. B->Aa 11. B->AA
12. B->a 12. B->a
13. B->a 13. B->a
14. A->a 14. A->a
Step # 4: Reduce the number of variables upto 2 variables.

1. S->ABAB 1. S->ABAB
2. S->ABB (Reduced Productions from Production 1)
3. S->ABA S->TT
4. S->AB T->AB
5. A->BAB 2. S->ABB
6. A->BB (Reduced Productions from Production 2)
7. A->BA S->TB
8. A->b 3. S->ABA
9. B->BAA (Reduced Productions from Production 3)
10. B->BA S-> TA
11. B->AA
4. S->AB
12. B->a
5. A->BAB
13. B->a
(Reduced Productions from Production 5)
14. A->a
A-> BT
6. A->BB
7. A->BA
8. A->b
9. B->BAA
(Reduced Productions from Production 9)
B->MA
M->BA
10. B->BA
11. B->AA
12. B->a
13. B->a
14. A->a
Final CNF

1. S->TT
2. T->AB
3. S->TB
4. S-> TA

5. S->AB

6. A-> BT

7. A->BB

8. A->BA

9. A->b

10. B->MA
11. M->BA

12. B->BA

13. B->AA

14. B->a

15. B->a
16. A->a
Example Question 2: Covert the following given CFG into its respective CNF form.

S->ABA

A->aA

A->Λ

B->bB

B->Λ

Solution

Step # 1: Remove/Kill all Null Productions


1. S->ABA S->ABA
2. A->aA S->BA
3. A->Λ S->AA
4. B->bB S->AB
5. B->Λ S->A
S->B
A->aA
A->a
B->bB
B->b

So after removing all Null Productions we will


get above mentioned 10 Productions
Step # 2: Remove all Unit Productions
1. S->ABA 1. S->ABA
2. S->BA 2. S->BA
3. S->AA 3. S->AA
4. S->AB 4. S->AB
5. S->A 5. S->a
6. S->B 6. S->b
7. A->aA 7. A->aA
8. A->a 8. A->a (Duplicated with rule 11)
9. B->bB 9. B->bB
10. B->b 10. B->b (Duplicated with rule 12)
11. A->a (Add Rule as we converted Capital A
into small a to remove unit production)
12. B->b (Add Rule as we converted Capital A
into small a to remove unit production)
Step # 3: Convert all Mix Terms (Terminals + Variables )into Capitals ; If Terms are not mixed
then check if there are 2 or more terminals then convert them into capitals ; if there is only
one single terminal don’t convert it into capital.
1. S->ABA 1. S->ABA
2. S->BA 2. S->BA
3. S->AA 3. S->AA
4. S->AB 4. S->AB
5. S->a 5. S->a
6. S->b 6. S->b
7. A->aA 7. A->AA
8. A->a 8. A->a
9. B->bB 9. B->BB
10. B->b 10. B->b

Step # 4: Reduce the number of variables upto 2 variables.

1. S->ABA 1. S->ABA
2. S->BA S->MA
3. S->AA M->AB
4. S->AB
5. S->a
6. S->b 2. S->BA
7. A->AA 3. S->AA
8. A->a 4. S->AB
9. B->BB 5. S->a
10. B->b 6. S->b
7. A->AA
8. A->a
9. B->BB
10. B->b
Final CNF

S->MA

M->AB

S->BA

S->AA

S->AB

S->a

S->b

A->AA

A->a

B->BB

B->b

You might also like