Chomsky Normal Form
CS 133 : Automata Theory and Computability Context-Free Grammars and Languages Henry N. Adorna Nestine Hope S. Hernandez Algorithms and Complexity Laboratory Department of Computer Science University of the Philippines, Diliman {hnadorna,nshernandez}@dcs.upd.edu.ph
LEC 5
Chomsky Normal Form
Context-Free Grammars and Languages
Chomsky Normal Form
Chomsky Normal Form
Context-Free Grammars and Languages
Chomsky Normal Form
Chomsky Normal Form
Definition A CFG is in Chomsky normal form if every rule is of the form A A
→ →
BC a
where a is any terminal and A, B, C are any variables except that B and C may not be the start variable. In addition we permit the rule S → ε, where S is the start variable.
Chomsky Normal Form
All CFGs can be converted to CNF.
Chomsky Normal Form
All CFGs can be converted to CNF.
Outline of conversion algorithm 1. Create a new start symbol S0 , with new rule S0 → S 2. Remove "nullable" variables 3. Remove "unit pairs" 4. Restructure rules whose right hand sides have length greater than 1 and include terminals 5. Restructure rules with long right hand sides
Chomsky Normal Form
All CFGs can be converted to CNF.
Outline of conversion algorithm 1. Create a new start symbol S0 , with new rule S0 → S 2. Remove "nullable" variables 3. Remove "unit pairs" 4. Restructure rules whose right hand sides have length greater than 1 and include terminals 5. Restructure rules with long right hand sides
Example S → ASA | aB A→ B |S B→ b|ε
Chomsky Normal Form
Convert the following CFG into CNF: 1. S A B
→ → →
ASB | ε aAS |a SbS | A |bb
2. S A B C
→ → → →
0A0 | 1B1 |BB C S|A S|ε
3. S A B
→ → →
AAA | B aA |B ε
4. S A B A B
→ → → → →
aAa | bBb | ε C |a C |b CDE |ε A | B |ab
Chomsky Normal Form
Questions? See you next meeting!