SlideShare a Scribd company logo
1 of 8
• Step 1
Make sure the start symbol (S) doesn't appear on right hand
side. If so, add new Start symbol.
Step 2
Remove ε-productions.
Step 3
Remove unit productions.
Step 4: Break right sides longer than two into a chain of
productions with right sides of two variables.
Step 5: Make sure that the productions are in either these two
forms:
1. A -> BC (body is two variables).
2. A -> a (body is a single terminal).
So with the continuation of the previous
example,
• S0 → ASA | aB | a | SA |AS
• S → ASA | aB | a | SA | AS
• A → b | ASA | aB | a | SA | AS
• B → b
Introduce new variables.
So for S0 → ASA & S → ASA , we replace SAwith a new
variable, A1 therefore:
• S0 → ASA | aB | a | SA |AS
• S → ASA | aB | a | SA | AS
• A → b | ASA | aB | a | SA | AS
• B → b
S0 → A A1 | aB | a | SA | AS
S → A A1 | aB | a | SA |AS
A → b | A A1 | aB | a | SA |AS
A1 → SA
B → b
Recal
l:
1. A -> BC (body is
two
variables).
1. A -> BC (body is two variables).
2. A -> a (body is a single terminal).
• S0 → A A1 | aB | a | SA |AS
• S → A A1 | aB | a | SA |AS
• A → b | A A1 | aB | a | SA |AS
• A1 → SA
• B → b
So we replace right hand sides with the wrong form by
introducing a new variable just like the previous step. In this
example, A2
• S0 → A A1 | aB | a | SA |AS
• S → AA1 | aB | a | SA | AS
• A → b | A A1 | aB | a | SA |AS
• A1 → SA
• B → b
S0 → A A1 | A2 B| a | SA |AS
S → A A1 | A2 B | a | SA |AS
A → b | A A1 | A2 B | a | SA | AS
A1 → SA
A2 → a
B → b
Example
#2:
• S → aXbX
• X → aY | bY |
ε
• Y → X | c
Remove ε-productions.
Then since the right hand
of S contains X,
X → ε
S → aXbX
Consider all
cases,
Case 1: S → a ε bX
S → abX
Case 2: S → aXb ε
S → aXb
Case 3: S → a ε b ε
S → ab
The variable X is nullable
and therefore, also Y so,
X →
ε Y
→ X
Y →
ε
X → aY | bY
X → a | b add this
new production to X
Example
#2
• From previous step we
obtain, S → aXbX | abX |
aXb | ab
X → aY | bY | a |
b Y → X | c
Now we eliminate unit productions such
as
Y → X so,
S → aXbX | abX | aXb |
ab X → aY | bY | a | b
Y → aY | bY | a | b | c
Recall that:
If A =>* B by a series of
unit productions, and B -
>  is a non-unit-
production, then add
production A -> .
Example
#2 S → aXbX | abX | aXb |
ab
X → aY | bY | a | b
Y → aY | bY | a | b | c
Now we replace longer productions with shorter
ones
by adding new
variables.
D →
aX E
→ bX
New grammar:
S → DE | aE |Db|
ab X → aY | bY |
a | b
Y → aY | bY | a | b |
c D → aX
E → bX
Example
#2 S → DE | aE |Db| ab
X → aY | bY | a | b
Y → aY | bY | a | b |
c D → aX
E → bX
Then we correct the productions with wrong forms
and introduce new variables F & G:
F →
a G
→ b
Example #2
Final CNG in Chomsky Normal
Form: S → DE | FE |DF| FG
X → FY | GY | a | b
Y → FY | GY | a | b |
c D → FX
E → GX
F →
a G
→ b

More Related Content

Similar to CFG to CNF.pptx (6)

Simplifiaction of grammar
Simplifiaction of grammarSimplifiaction of grammar
Simplifiaction of grammar
 
5045.-Compiler-Design-Left-Recursion-and-Left-Factoring.pptx
5045.-Compiler-Design-Left-Recursion-and-Left-Factoring.pptx5045.-Compiler-Design-Left-Recursion-and-Left-Factoring.pptx
5045.-Compiler-Design-Left-Recursion-and-Left-Factoring.pptx
 
Chomsky & Greibach Normal Forms
Chomsky & Greibach Normal FormsChomsky & Greibach Normal Forms
Chomsky & Greibach Normal Forms
 
Simplifies and normal forms - Theory of Computation
Simplifies and normal forms - Theory of ComputationSimplifies and normal forms - Theory of Computation
Simplifies and normal forms - Theory of Computation
 
Cfg part ii
Cfg   part iiCfg   part ii
Cfg part ii
 
Geometry working with line segments
Geometry working with  line segmentsGeometry working with  line segments
Geometry working with line segments
 

More from SadagopanS (6)

partial-order.ppt
partial-order.pptpartial-order.ppt
partial-order.ppt
 
Goal stack planning.ppt
Goal stack planning.pptGoal stack planning.ppt
Goal stack planning.ppt
 
Normal forms fourth and fifth.pptx
Normal forms fourth and fifth.pptxNormal forms fourth and fifth.pptx
Normal forms fourth and fifth.pptx
 
Bermuda Triangle.pptx
Bermuda Triangle.pptxBermuda Triangle.pptx
Bermuda Triangle.pptx
 
Minimization of DFA.pptx
Minimization of DFA.pptxMinimization of DFA.pptx
Minimization of DFA.pptx
 
AWS Cloud9 to GitHub .pdf
AWS Cloud9 to GitHub .pdfAWS Cloud9 to GitHub .pdf
AWS Cloud9 to GitHub .pdf
 

Recently uploaded

SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project research
CaitlinCummins3
 
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
中 央社
 
Poster_density_driven_with_fracture_MLMC.pdf
Poster_density_driven_with_fracture_MLMC.pdfPoster_density_driven_with_fracture_MLMC.pdf
Poster_density_driven_with_fracture_MLMC.pdf
Alexander Litvinenko
 

Recently uploaded (20)

SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project research
 
Chapter 7 Pharmacosy Traditional System of Medicine & Ayurvedic Preparations ...
Chapter 7 Pharmacosy Traditional System of Medicine & Ayurvedic Preparations ...Chapter 7 Pharmacosy Traditional System of Medicine & Ayurvedic Preparations ...
Chapter 7 Pharmacosy Traditional System of Medicine & Ayurvedic Preparations ...
 
Improved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio AppImproved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio App
 
Implanted Devices - VP Shunts: EMGuidewire's Radiology Reading Room
Implanted Devices - VP Shunts: EMGuidewire's Radiology Reading RoomImplanted Devices - VP Shunts: EMGuidewire's Radiology Reading Room
Implanted Devices - VP Shunts: EMGuidewire's Radiology Reading Room
 
Including Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdfIncluding Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdf
 
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
 
Poster_density_driven_with_fracture_MLMC.pdf
Poster_density_driven_with_fracture_MLMC.pdfPoster_density_driven_with_fracture_MLMC.pdf
Poster_density_driven_with_fracture_MLMC.pdf
 
The Ball Poem- John Berryman_20240518_001617_0000.pptx
The Ball Poem- John Berryman_20240518_001617_0000.pptxThe Ball Poem- John Berryman_20240518_001617_0000.pptx
The Ball Poem- John Berryman_20240518_001617_0000.pptx
 
IPL Online Quiz by Pragya; Question Set.
IPL Online Quiz by Pragya; Question Set.IPL Online Quiz by Pragya; Question Set.
IPL Online Quiz by Pragya; Question Set.
 
Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...
 
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
 
Capitol Tech Univ Doctoral Presentation -May 2024
Capitol Tech Univ Doctoral Presentation -May 2024Capitol Tech Univ Doctoral Presentation -May 2024
Capitol Tech Univ Doctoral Presentation -May 2024
 
UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024
 
Envelope of Discrepancy in Orthodontics: Enhancing Precision in Treatment
 Envelope of Discrepancy in Orthodontics: Enhancing Precision in Treatment Envelope of Discrepancy in Orthodontics: Enhancing Precision in Treatment
Envelope of Discrepancy in Orthodontics: Enhancing Precision in Treatment
 
The Liver & Gallbladder (Anatomy & Physiology).pptx
The Liver &  Gallbladder (Anatomy & Physiology).pptxThe Liver &  Gallbladder (Anatomy & Physiology).pptx
The Liver & Gallbladder (Anatomy & Physiology).pptx
 
“O BEIJO” EM ARTE .
“O BEIJO” EM ARTE                       .“O BEIJO” EM ARTE                       .
“O BEIJO” EM ARTE .
 
How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17
 
An overview of the various scriptures in Hinduism
An overview of the various scriptures in HinduismAn overview of the various scriptures in Hinduism
An overview of the various scriptures in Hinduism
 
BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...
BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...
BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...
 
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjStl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
 

CFG to CNF.pptx

  • 1. • Step 1 Make sure the start symbol (S) doesn't appear on right hand side. If so, add new Start symbol. Step 2 Remove ε-productions. Step 3 Remove unit productions. Step 4: Break right sides longer than two into a chain of productions with right sides of two variables. Step 5: Make sure that the productions are in either these two forms: 1. A -> BC (body is two variables). 2. A -> a (body is a single terminal).
  • 2. So with the continuation of the previous example, • S0 → ASA | aB | a | SA |AS • S → ASA | aB | a | SA | AS • A → b | ASA | aB | a | SA | AS • B → b Introduce new variables. So for S0 → ASA & S → ASA , we replace SAwith a new variable, A1 therefore: • S0 → ASA | aB | a | SA |AS • S → ASA | aB | a | SA | AS • A → b | ASA | aB | a | SA | AS • B → b S0 → A A1 | aB | a | SA | AS S → A A1 | aB | a | SA |AS A → b | A A1 | aB | a | SA |AS A1 → SA B → b Recal l: 1. A -> BC (body is two variables).
  • 3. 1. A -> BC (body is two variables). 2. A -> a (body is a single terminal). • S0 → A A1 | aB | a | SA |AS • S → A A1 | aB | a | SA |AS • A → b | A A1 | aB | a | SA |AS • A1 → SA • B → b So we replace right hand sides with the wrong form by introducing a new variable just like the previous step. In this example, A2 • S0 → A A1 | aB | a | SA |AS • S → AA1 | aB | a | SA | AS • A → b | A A1 | aB | a | SA |AS • A1 → SA • B → b S0 → A A1 | A2 B| a | SA |AS S → A A1 | A2 B | a | SA |AS A → b | A A1 | A2 B | a | SA | AS A1 → SA A2 → a B → b
  • 4. Example #2: • S → aXbX • X → aY | bY | ε • Y → X | c Remove ε-productions. Then since the right hand of S contains X, X → ε S → aXbX Consider all cases, Case 1: S → a ε bX S → abX Case 2: S → aXb ε S → aXb Case 3: S → a ε b ε S → ab The variable X is nullable and therefore, also Y so, X → ε Y → X Y → ε X → aY | bY X → a | b add this new production to X
  • 5. Example #2 • From previous step we obtain, S → aXbX | abX | aXb | ab X → aY | bY | a | b Y → X | c Now we eliminate unit productions such as Y → X so, S → aXbX | abX | aXb | ab X → aY | bY | a | b Y → aY | bY | a | b | c Recall that: If A =>* B by a series of unit productions, and B - >  is a non-unit- production, then add production A -> .
  • 6. Example #2 S → aXbX | abX | aXb | ab X → aY | bY | a | b Y → aY | bY | a | b | c Now we replace longer productions with shorter ones by adding new variables. D → aX E → bX New grammar: S → DE | aE |Db| ab X → aY | bY | a | b Y → aY | bY | a | b | c D → aX E → bX
  • 7. Example #2 S → DE | aE |Db| ab X → aY | bY | a | b Y → aY | bY | a | b | c D → aX E → bX Then we correct the productions with wrong forms and introduce new variables F & G: F → a G → b
  • 8. Example #2 Final CNG in Chomsky Normal Form: S → DE | FE |DF| FG X → FY | GY | a | b Y → FY | GY | a | b | c D → FX E → GX F → a G → b