SlideShare uma empresa Scribd logo
1 de 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

Mais conteúdo relacionado

Semelhante a 5-step process to convert context-free grammar to Chomsky Normal Form

Simplifiaction of grammar
Simplifiaction of grammarSimplifiaction of grammar
Simplifiaction of grammarlavishka_anuj
 
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.pptxShubhamKumar483645
 
Chomsky & Greibach Normal Forms
Chomsky & Greibach Normal FormsChomsky & Greibach Normal Forms
Chomsky & Greibach Normal FormsRajendran
 
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 ComputationNikhil Pandit
 
Geometry working with line segments
Geometry working with  line segmentsGeometry working with  line segments
Geometry working with line segmentsrfarinas
 

Semelhante a 5-step process to convert context-free grammar to Chomsky Normal Form (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
 

Mais de SadagopanS

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

Mais de 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
 

Último

Integumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.pptIntegumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.pptshraddhaparab530
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...Nguyen Thanh Tu Collection
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYKayeClaireEstoconing
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17Celine George
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)lakshayb543
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONHumphrey A Beña
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parentsnavabharathschool99
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfErwinPantujan2
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management SystemChristalin Nelson
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Seán Kennedy
 
Activity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translationActivity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translationRosabel UA
 
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptxAUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptxiammrhaywood
 

Último (20)

Integumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.pptIntegumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.ppt
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parents
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
 
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptxLEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management System
 
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptxYOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...
 
Activity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translationActivity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translation
 
Raw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptxRaw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptx
 
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptxAUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
 

5-step process to convert context-free grammar to Chomsky Normal Form

  • 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