SlideShare ist ein Scribd-Unternehmen logo
1 von 8
CONVERSION FROM CFG TO PDA
Adithya M
TOC
Rollno:13
CONTEXT FREE GRAMMER (CFG)
• Context free grammar is a formal grammar which is used to
generate all possible strings in a given formal language.
• Context-free grammar G can be defined by four tuples as:
• G = (V, T, P, S)
• Where,
• G is the grammar, T is the final set of a terminal symbol, V is
the final set of a non-terminal symbol, P is a set of production
rules, S is the start symbol which is used to derive the string.
PUSHDOWN AUTOMATA (PDA)
• Pushdown automata is a way to implement a CFG in the same
way we design DFA for a regular grammar.
• A DFA can remember a finite amount of information, but a PDA
can remember an infinite amount of information.
FORMAL DEFINITION OF PDA:
• The PDA can be defined as a collection of 7 components:
• Q: the finite set of states
• ∑: the input set
• Γ: a stack symbol which can be pushed and popped from
the stack
• q0: the initial state
• Z: a start symbol which is in Γ.
• F: a set of final states
• δ: mapping function which is used for moving from
current state to next state.
CONVERSION OF CFG TO PDA
• Step 1: Convert the given productions of CFG into GNF.
• Step 2: The PDA will only have one state {q}.
• Step 3: The initial symbol of CFG will be the initial symbol in
the PDA.
• Step 4: For non-terminal symbol, add the following
rule:δ(q, ε, A) = (q, α)
• Where the production rule is A → α
• Step 5: For each terminal symbols, add the following rule:
• δ(q, a, a) = (q, ε) for every terminal symbol
• Example:
• Convert the following grammar to a PDA that accepts the same
language.
• S → 0S1 | A
• A → 1A0 | S | ε
• Solution:
• The CFG can be first simplified by eliminating unit productions:
• S → 0S1 | 1S0 | ε
• Now we will convert this CFG to GNF:
• S → 0SX | 1SY | ε
• X → 1
• Y → 0
• The pda can be
• R1: δ(q, ε, S) = {(q, 0SX) | (q, 1SY) | (q, ε)}
• R2: δ(q, ε, X) = {(q, 1)}
• R3: δ(q, ε, Y) = {(q, 0)}
• R4: δ(q, 0, 0) = {(q, ε)}
• R5: δ(q, 1, 1) = {(q, ε)}
THANK YOU

Weitere ähnliche Inhalte

Ähnlich wie Presentation (2).pptx

@vtucode.in-module-1-21CS51-5th-semester (1).pdf
@vtucode.in-module-1-21CS51-5th-semester (1).pdf@vtucode.in-module-1-21CS51-5th-semester (1).pdf
@vtucode.in-module-1-21CS51-5th-semester (1).pdf
FariyaTasneem1
 
cmp104 lec 8
cmp104 lec 8cmp104 lec 8
cmp104 lec 8
kapil078
 
Part III: Assembly Language
Part III: Assembly LanguagePart III: Assembly Language
Part III: Assembly Language
Ahmed M. Abed
 

Ähnlich wie Presentation (2).pptx (20)

Unit iv
Unit ivUnit iv
Unit iv
 
Automata theory - Push Down Automata (PDA)
Automata theory - Push Down Automata (PDA)Automata theory - Push Down Automata (PDA)
Automata theory - Push Down Automata (PDA)
 
Pda to cfg h2
Pda to cfg h2Pda to cfg h2
Pda to cfg h2
 
Cse115 lecture04introtoc programming
Cse115 lecture04introtoc programmingCse115 lecture04introtoc programming
Cse115 lecture04introtoc programming
 
@vtucode.in-module-1-21CS51-5th-semester (1).pdf
@vtucode.in-module-1-21CS51-5th-semester (1).pdf@vtucode.in-module-1-21CS51-5th-semester (1).pdf
@vtucode.in-module-1-21CS51-5th-semester (1).pdf
 
TOC_Solutions-Adi.pdf
TOC_Solutions-Adi.pdfTOC_Solutions-Adi.pdf
TOC_Solutions-Adi.pdf
 
TOC Solutions-Adi.pdf
TOC Solutions-Adi.pdfTOC Solutions-Adi.pdf
TOC Solutions-Adi.pdf
 
TOC_Solutions-Adi.pdf
TOC_Solutions-Adi.pdfTOC_Solutions-Adi.pdf
TOC_Solutions-Adi.pdf
 
Lec04
Lec04Lec04
Lec04
 
Lec04
Lec04Lec04
Lec04
 
Theory of automata
Theory of automataTheory of automata
Theory of automata
 
push down automata
push down automatapush down automata
push down automata
 
Microprocessor Part 3
Microprocessor    Part  3Microprocessor    Part  3
Microprocessor Part 3
 
a7f0bc7785844884c4de624f61ce5978_MIT18_404f20_lec4.pptx
a7f0bc7785844884c4de624f61ce5978_MIT18_404f20_lec4.pptxa7f0bc7785844884c4de624f61ce5978_MIT18_404f20_lec4.pptx
a7f0bc7785844884c4de624f61ce5978_MIT18_404f20_lec4.pptx
 
cmp104 lec 8
cmp104 lec 8cmp104 lec 8
cmp104 lec 8
 
Part III: Assembly Language
Part III: Assembly LanguagePart III: Assembly Language
Part III: Assembly Language
 
Rseminarp
RseminarpRseminarp
Rseminarp
 
Slicing of Object-Oriented Programs
Slicing of Object-Oriented ProgramsSlicing of Object-Oriented Programs
Slicing of Object-Oriented Programs
 
Introduction_to_PDA.pptx
Introduction_to_PDA.pptxIntroduction_to_PDA.pptx
Introduction_to_PDA.pptx
 
LCD_Example.pptx
LCD_Example.pptxLCD_Example.pptx
LCD_Example.pptx
 

Kürzlich hochgeladen

The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
heathfieldcps1
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 

Kürzlich hochgeladen (20)

Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 

Presentation (2).pptx

  • 1. CONVERSION FROM CFG TO PDA Adithya M TOC Rollno:13
  • 2. CONTEXT FREE GRAMMER (CFG) • Context free grammar is a formal grammar which is used to generate all possible strings in a given formal language. • Context-free grammar G can be defined by four tuples as: • G = (V, T, P, S) • Where, • G is the grammar, T is the final set of a terminal symbol, V is the final set of a non-terminal symbol, P is a set of production rules, S is the start symbol which is used to derive the string.
  • 3. PUSHDOWN AUTOMATA (PDA) • Pushdown automata is a way to implement a CFG in the same way we design DFA for a regular grammar. • A DFA can remember a finite amount of information, but a PDA can remember an infinite amount of information.
  • 4. FORMAL DEFINITION OF PDA: • The PDA can be defined as a collection of 7 components: • Q: the finite set of states • ∑: the input set • Γ: a stack symbol which can be pushed and popped from the stack • q0: the initial state • Z: a start symbol which is in Γ. • F: a set of final states • δ: mapping function which is used for moving from current state to next state.
  • 5. CONVERSION OF CFG TO PDA • Step 1: Convert the given productions of CFG into GNF. • Step 2: The PDA will only have one state {q}. • Step 3: The initial symbol of CFG will be the initial symbol in the PDA. • Step 4: For non-terminal symbol, add the following rule:δ(q, ε, A) = (q, α) • Where the production rule is A → α • Step 5: For each terminal symbols, add the following rule: • δ(q, a, a) = (q, ε) for every terminal symbol
  • 6. • Example: • Convert the following grammar to a PDA that accepts the same language. • S → 0S1 | A • A → 1A0 | S | ε • Solution: • The CFG can be first simplified by eliminating unit productions: • S → 0S1 | 1S0 | ε • Now we will convert this CFG to GNF: • S → 0SX | 1SY | ε • X → 1 • Y → 0
  • 7. • The pda can be • R1: δ(q, ε, S) = {(q, 0SX) | (q, 1SY) | (q, ε)} • R2: δ(q, ε, X) = {(q, 1)} • R3: δ(q, ε, Y) = {(q, 0)} • R4: δ(q, 0, 0) = {(q, ε)} • R5: δ(q, 1, 1) = {(q, ε)}