SlideShare a Scribd company logo
1 of 15
GROUP MEMBERS
โ–ช Zain UL Abideen
(BSSE-FA17-048)
Theory
Of
Automata
โ–  Presentation
CFGTO CNF
CFG
CFG stands for context-free grammar.
It is a formal grammar which is used to
generate all possible patterns of
strings in a given formal language.
CFG
Context-free grammar G can be
defined by four tuples as
G = (V, T, P, S)
CFG
G is the grammar, which consists of a set of the production
rule. It is used to generate the string of a language.
T is the final set of a terminal symbol. It is denoted by
lower case letters.
V is the final set of a non-terminal symbol. It is denoted by
capital letters.
P is a set of production rules, which is used for replacing
non-terminals symbols(on the left side of the production) in
a string with other terminal or non-terminal symbols(on the
right side of the production).
S is the start symbol which is used to derive the string. We
can derive the string by repeatedly replacing a non-
terminal by the right-hand side of the production until all
non-terminal have been replaced by terminal symbols.
CNF
CNF stands for Chomsky normal form. A
CFG(context free grammar) is in CNF(Chomsky
normal form) if all production rules satisfy one of
the following conditions:
โ€ข Start symbol generating ฮต. For example, A โ†’ ฮต.
โ€ข A non-terminal generating two non-terminals.
For example, S โ†’ AB.
โ€ข A non-terminal generating a terminal. For
example, S โ†’ a.
CONVERTTING
CFGTO CNF
Steps for converting CFG into CNF
โ–  Step 1: Eliminate start symbol from the RHS. If the start symbolT is at the right-hand side
of any production, create a new production as: S1 โ†’ S
โ–  Where S1 is the new start symbol.
โ–  Step 2: In the grammar, remove the null, unit and useless productions.You can refer to
the Simplification of CFG.
โ–  Step 3: Eliminate terminals from the RHS of the production if they exist with other non-
terminals or terminals. For example, production S โ†’ aA can be decomposed as:
โ–  S โ†’ RA
โ–  R โ†’ a
โ–  Step 4: Eliminate RHS with more than two non-terminals. For example, S โ†’ ASB can be
decomposed as:
โ–  S โ†’ RS
โ–  R โ†’ AS
EXAMPLE
Convert the given CFG to CNF. Consider the given
grammar G1:
S โ†’ a | aA | B
A โ†’ aBB | ฮต
B โ†’ Aa | b
SOLUTION:
Step 1: We will create a new production S1 โ†’ S, as the start symbol S
appears on the RHS. The grammar will be:
S1 โ†’ S
S โ†’ a | aA | B
A โ†’ aBB | ฮต
B โ†’ Aa | b
Step 2: As grammar G1 contains A โ†’ ฮต null production, its removal from the grammar yields:
S1 โ†’ S
S โ†’ a | aA | B
A โ†’ aBB
B โ†’ Aa | b | a
Now, as grammar G1 contains Unit production S โ†’ B, its removal yield:
S1 โ†’ S
S โ†’ a | aA | Aa | b
A โ†’ aBB
B โ†’ Aa | b | a
Also remove the unit production S1 โ†’ S, its removal from the grammar yields:
S0 โ†’ a | aA | Aa | b
S โ†’ a | aA | Aa | b
A โ†’ aBB
B โ†’ Aa | b | a
Step 3: In the production rule S0 โ†’ aA | Aa, S โ†’ aA | Aa, A โ†’ aBB and B โ†’ Aa, terminal a
exists on RHS with non-terminals. So we will replace terminal a with X:
S0 โ†’ a | XA | AX | b
S โ†’ a | XA | AX | b
A โ†’ XBB
B โ†’ AX | b | a
X โ†’ a
Step 4: In the production rule A โ†’ XBB, RHS has more than two symbols, removing it from
grammar yield:
S0 โ†’ a | XA | AX | b
S โ†’ a | XA | AX | b
A โ†’ RB
B โ†’ AX | b | a
X โ†’ a
R โ†’ XB
Hence, for the given grammar, this is the required CNF.
END
OF
Presentation
THANK
YOU

More Related Content

What's hot

Nondeterministic Finite Automata
Nondeterministic Finite AutomataNondeterministic Finite Automata
Nondeterministic Finite Automata
Adel Al-Ofairi
ย 

What's hot (20)

push down automata
push down automatapush down automata
push down automata
ย 
Context free grammar
Context free grammar Context free grammar
Context free grammar
ย 
Finite Automata
Finite AutomataFinite Automata
Finite Automata
ย 
Push down automata
Push down automataPush down automata
Push down automata
ย 
Chomsky & Greibach Normal Forms
Chomsky & Greibach Normal FormsChomsky & Greibach Normal Forms
Chomsky & Greibach Normal Forms
ย 
NFA or Non deterministic finite automata
NFA or Non deterministic finite automataNFA or Non deterministic finite automata
NFA or Non deterministic finite automata
ย 
Automata theory
Automata theoryAutomata theory
Automata theory
ย 
CONTEXT FREE GRAMMAR
CONTEXT FREE GRAMMAR CONTEXT FREE GRAMMAR
CONTEXT FREE GRAMMAR
ย 
Lecture 3,4
Lecture 3,4Lecture 3,4
Lecture 3,4
ย 
context free language
context free languagecontext free language
context free language
ย 
Theory of Computation Grammar Concepts and Problems
Theory of Computation Grammar Concepts and ProblemsTheory of Computation Grammar Concepts and Problems
Theory of Computation Grammar Concepts and Problems
ย 
Regular expressions
Regular expressionsRegular expressions
Regular expressions
ย 
Cs2303 theory of computation all anna University question papers
Cs2303 theory of computation all anna University question papersCs2303 theory of computation all anna University question papers
Cs2303 theory of computation all anna University question papers
ย 
Context free grammars
Context free grammarsContext free grammars
Context free grammars
ย 
Nondeterministic Finite Automata
Nondeterministic Finite AutomataNondeterministic Finite Automata
Nondeterministic Finite Automata
ย 
Lecture 8
Lecture 8Lecture 8
Lecture 8
ย 
Regular Languages
Regular LanguagesRegular Languages
Regular Languages
ย 
Lecture 1,2
Lecture 1,2Lecture 1,2
Lecture 1,2
ย 
Chomsky classification of Language
Chomsky classification of LanguageChomsky classification of Language
Chomsky classification of Language
ย 
pushdown automata
pushdown automatapushdown automata
pushdown automata
ย 

Similar to CFG to CNF

Theory of competition topic simplification of cfg, normal form of FG.pptx
Theory of competition topic simplification of cfg, normal form of FG.pptxTheory of competition topic simplification of cfg, normal form of FG.pptx
Theory of competition topic simplification of cfg, normal form of FG.pptx
Jisock
ย 
8086-instruction-set-ppt
 8086-instruction-set-ppt 8086-instruction-set-ppt
8086-instruction-set-ppt
jemimajerome
ย 

Similar to CFG to CNF (15)

Theory of competition topic simplification of cfg, normal form of FG.pptx
Theory of competition topic simplification of cfg, normal form of FG.pptxTheory of competition topic simplification of cfg, normal form of FG.pptx
Theory of competition topic simplification of cfg, normal form of FG.pptx
ย 
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
ย 
Context Free Languages by S.Mandal-1.ppt
Context Free Languages by S.Mandal-1.pptContext Free Languages by S.Mandal-1.ppt
Context Free Languages by S.Mandal-1.ppt
ย 
NORMAL-FORMS.ppt
NORMAL-FORMS.pptNORMAL-FORMS.ppt
NORMAL-FORMS.ppt
ย 
NORMAL-FORMS.ppt
NORMAL-FORMS.pptNORMAL-FORMS.ppt
NORMAL-FORMS.ppt
ย 
TOA_WEEK 14.pptx
TOA_WEEK 14.pptxTOA_WEEK 14.pptx
TOA_WEEK 14.pptx
ย 
2.8 normal forms gnf & problems
2.8 normal forms   gnf & problems2.8 normal forms   gnf & problems
2.8 normal forms gnf & problems
ย 
Theory of Automata and formal languages Unit 3
Theory of Automata and formal languages Unit 3Theory of Automata and formal languages Unit 3
Theory of Automata and formal languages Unit 3
ย 
inbound6417574391896884649.pptx
inbound6417574391896884649.pptxinbound6417574391896884649.pptx
inbound6417574391896884649.pptx
ย 
Chomsky_GreibachNF.ppt
Chomsky_GreibachNF.pptChomsky_GreibachNF.ppt
Chomsky_GreibachNF.ppt
ย 
Chomsky_Greibach-Hector-Chavez.ppt
Chomsky_Greibach-Hector-Chavez.pptChomsky_Greibach-Hector-Chavez.ppt
Chomsky_Greibach-Hector-Chavez.ppt
ย 
Lecture4 lexical analysis2
Lecture4 lexical analysis2Lecture4 lexical analysis2
Lecture4 lexical analysis2
ย 
8086-instruction-set-ppt
 8086-instruction-set-ppt 8086-instruction-set-ppt
8086-instruction-set-ppt
ย 
Presentation (2).pptx
Presentation (2).pptxPresentation (2).pptx
Presentation (2).pptx
ย 
Assembly Complete 8086 Instruction Set
Assembly Complete 8086 Instruction SetAssembly Complete 8086 Instruction Set
Assembly Complete 8086 Instruction Set
ย 

Recently uploaded

+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
ย 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
mohitmore19
ย 
CHEAP Call Girls in Pushp Vihar (-DELHI )๐Ÿ” 9953056974๐Ÿ”(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )๐Ÿ” 9953056974๐Ÿ”(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )๐Ÿ” 9953056974๐Ÿ”(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )๐Ÿ” 9953056974๐Ÿ”(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
ย 
CALL ON โžฅ8923113531 ๐Ÿ”Call Girls Badshah Nagar Lucknow best Female service
CALL ON โžฅ8923113531 ๐Ÿ”Call Girls Badshah Nagar Lucknow best Female serviceCALL ON โžฅ8923113531 ๐Ÿ”Call Girls Badshah Nagar Lucknow best Female service
CALL ON โžฅ8923113531 ๐Ÿ”Call Girls Badshah Nagar Lucknow best Female service
anilsa9823
ย 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
bodapatigopi8531
ย 

Recently uploaded (20)

Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
ย 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
ย 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
ย 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
ย 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
ย 
call girls in Vaishali (Ghaziabad) ๐Ÿ” >เผ’8448380779 ๐Ÿ” genuine Escort Service ๐Ÿ”โœ”๏ธโœ”๏ธ
call girls in Vaishali (Ghaziabad) ๐Ÿ” >เผ’8448380779 ๐Ÿ” genuine Escort Service ๐Ÿ”โœ”๏ธโœ”๏ธcall girls in Vaishali (Ghaziabad) ๐Ÿ” >เผ’8448380779 ๐Ÿ” genuine Escort Service ๐Ÿ”โœ”๏ธโœ”๏ธ
call girls in Vaishali (Ghaziabad) ๐Ÿ” >เผ’8448380779 ๐Ÿ” genuine Escort Service ๐Ÿ”โœ”๏ธโœ”๏ธ
ย 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
ย 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
ย 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
ย 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
ย 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
ย 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
ย 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
ย 
CHEAP Call Girls in Pushp Vihar (-DELHI )๐Ÿ” 9953056974๐Ÿ”(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )๐Ÿ” 9953056974๐Ÿ”(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )๐Ÿ” 9953056974๐Ÿ”(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )๐Ÿ” 9953056974๐Ÿ”(=)/CALL GIRLS SERVICE
ย 
CALL ON โžฅ8923113531 ๐Ÿ”Call Girls Badshah Nagar Lucknow best Female service
CALL ON โžฅ8923113531 ๐Ÿ”Call Girls Badshah Nagar Lucknow best Female serviceCALL ON โžฅ8923113531 ๐Ÿ”Call Girls Badshah Nagar Lucknow best Female service
CALL ON โžฅ8923113531 ๐Ÿ”Call Girls Badshah Nagar Lucknow best Female service
ย 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
ย 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
ย 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
ย 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
ย 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlanโ€™s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlanโ€™s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlanโ€™s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlanโ€™s ...
ย 

CFG to CNF

  • 1.
  • 2. GROUP MEMBERS โ–ช Zain UL Abideen (BSSE-FA17-048)
  • 5. CFG CFG stands for context-free grammar. It is a formal grammar which is used to generate all possible patterns of strings in a given formal language.
  • 6. CFG Context-free grammar G can be defined by four tuples as G = (V, T, P, S)
  • 7. CFG G is the grammar, which consists of a set of the production rule. It is used to generate the string of a language. T is the final set of a terminal symbol. It is denoted by lower case letters. V is the final set of a non-terminal symbol. It is denoted by capital letters. P is a set of production rules, which is used for replacing non-terminals symbols(on the left side of the production) in a string with other terminal or non-terminal symbols(on the right side of the production). S is the start symbol which is used to derive the string. We can derive the string by repeatedly replacing a non- terminal by the right-hand side of the production until all non-terminal have been replaced by terminal symbols.
  • 8. CNF CNF stands for Chomsky normal form. A CFG(context free grammar) is in CNF(Chomsky normal form) if all production rules satisfy one of the following conditions: โ€ข Start symbol generating ฮต. For example, A โ†’ ฮต. โ€ข A non-terminal generating two non-terminals. For example, S โ†’ AB. โ€ข A non-terminal generating a terminal. For example, S โ†’ a.
  • 10. Steps for converting CFG into CNF โ–  Step 1: Eliminate start symbol from the RHS. If the start symbolT is at the right-hand side of any production, create a new production as: S1 โ†’ S โ–  Where S1 is the new start symbol. โ–  Step 2: In the grammar, remove the null, unit and useless productions.You can refer to the Simplification of CFG. โ–  Step 3: Eliminate terminals from the RHS of the production if they exist with other non- terminals or terminals. For example, production S โ†’ aA can be decomposed as: โ–  S โ†’ RA โ–  R โ†’ a โ–  Step 4: Eliminate RHS with more than two non-terminals. For example, S โ†’ ASB can be decomposed as: โ–  S โ†’ RS โ–  R โ†’ AS
  • 11. EXAMPLE Convert the given CFG to CNF. Consider the given grammar G1: S โ†’ a | aA | B A โ†’ aBB | ฮต B โ†’ Aa | b
  • 12. SOLUTION: Step 1: We will create a new production S1 โ†’ S, as the start symbol S appears on the RHS. The grammar will be: S1 โ†’ S S โ†’ a | aA | B A โ†’ aBB | ฮต B โ†’ Aa | b
  • 13. Step 2: As grammar G1 contains A โ†’ ฮต null production, its removal from the grammar yields: S1 โ†’ S S โ†’ a | aA | B A โ†’ aBB B โ†’ Aa | b | a Now, as grammar G1 contains Unit production S โ†’ B, its removal yield: S1 โ†’ S S โ†’ a | aA | Aa | b A โ†’ aBB B โ†’ Aa | b | a Also remove the unit production S1 โ†’ S, its removal from the grammar yields: S0 โ†’ a | aA | Aa | b S โ†’ a | aA | Aa | b A โ†’ aBB B โ†’ Aa | b | a
  • 14. Step 3: In the production rule S0 โ†’ aA | Aa, S โ†’ aA | Aa, A โ†’ aBB and B โ†’ Aa, terminal a exists on RHS with non-terminals. So we will replace terminal a with X: S0 โ†’ a | XA | AX | b S โ†’ a | XA | AX | b A โ†’ XBB B โ†’ AX | b | a X โ†’ a Step 4: In the production rule A โ†’ XBB, RHS has more than two symbols, removing it from grammar yield: S0 โ†’ a | XA | AX | b S โ†’ a | XA | AX | b A โ†’ RB B โ†’ AX | b | a X โ†’ a R โ†’ XB Hence, for the given grammar, this is the required CNF.