Equivalence of Pushdown Automata and Context-Free Grammars (1) Theorem. Given a context-free grammar CG = ( ,NT,R,S), then there is a pushdown automaton.

Slides:



Advertisements
Similar presentations
Pushdown Automata Section 2.2 CSC 4170 Theory of Computation.
Advertisements

C O N T E X T - F R E E LANGUAGES ( use a grammar to describe a language) 1.
Pushdown Automata Chapter 12. Recognizing Context-Free Languages Two notions of recognition: (1) Say yes or no, just like with FSMs (2) Say yes or no,
FORMAL LANGUAGES, AUTOMATA, AND COMPUTABILITY
Pushdown Automata Part II: PDAs and CFG Chapter 12.
PDAs => CFGs Sipser 2.2 (pages ). Last time…
PDAs => CFGs Sipser 2.2 (pages ). Last time…
1 … NPDAs continued. 2 Pushing Strings Input symbol Pop symbol Push string.
CS 310 – Fall 2006 Pacific University CS310 Pushdown Automata Sections: 2.2 page 109 October 11, 2006.
Costas Busch - RPI1 NPDAs Accept Context-Free Languages.
Chap 2 Context-Free Languages. Context-free Grammars is not regular Context-free grammar : eg. G 1 : A  0A1substitution rules A  Bproduction rules B.
Courtesy Costas Busch - RPI1 NPDAs Accept Context-Free Languages.
1 Converting NPDAs to Context-Free Grammars. 2 For any NPDA we will construct a context-free grammar with.
1 Normal Forms for Context-free Grammars. 2 Chomsky Normal Form All productions have form: variable and terminal.
Fall 2004COMP 3351 NPDA’s Accept Context-Free Languages.
Foundations of (Theoretical) Computer Science Chapter 2 Lecture Notes (Section 2.2: Pushdown Automata) Prof. Karen Daniels, Fall 2009 with acknowledgement.
Fall 2006Costas Busch - RPI1 Pushdown Automata PDAs.
1 Normal Forms for Context-free Grammars. 2 Chomsky Normal Form All productions have form: variable and terminal.
CS5371 Theory of Computation Lecture 8: Automata Theory VI (PDA, PDA = CFG)
1 Context-Free Languages. 2 Regular Languages 3 Context-Free Languages.
January 15, 2014CS21 Lecture 61 CS21 Decidability and Tractability Lecture 6 January 16, 2015.
Fall 2006Costas Busch - RPI1 PDAs Accept Context-Free Languages.
1 Pushdown Automata PDAs. 2 Pushdown Automaton -- PDA Input String Stack States.
1 PDAs Accept Context-Free Languages. 2 Context-Free Languages (Grammars) Languages Accepted by PDAs Theorem:
CS 3240: Languages and Computation Pushdown Automata & CF Grammars NOTE: THESE ARE ONLY PARTIAL SLIDES RELATED TO WEEKS 9 AND 10. PLEASE REFER TO THE TEXTBOOK.
Problem of the DAY Create a regular context-free grammar that generates L= {w  {a,b}* : the number of a’s in w is not divisible by 3} Hint: start by designing.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 7 Mälardalen University 2010.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 8 Mälardalen University 2010.
CSCI 2670 Introduction to Theory of Computing September 20, 2005.
Pushdown Automata CS 130: Theory of Computation HMU textbook, Chap 6.
Pushdown Automata (PDAs)
Equivalence of Pushdown Automata and Context-Free Grammars (1) Theorem. Given a context-free grammar CG = ( ,NT,R,S), then there is a pushdown automaton.
Lecture Pushdown Automata. stack stack head finite control tape head tape.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 11 Midterm Exam 2 -Context-Free Languages Mälardalen University 2005.
1 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 6 Mälardalen University 2010.
Equivalence of Pushdown Automata and Context-Free Grammar Prof. Héctor Muñoz-Avila.
CS 208: Computing Theory Assoc. Prof. Dr. Brahim Hnich Faculty of Computer Sciences Izmir University of Economics.
1Computer Sciences Department. Book: INTRODUCTION TO THE THEORY OF COMPUTATION, SECOND EDITION, by: MICHAEL SIPSER Reference 3Computer Sciences Department.
Foundations of (Theoretical) Computer Science Chapter 2 Lecture Notes (Section 2.2: Pushdown Automata) Prof. Karen Daniels, Fall 2010 with acknowledgement.
11 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 7 School of Innovation, Design and Engineering Mälardalen University 2012.
Introduction Finite Automata accept all regular languages and only regular languages Even very simple languages are non regular (  = {a,b}): - {a n b.
1 Pushdown Automata There are context-free languages that are not regular. Finite automata cannot recognize all context-free languages.
Formal Languages, Automata and Models of Computation
Donghyun (David) Kim Department of Mathematics and Physics North Carolina Central University 1 Chapter 2 Context-Free Languages Some slides are in courtesy.
CSCI 4325 / 6339 Theory of Computation Zhixiang Chen Department of Computer Science University of Texas-Pan American.
1 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 8 Mälardalen University 2011.
Summary of Previous Class There are languages that are not decidable –(we have not proved this yet) Why not extend Turing machines just as we did with.
Pushdown Automata Chapter 12. Recognizing Context-Free Languages Two notions of recognition: (1) Say yes or no, just like with FSMs (2) Say yes or no,
1 Chapter Pushdown Automata. 2 Section 12.2 Pushdown Automata A pushdown automaton (PDA) is a finite automaton with a stack that has stack operations.
1 Section 12.2 Pushdown Automata A pushdown automaton (PDA) is a finite automaton with a stack that has stack operations pop, push, and nop. PDAs always.
Costas Busch - LSU1 PDAs Accept Context-Free Languages.
Theory of Computation Automata Theory Dr. Ayman Srour.
Lecture 11  2004 SDU Lecture7 Pushdown Automaton.
Recap: Nondeterministic Finite Automaton (NFA) A deterministic finite automaton (NFA) is a 5-tuple (Q, , ,s,F) where: Q is a finite set of elements called.
6. Pushdown Automata CIS Automata and Formal Languages – Pei Wang.
Formal Languages, Automata and Models of Computation
PDAs Accept Context-Free Languages
NPDAs Accept Context-Free Languages
Pushdown Automata PDAs
Pushdown Automata PDAs
Pushdown Automata PDAs
Pushdown Automata PDAs
Chapter 7 PUSHDOWN AUTOMATA.
NPDAs Accept Context-Free Languages
NFA vs DFA DFA: For every state q in S and every character  in , one and only one transition of the following form occurs:  q q’ NFA: For every state.
Chapter 2 Context-Free Language - 01
Principles of Computing – UFCFA3-30-1
… NPDAs continued.
Normal Forms for Context-free Grammars
Presentation transcript:

Equivalence of Pushdown Automata and Context-Free Grammars (1) Theorem. Given a context-free grammar CG = ( ,NT,R,S), then there is a pushdown automaton PA = (Q, , , ,s,F) such that L(CG) = L(PA) Construction: Q = {s,f}, F ={f},  = ,  =   NT Make a rule pushing S in the stack: ((s,e,e),(f,S)) For each rule C  w in R: ((f,e,C),(f,w)) For each terminal  in  ((f, ,  ),(f,e))

Sketch of the Proof S   1 T 1  1 where  1,  1 are in  * and T 1 is in (   NT)*   1  2 T 2  2  1 where  2 is in in  * and T 2 is in (   NT)* (taking the leftmost non terminal in T 1 ) … (always taking the leftmost non terminal)   1  2…  n  n …  1 (s,  1  2 …  n  n  1, e)  (f,  1  2 …  n  n  1, S)  (f,  1  2 …  n  n  1,  1 T 1  1 )  * (f,  2 …  n  n  1, T 1  1 )  (f,  2 …  n  n  1,  2 T 2  2  1 )  * (f,  3 …  n  n  2  1,T 2  2  1 )  * (f, e,e)

Equivalence of Pushdown Automata and Context-Free Grammars (2) Theorem. Given a pushdown automata PA = (Q, , , ,s,F) then, there exists a context-free grammar CG = ( ,NT,R,S) such that L(PA) = L(CG) Steps: 1. Obtain an equivalent pushdown automata accepting by empty stack 2. Obtain an equivalent simple pushdown automata (Q, , ,, ,s) 3. Use (Q, , ,, ,s) to obtain a context-free grammar CG = ( ,NT,R,S) such that L(SAE) = L(CG)

Simple Pushdown Automata A pushdown automata SA is simple if for each ((q, , ), (q’,  )) in  then   and SA accepts by empty stack Theorem. Given a pushdown automata accepting a language by empty stack PAE = (Q, , , ,s) there is a simple pushdown automata SPA = (Q’,  ’,  ’,,  ’,s’) accepting by empty stack such that L(SAE) = L(PAE) (that means no pop of empty word or more than one character) Assumptions:   For any word w we start with the configuration (s’,w, )

Proof Replace each transition ((q, ,w), (q’,  )), where w is a word with at least 2 characters, w =  1  2 …  n with: ((q,e,  1 ),(q 1,e)) ((q 1,e,  2 ),(q 2,e)) … ((q n-1,e,  n ),(q’,  )) where q 1,.., q n-1 are new states For every state q we add the transition: ((q, e, ), (q,e)) Replace each transformation ((q, ,e), (q’,  )) with a transformation ((q, , ), (q’,  )) Idea: always maintain on top of the stack

Last step: From a Simple Pushdown Automaton to a Context-Free Grammar Suppose that we have the transition: ((s,a,A),(q,B 1 B 2 …B n )) Problem with first attempt: 1. Doesn’t consider the states s or q First attempt: add the rule A  a B 1 B 2 …B n 2. Doesn’t consider the state where it is going to end after popping B 1 B 2 …B n Solution: Nonterminals will have the form [s,A,p], Where s and p are in Q and A is in  Roughly, [s,A,p] indicates that we can reach state p from state s after popping A from the stack

Special Case If ((s,a,A),(q,e)) is in  then add the rule: [s,A,q]  a

General Case If Nonterminals are having the form [s,A,p] and we have the transition: ((s,a,A),(q,B 1 B 2 …B n )) Our rule has the form: [s,A,?]  a[q, B 1,?] [?, B 2,?]… [?, B n,?] With which states should we fill the question marks? A s a B1B1 q p2p2 B2B2 p3p3 … BnBn p Problem: we don’t know the states p 2, …, p n-1, p

General Case (2) Solution: take all possible p 2, …, p n-1, p A s a B1B1 q P2P2 B2B2 P3P3 … BnBn p ((s,a,A),(q,B 1 B 2 …B n )) We add several rules: [s,A,p]  a[q, B 1, p 2 ] [p 2, B 2, p 3 ]… [p n-1, B n, p] One for each possible combination p 2, …, p n-1, p For each transition:

Resulting Context-Free Grammar Grammar: For every p  Q we add the rule: S  [s,, p] If ((s,a,A),(q,e)) is in  then add the rule: [s,A,q]  a If ((s,a,A),(q,B 1 B 2 …B n )) is in  then we add the rules: [s,A,p]  a[q, B 1, p 2 ] [p 2, B 2, p 3 ]… [p n-1, B n, p] one for each possible combination p 2, …, p n-1, p

Homework for Friday Consider the grammar from Example of the book (Page 74) –Use the grammar to generate the word: (v + (v/(v*v))) –Convert it into a pushdown automaton. –Show that the word (v + (v/(v*v))) is accepted by the pushdown automaton Consider the pushdown automaton from Example of the book (Page 83) –What is the language accepted by this pushdown automaton –Convert it into an equivalent pushdown automaton accepting by empty stack Consider the following pushdown automaton P accepting by empty stack: –What is the language accepted by it? –Convert P to a simple pushdown automaton. Note: you will need to figure out yourself how to make the transformation. The procedure in the book and the one in the slides has some errors. Assume that the initial configuration is: ((s,a,e),(s,a)) ((s,e,e),(f,e)) ((f,b,aa),(f,e))