SlideShare une entreprise Scribd logo
1  sur  10
Convert PDA to CFG
• Given a PDA M = (Q, €, F, 6, qO, ZO, {}), we construct a CFG G = (V,
€, P, S)
– V = {[q, A, p] | q, p are in Q, A is in F+{S}}
– P is a set of productions constructed as follows:
• S c [qO, ZO, q] for all q in Q
• for each (p, s) in 6(q, a, A), where a is in € + {s}, we define
production:
[q, A, p] c a € + {s} and B are
in
• for each (p, B1B2…Bm) in 6(q, a, A), where a is
in
F [q, A, qm+1] -> a [q1, B1, q2] [q2, B2, q3] …[qm, Bm, qm+1]
for all q, q1, q2, …, qm+1 in Q
Deterministic PDA’s
• A PDA is deterministic if there is at most one move for any
input symbol, any top stack symbol, and at any state.
• A no move or move without advancing input string are
possible in a deterministic PDA.
• A move without advancing input string implies that no
other move exists.
• The pushdown automaton for wcwR is deterministic.
Deterministic PDA’s
• The set of languages accepted by deterministic PDD’s is
only a subset of the languages accepted by
nondeterministic PDA’s.
• A regular language is language accepted by a DPDA.
• Not all languages accepted by DPAD are regular.
• All languages accepted by DPAD have an unambiguous
CFG.
• Not all unambiguous languages are accepted by DPAD.
Grammatical Format
• Eliminate useless symbols
– derivable from S
– can derive a string of terminals
• Eliminate s-productions
– A -> s is an s-production.
• Eliminate unit productions
– A -> B is a unit production if both A and B are variables.
• For any CFG G and s is not in L(G), there exists
an equivalent context -free grammar with no
useless symbol, s-production, and unit production.
Eliminating Useless Symbols
• Given a CFG G = (V, T, P, S), withL(G ) is not empty, we
can effectively find an equivalent CFG G’ = (V’, T, P’, S)
such that for each A in V’ there is some w in T* for which
A=>*w.
• Given a CFG G = (V, T, P, S), we can effectively find an
equivalent CFG G’ = (V’, T’, P’, S) such that for each X in
(V’+T’) there exist a and þ in (V’+T’)* for which
S =>* aXþ.
Eliminatingssss-productions
• If s is not in L(G), we can eliminate all s-productions.
• A variable is nullable if A =>* s.
• For A -> X1X2…Xn, add the following productions A ->
Y1Y2…Yn
– If Xi is not nullable, then Yi = Xi.
– If Xi is nullable, then Yi = Xi or Yi = s.
– If Xi is nullable for (i = 1, …, n), don’t add A => s.
Eliminating Unit Productions
• If A=>*B and for all nonunit production B->X, add
– A->X
• Eliminate all unit productions.
Eliminating Useless Symbols and sss
and Unit Productions
1. Eliminate s-productions
2. Eliminate unit productions
3. Eliminate useless symbols.
Chomsky Normal Form (CNF)
• If aCFG has only productions of the form, it is called
Chomsky Normal Form (CNF)
– A -> BC, or
– A -> a
where A, B, and C are variables and a is a terminal.
• Any context-free language with e can be generated by a
context-free grammar in which all productions are in CNF.
Chomsky Normal Form (CNF)
• If aCFG has only productions of the form, it is called
Chomsky Normal Form (CNF)
– A -> BC, or
– A -> a
where A, B, and C are variables and a is a terminal.
• Any context-free language with e can be generated by a
context-free grammar in which all productions are in CNF.

Contenu connexe

Tendances

Naive Bayes Classifier | Naive Bayes Algorithm | Naive Bayes Classifier With ...
Naive Bayes Classifier | Naive Bayes Algorithm | Naive Bayes Classifier With ...Naive Bayes Classifier | Naive Bayes Algorithm | Naive Bayes Classifier With ...
Naive Bayes Classifier | Naive Bayes Algorithm | Naive Bayes Classifier With ...
Simplilearn
 

Tendances (20)

3.5 equivalence of pushdown automata and cfl
3.5 equivalence of pushdown automata and cfl3.5 equivalence of pushdown automata and cfl
3.5 equivalence of pushdown automata and cfl
 
Floyd warshall-algorithm
Floyd warshall-algorithmFloyd warshall-algorithm
Floyd warshall-algorithm
 
pushdown automata
pushdown automatapushdown automata
pushdown automata
 
Minimum spanning tree
Minimum spanning treeMinimum spanning tree
Minimum spanning tree
 
Finite automata
Finite automataFinite automata
Finite automata
 
Naive Bayes Classifier | Naive Bayes Algorithm | Naive Bayes Classifier With ...
Naive Bayes Classifier | Naive Bayes Algorithm | Naive Bayes Classifier With ...Naive Bayes Classifier | Naive Bayes Algorithm | Naive Bayes Classifier With ...
Naive Bayes Classifier | Naive Bayes Algorithm | Naive Bayes Classifier With ...
 
Decision properties of reular languages
Decision properties of reular languagesDecision properties of reular languages
Decision properties of reular languages
 
POST’s CORRESPONDENCE PROBLEM
POST’s CORRESPONDENCE PROBLEMPOST’s CORRESPONDENCE PROBLEM
POST’s CORRESPONDENCE PROBLEM
 
Regular expressions-Theory of computation
Regular expressions-Theory of computationRegular expressions-Theory of computation
Regular expressions-Theory of computation
 
Context free languages
Context free languagesContext free languages
Context free languages
 
Kruskal’s Algorithm
Kruskal’s AlgorithmKruskal’s Algorithm
Kruskal’s Algorithm
 
minimum spanning trees Algorithm
minimum spanning trees Algorithm minimum spanning trees Algorithm
minimum spanning trees Algorithm
 
Minimum spanning Tree
Minimum spanning TreeMinimum spanning Tree
Minimum spanning Tree
 
Turing Machine
Turing MachineTuring Machine
Turing Machine
 
1.7. eqivalence of nfa and dfa
1.7. eqivalence of nfa and dfa1.7. eqivalence of nfa and dfa
1.7. eqivalence of nfa and dfa
 
SINGLE-SOURCE SHORTEST PATHS
SINGLE-SOURCE SHORTEST PATHS SINGLE-SOURCE SHORTEST PATHS
SINGLE-SOURCE SHORTEST PATHS
 
Context free grammar
Context free grammar Context free grammar
Context free grammar
 
Finite Automata
Finite AutomataFinite Automata
Finite Automata
 
0 1 knapsack using branch and bound
0 1 knapsack using branch and bound0 1 knapsack using branch and bound
0 1 knapsack using branch and bound
 
Context free grammar
Context free grammarContext free grammar
Context free grammar
 

En vedette (14)

Cs419 lec7 cfg
Cs419 lec7   cfgCs419 lec7   cfg
Cs419 lec7 cfg
 
Finite automata intro
Finite automata introFinite automata intro
Finite automata intro
 
Kleene's theorem
Kleene's theoremKleene's theorem
Kleene's theorem
 
L3 cfg
L3 cfgL3 cfg
L3 cfg
 
Theory of Computation - Lectures 6 & 7
Theory of Computation - Lectures 6 & 7Theory of Computation - Lectures 6 & 7
Theory of Computation - Lectures 6 & 7
 
Payroll Management System
Payroll Management SystemPayroll Management System
Payroll Management System
 
Data Flow Diagram
Data Flow DiagramData Flow Diagram
Data Flow Diagram
 
Payroll Management System SRS
Payroll Management System SRSPayroll Management System SRS
Payroll Management System SRS
 
Dfd final
Dfd finalDfd final
Dfd final
 
Dfd and flowchart
Dfd and flowchartDfd and flowchart
Dfd and flowchart
 
Example of dfd with answer
Example of dfd with answerExample of dfd with answer
Example of dfd with answer
 
Data flow diagrams (2)
Data flow diagrams (2)Data flow diagrams (2)
Data flow diagrams (2)
 
Data flow diagram
Data flow diagram Data flow diagram
Data flow diagram
 
Dfd examples
Dfd examplesDfd examples
Dfd examples
 

Similaire à Pda to cfg h2

ContextFreeGrammars.pptx
ContextFreeGrammars.pptxContextFreeGrammars.pptx
ContextFreeGrammars.pptx
PEzhumalai
 
2. context free langauages
2. context free langauages2. context free langauages
2. context free langauages
danhumble
 
Unicode Cjk Compatible Variations
Unicode Cjk Compatible VariationsUnicode Cjk Compatible Variations
Unicode Cjk Compatible Variations
Joe Jiang
 

Similaire à Pda to cfg h2 (18)

Formal Languages and Automata Theory unit 3
Formal Languages and Automata Theory unit 3Formal Languages and Automata Theory unit 3
Formal Languages and Automata Theory unit 3
 
Presentation (2).pptx
Presentation (2).pptxPresentation (2).pptx
Presentation (2).pptx
 
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
 
Ch4a
Ch4aCh4a
Ch4a
 
Automata theory - CFG and normal forms
Automata theory - CFG and normal formsAutomata theory - CFG and normal forms
Automata theory - CFG and normal forms
 
ContextFreeGrammars.pptx
ContextFreeGrammars.pptxContextFreeGrammars.pptx
ContextFreeGrammars.pptx
 
ContextFreeGrammars (1).pptx
ContextFreeGrammars (1).pptxContextFreeGrammars (1).pptx
ContextFreeGrammars (1).pptx
 
Pushdown automata
Pushdown automataPushdown automata
Pushdown automata
 
Pushdown automata
Pushdown automataPushdown automata
Pushdown automata
 
PushdownAutomata.ppt
PushdownAutomata.pptPushdownAutomata.ppt
PushdownAutomata.ppt
 
Pda
PdaPda
Pda
 
Theory of Computation Regular Expressions, Minimisation & Pumping Lemma
Theory of Computation Regular Expressions, Minimisation & Pumping LemmaTheory of Computation Regular Expressions, Minimisation & Pumping Lemma
Theory of Computation Regular Expressions, Minimisation & Pumping Lemma
 
Lec1.pptx
Lec1.pptxLec1.pptx
Lec1.pptx
 
2. context free langauages
2. context free langauages2. context free langauages
2. context free langauages
 
Conversion of CFG to CNF.pptx
Conversion of CFG to CNF.pptxConversion of CFG to CNF.pptx
Conversion of CFG to CNF.pptx
 
Cs6503 theory of computation november december 2015 be cse anna university q...
Cs6503 theory of computation november december 2015  be cse anna university q...Cs6503 theory of computation november december 2015  be cse anna university q...
Cs6503 theory of computation november december 2015 be cse anna university q...
 
Unicode Cjk Compatible Variations
Unicode Cjk Compatible VariationsUnicode Cjk Compatible Variations
Unicode Cjk Compatible Variations
 
Ch03
Ch03Ch03
Ch03
 

Plus de Rajendran

Plus de Rajendran (20)

Element distinctness lower bounds
Element distinctness lower boundsElement distinctness lower bounds
Element distinctness lower bounds
 
Scheduling with Startup and Holding Costs
Scheduling with Startup and Holding CostsScheduling with Startup and Holding Costs
Scheduling with Startup and Holding Costs
 
Divide and conquer surfing lower bounds
Divide and conquer  surfing lower boundsDivide and conquer  surfing lower bounds
Divide and conquer surfing lower bounds
 
Red black tree
Red black treeRed black tree
Red black tree
 
Hash table
Hash tableHash table
Hash table
 
Medians and order statistics
Medians and order statisticsMedians and order statistics
Medians and order statistics
 
Proof master theorem
Proof master theoremProof master theorem
Proof master theorem
 
Recursion tree method
Recursion tree methodRecursion tree method
Recursion tree method
 
Recurrence theorem
Recurrence theoremRecurrence theorem
Recurrence theorem
 
Master method
Master method Master method
Master method
 
Master method theorem
Master method theoremMaster method theorem
Master method theorem
 
Hash tables
Hash tablesHash tables
Hash tables
 
Lower bound
Lower boundLower bound
Lower bound
 
Master method theorem
Master method theoremMaster method theorem
Master method theorem
 
Greedy algorithms
Greedy algorithmsGreedy algorithms
Greedy algorithms
 
Longest common subsequences in Algorithm Analysis
Longest common subsequences in Algorithm AnalysisLongest common subsequences in Algorithm Analysis
Longest common subsequences in Algorithm Analysis
 
Dynamic programming in Algorithm Analysis
Dynamic programming in Algorithm AnalysisDynamic programming in Algorithm Analysis
Dynamic programming in Algorithm Analysis
 
Average case Analysis of Quicksort
Average case Analysis of QuicksortAverage case Analysis of Quicksort
Average case Analysis of Quicksort
 
Np completeness
Np completenessNp completeness
Np completeness
 
computer languages
computer languagescomputer languages
computer languages
 

Dernier

The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 

Dernier (20)

Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptx
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 

Pda to cfg h2

  • 1. Convert PDA to CFG • Given a PDA M = (Q, €, F, 6, qO, ZO, {}), we construct a CFG G = (V, €, P, S) – V = {[q, A, p] | q, p are in Q, A is in F+{S}} – P is a set of productions constructed as follows: • S c [qO, ZO, q] for all q in Q • for each (p, s) in 6(q, a, A), where a is in € + {s}, we define production: [q, A, p] c a € + {s} and B are in • for each (p, B1B2…Bm) in 6(q, a, A), where a is in F [q, A, qm+1] -> a [q1, B1, q2] [q2, B2, q3] …[qm, Bm, qm+1] for all q, q1, q2, …, qm+1 in Q
  • 2. Deterministic PDA’s • A PDA is deterministic if there is at most one move for any input symbol, any top stack symbol, and at any state. • A no move or move without advancing input string are possible in a deterministic PDA. • A move without advancing input string implies that no other move exists. • The pushdown automaton for wcwR is deterministic.
  • 3. Deterministic PDA’s • The set of languages accepted by deterministic PDD’s is only a subset of the languages accepted by nondeterministic PDA’s. • A regular language is language accepted by a DPDA. • Not all languages accepted by DPAD are regular. • All languages accepted by DPAD have an unambiguous CFG. • Not all unambiguous languages are accepted by DPAD.
  • 4. Grammatical Format • Eliminate useless symbols – derivable from S – can derive a string of terminals • Eliminate s-productions – A -> s is an s-production. • Eliminate unit productions – A -> B is a unit production if both A and B are variables. • For any CFG G and s is not in L(G), there exists an equivalent context -free grammar with no useless symbol, s-production, and unit production.
  • 5. Eliminating Useless Symbols • Given a CFG G = (V, T, P, S), withL(G ) is not empty, we can effectively find an equivalent CFG G’ = (V’, T, P’, S) such that for each A in V’ there is some w in T* for which A=>*w. • Given a CFG G = (V, T, P, S), we can effectively find an equivalent CFG G’ = (V’, T’, P’, S) such that for each X in (V’+T’) there exist a and þ in (V’+T’)* for which S =>* aXþ.
  • 6. Eliminatingssss-productions • If s is not in L(G), we can eliminate all s-productions. • A variable is nullable if A =>* s. • For A -> X1X2…Xn, add the following productions A -> Y1Y2…Yn – If Xi is not nullable, then Yi = Xi. – If Xi is nullable, then Yi = Xi or Yi = s. – If Xi is nullable for (i = 1, …, n), don’t add A => s.
  • 7. Eliminating Unit Productions • If A=>*B and for all nonunit production B->X, add – A->X • Eliminate all unit productions.
  • 8. Eliminating Useless Symbols and sss and Unit Productions 1. Eliminate s-productions 2. Eliminate unit productions 3. Eliminate useless symbols.
  • 9. Chomsky Normal Form (CNF) • If aCFG has only productions of the form, it is called Chomsky Normal Form (CNF) – A -> BC, or – A -> a where A, B, and C are variables and a is a terminal. • Any context-free language with e can be generated by a context-free grammar in which all productions are in CNF.
  • 10. Chomsky Normal Form (CNF) • If aCFG has only productions of the form, it is called Chomsky Normal Form (CNF) – A -> BC, or – A -> a where A, B, and C are variables and a is a terminal. • Any context-free language with e can be generated by a context-free grammar in which all productions are in CNF.