Push Down Automata Push Down Automata (PDAs) are L-NFAs with stack memory. Transitions are labeled by an input symbol together with a pair of the form.

Slides:



Advertisements
Similar presentations
Chapter 5 Pushdown Automata
Advertisements

1 Pushdown Automata (PDA) Informally: –A PDA is an NFA-ε with a stack. –Transitions are modified to accommodate stack operations. Questions: –What is a.
C O N T E X T - F R E E LANGUAGES ( use a grammar to describe a language) 1.
Closure Properties of CFL's
Pushdown Automata (PDA)
Introduction to Computability Theory
1 Introduction to Computability Theory Lecture7: PushDown Automata (Part 1) Prof. Amos Israeli.
Costas Busch - RPI1 Pushdown Automata PDAs. Costas Busch - RPI2 Pushdown Automaton -- PDA Input String Stack States.
1 … NPDAs continued. 2 Pushing Strings Input symbol Pop symbol Push string.
Costas Busch - RPI1 NPDAs Accept Context-Free Languages.
Courtesy Costas Busch - RPI1 NPDAs Accept Context-Free Languages.
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 2004COMP 3351 Pushdown Automata PDAs. Fall 2004COMP 3352 Pushdown Automaton -- PDA Input String Stack States.
CS5371 Theory of Computation Lecture 8: Automata Theory VI (PDA, PDA = CFG)
Fall 2006Costas Busch - RPI1 PDAs Accept Context-Free Languages.
1 Pushdown Automata PDAs. 2 Pushdown Automaton -- PDA Input String Stack States.
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.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 8 Mälardalen University 2010.
CSCI 2670 Introduction to Theory of Computing September 21, 2005.
Pushdown Automata.
Pushdown Automata CS 130: Theory of Computation HMU textbook, Chap 6.
Pushdown Automata (PDAs)
Definition Moves of the PDA Languages of the PDA Deterministic PDA’s Pushdown Automata 11.
1 Pushdown Automata Definition: relation to  -NFA Moves of the PDA Languages of the PDA Deterministic PDA’s Quiz Wednesday on CFGs lecture #3.
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.
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.
Formal Languages, Automata and Models of Computation
1 Pushdown Automata Definition Moves of the PDA Languages of the PDA Deterministic PDA’s.
Lecture 14 Push Down Automata (PDA) Topics:  Definition  Moves of the PDA  Languages of the PDA  Deterministic PDA’s June 18, 2015 CSCE 355 Foundations.
Pushdown Automata Hopcroft, Motawi, Ullman, Chap 6.
Grammar Set of variables Set of terminal symbols Start variable Set of Production rules.
1 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 8 Mälardalen University 2011.
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.
Costas Busch - LSU1 PDAs Accept Context-Free Languages.
Lecture 11  2004 SDU Lecture7 Pushdown Automaton.
6. Pushdown Automata CIS Automata and Formal Languages – Pei Wang.
Formal Languages, Automata and Models of Computation
Pushdown Automata.
Lecture 14 Push Down Automata (PDA)
PDAs Accept Context-Free Languages
CSE 105 theory of computation
NPDAs Accept Context-Free Languages
Pushdown Automata (PDA). Part 2
CIS Automata and Formal Languages – Pei Wang
Pushdown Automata PDAs
Pushdown Automata PDAs
Pushdown Automata PDAs
PDAs Accept Context-Free Languages
Pushdown Automata PDAs
Chapter 7 PUSHDOWN AUTOMATA.
AUTOMATA THEORY VI.
Pushdown Automata (PDA)
NPDAs Accept Context-Free Languages
Pushdown Automata Reading: Chapter 6.
Last Lecture We began to show CFL = PDA
فصل دوم Context-Free Languages
Pushdown automata a_introduction.htm.
Definition Moves of the PDA Languages of the PDA Deterministic PDA’s
Chapter 2 Context-Free Language - 01
CSE 105 theory of computation
… NPDAs continued.
Pushdown automata The Chinese University of Hong Kong Fall 2011
CSE 105 theory of computation
Normal Forms for Context-free Grammars
CSE 105 theory of computation
Presentation transcript:

Push Down Automata Push Down Automata (PDAs) are L-NFAs with stack memory. Transitions are labeled by an input symbol together with a pair of the form X/a. The transition is possible only if the top of the stack contains the symbol X After the transition, the stack is changed by replacing the top symbol X with the string of symbols a. (Pop X, then push symbols of a.)

Example PDAs can accept languages that are not regular. The following one accepts: L={0i1j | 0 £ i £ j}   s q 0, X/XX 0, Z0/XZ0 p 1, X/e L, Z0/Z0 1, Z0/Z0

Definition A PDA is a 7-tuple P=(Q,S,G,d,q0,Z0,F) where Q, S, q0, F are as in NFAs, and G is the stack alphabet. Z0 Î G is the start symbol; it is assumed that initially the stack contains only the symbol Z0. d: Q ×(SÈ{L}) × G ¾® P(Q × G*) is the transition function: given a state, an input symbol (or L), and a stack symbol, it gives us a finite number of pairs (q,a), where q is the next state and a is the string of stack symbols that will replace X on top of the stack.

d(q,a,Y)=Æ for all other possibilities. In our example, the transition from s to s labeled (0,Z0/XZ0) corresponds to the fact (s,XZ0)Î d(s,0,Z0). A complete description of the transition function in this example is given by d(s,0,Z0) = {(s,XZ0)} d(s,0,X) = {(s,XX)} d(s,L,Z0) = {(q,Z0)} d(s,1,X) = {(p,e)} d(p,1,X) = {(p,e)} d(p,L,Z0) = {(q,Z0)} d(q,1,Z0) = {(q,Z0)} and d(q,a,Y)=Æ for all other possibilities. s q 0, X/XX 0, Z0/XZ0 p 1, X/e L, Z0/Z0 1, Z0/Z0

Instantaneous Descriptions and Moves of PDAs  IDs (also called configurations) describe the execution of a PDA at each instant. An ID is a triple (q,w,a), with this intended meaning: q is the current state w is the remaining part of the input a is the current content of the stack, with top of the stack on the left.

The relation |- describes possible moves from one ID to another during execution of a PDA. If d(q,a,X) contains (p,a), then (q,aw,Xb) |- (p,w,ab) is true for every w and b.   The relation |-* is the reflexive-transitive closure of |- We have (q,w,a) |-* (q',w',a') when (q,w,a) leads through a sequence (possibly empty) of moves to (q',w',a')

(s,011,z) |- (s,11,xz) |- (P,1,z)|-(q,1,z) |- (q,””,Z) 0, X/XX 0, Z0/XZ0 p 1, X/e L, Z0/Z0 1, Z0/Z0 (s,011,z) |- (s,11,xz) |- (P,1,z)|-(q,1,z) |- (q,””,Z) (s,011,z) |- (q,011,Z)

Properties of |- Property 1. Property 2. If (q,x,a) |-* (p,y,b) Then (q,xw,ag) |-* (p,yw,bg) If you only need some prefix of the input (x) and stack (a) to make a series of transitions, you can make the same transitions for any longer input and stack. Property 2. If (q,xw,a) |-* (p,yw,b) Then (q,x,a) |-* (p,y,b) It is ok to remove unused input, since a PDA cannot add input back on once consumed.

The Language of a PDA A PDA as above accepts the string w iff (q0,w,Z0) |-* (p,L,a) is true for some final state p and some a. (We don't care what's on the stack at the end of input.)   The language L(P) of the PDA P is the set of all strings accepted by P.

Here is the chain of IDs showing that the string 001111 is accepted by our example PDA: (s,001111,Z0) |- (s,01111,XZ0) |- (s, 1111,XXZ0) |- (p,111,XZ0) |- (p,11,Z0) |- (q,11,Z0) |- (q,1,Z0) |- (q,e,Z0) s q 0, X/XX 0, Z0/XZ0 p 1, X/e L, Z0/Z0 1, Z0/Z0

The language of the following PDA is {0i1j | 0 < i £ j}*. How can we prove this? 1, X,e 1, Z0/Z0 0, X/XX 0, Z0/XZ0 1, X/e s p q L, Z0/Z0

Example A PDA for the language of balanced parentheses: q p L, Z0/Z0 (, Z0/XZ0 (, X/XX L, Z0/Z0 p q ), X/e

Acceptance by Empty Stack Define N(P) to be the set of all strings w such that (q0,w,Z0) |-* (q,L,e) for some state q. These are the strings P accepts by empty stack. Note that the set of final states plays no role in this definition.   Theorem. A language is L(P1) for some PDA P1 if and only if it is N(P2) for some PDA P2.

Proof 1 Pf p0 q0 P2 1. From empty stack to final state.   Given P2 that accepts by empty stack, get P1 by adding a new start state and a new final state as in the picture below. We also add a new stack symbol X0 and make it the start symbol for P1's stack. p0 Pf L, X0/Z0X0 q0 L, X0/e (add this transition from all states of P2 to new state Pf) P2

Proof 2 2. From final state to empty stack.   Given P1, we get P2 again by adding a new start state, final state and start stack symbol. New transitions are seen in the picture. P2 L, X0/Z0X0 p0 q0 L, G/e L, G/e P L, G/e

Equivalence of CFGs and PDAs The equivalence is expressed by two theorems. Theorem 1. Every context-free language is accepted by some PDA. Theorem 2. For every PDA M, the language L(M) is context-free. We will describe the constructions, see some examples and proof ideas.

Given a CFG G=(V,T,P,S), we define a PDA M=({q},T, T È V, d,q,S), with d given by If A Î V, then d(q,e,A) = { (q,a) | A ® a is in P} If a Î T, then d(q,a,a) = { (q,e) } Note that the stack symbols of the new PDA contain all the terminal and non-terminals of the CFG There is only 1 state in the new PDA, all the rest of the info is encoded in the stack. Most transitions are on L, one for each production The other transitions come one for each terminal. The automaton simulates leftmost derivations of G, accepting by empty stack. For every intermediate sentential form uAa in the leftmost derivation of w (note first that w = uv for some v), M will have Aa on its stack after reading u. At the end (case u = w) the stack will be empty.

Example For our old grammar: S ® SS | (S) | L the automaton M will have five transitions, all from q to q: d(q, L,S) = (q, SS) S ® SS d(q, L,S) = (q, (S) ) S ® (S) d(q, L,S) = (q, L ) S ® L d(q, (, ( ) = (q,L) d(q, ), ) ) = (q,L) Most transitions are on L, one for each production The other transitions come one for each terminal.

Compare Now compare the leftmost derivation S Þ SS Þ (S)S Þ ((S))S Þ (())S Þ (())(S) Þ (())() with the M's execution on the same string given as input: (q, "(())()" ,S ) |- [1] (q, "(())()" ,SS ) |- [2] (q, "(())()" ,(S)S ) |- [4] (q, "())()" ,S)S ) |- [4] (q, "())()" ,(S))S ) |- [4] (q, "))()" ,S))S ) |- [3] (q, "))()" ,))S ) |- [5] (q, ")()" ,)S ) |- [5] (q, "()" ,S ) |- [2] (q, "()" ,(S) ) |- [4] (q, ")" ,S) ) |- [3] (q, ")" ,) ) |- [5] (q, e ,e ) d(q, L,S) = (q, SS) S ® SS d(q, L,S) = (q, (S) ) S ® (S) d(q, L,S) = (q, e ) S ® L d(q, (, ( ) = (q,L) d(q, ), ) ) = (q,L)

Next time We’ll prove the construction correct, Look at the inverse construction. PDA®CFL