Chapter 5 Pushdown Automata

Slides:



Advertisements
Similar presentations
Theory of Computation CS3102 – Spring 2014 A tale of computers, math, problem solving, life, love and tragic death Nathan Brunelle Department of Computer.
Advertisements

Pushdown Automata Section 2.2 CSC 4170 Theory of Computation.
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.
Pushdown Automata CPSC 388 Ellen Walker Hiram College.
1 Introduction to Computability Theory Lecture12: Decidable Languages Prof. Amos Israeli.
Introduction to Computability Theory
CFG => PDA Sipser 2 (pages ).
1 Introduction to Computability Theory Lecture7: PushDown Automata (Part 1) Prof. Amos Israeli.
CFG => PDA Sipser 2 (pages ). CS 311 Fall Formally… A pushdown automaton is a sextuple M = (Q, Σ, Γ, δ, q 0, F), where – Q is a finite set.
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.
Courtesy Costas Busch - RPI1 NPDAs Accept Context-Free Languages.
CS 310 – Fall 2006 Pacific University CS310 Pushdown Automata Sections: 2.2 page 109 October 9, 2006.
Fall 2006Costas Busch - RPI1 Pushdown Automata PDAs.
CS5371 Theory of Computation Lecture 8: Automata Theory VI (PDA, PDA = CFG)
Prof. Busch - LSU1 Pushdown Automata PDAs. Prof. Busch - LSU2 Pushdown Automaton -- PDA Input String Stack States.
Fall 2005Costas Busch - RPI1 Pushdown Automata PDAs.
1 Pushdown Automata PDAs. 2 Pushdown Automaton -- PDA Input String Stack States.
Finite State Machines Data Structures and Algorithms for Information Processing 1.
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 CS 130: Theory of Computation HMU textbook, Chap 6.
Pushdown Automata (PDAs)
Context-free Languages
Definition Moves of the PDA Languages of the PDA Deterministic PDA’s Pushdown Automata 11.
Lecture Pushdown Automata. stack stack head finite control tape head tape.
Part VII. Models for Context-Free Languages 1/50.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 11 Midterm Exam 2 -Context-Free Languages Mälardalen University 2005.
Pushdown Accepters & Context-Free Grammars Sipser, Theorem 2.12 Denning, Chapter 8.
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.
1 Pushdown Automata There are context-free languages that are not regular. Finite automata cannot recognize all context-free languages.
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.
Pushdown Automata Hopcroft, Motawi, Ullman, Chap 6.
Grammar Set of variables Set of terminal symbols Start variable Set of Production rules.
Lecture 6: Context-Free Languages
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.
Lecture 11  2004 SDU Lecture7 Pushdown Automaton.
6. Pushdown Automata CIS Automata and Formal Languages – Pei Wang.
Formal Languages, Automata and Models of Computation
CSE 105 theory of computation
Deterministic FA/ PDA Sequential Machine Theory Prof. K. J. Hintz
Pushdown automata Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Theorem 29 Given any PDA, there is another PDA that accepts exactly the same language with the additional property that whenever a path leads to ACCEPT,
NPDAs Accept Context-Free Languages
CIS Automata and Formal Languages – Pei Wang
Pushdown Automata PDAs
Pushdown Automata PDAs
Pushdown Automata PDAs
Chapter 7 PUSHDOWN AUTOMATA.
NPDAs Accept Context-Free Languages
Pushdown Automata Reading: Chapter 6.
فصل دوم Context-Free Languages
Pushdown automata a_introduction.htm.
Chapter 2 Context-Free Language - 01
CSE 105 theory of computation
Pushdown automata Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
… NPDAs continued.
Pushdown automata Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Pushdown automata The Chinese University of Hong Kong Fall 2011
Pushdown automata Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
CSE 105 theory of computation
Pushdown automata Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Pushdown automata Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
CSE 105 theory of computation
Presentation transcript:

Chapter 5 Pushdown Automata In this section, we shall introduce pushdown automata as machines to accept context-free languages. For a context-free grammar G, there is an equivalent pushdown automaton M to recognize the language generated by the grammar G. Here the pushdown automaton is nondeterministic, the deterministic version accepts only a subset of all CFL's.

Description of pushdown automaton (PDA) A PDA has an input tape, a finite control, and a stack. 1 (input tape) q1 q1 q1 step1: read 0, push 0, and move to right (stack) step2: read 0, push 0, and move to right (finite control)

There are 2 types of moves: According to an input symbol, current state, and top symbol of the stack, a decision is made, then the input head is moved ahead one symbol. Next move is decided by the current state and the top symbol of the stack only. The input symbol is not used. Hence the input head is not moved at all after the decision is made. This type of move is called ε-move that allows the PDA to manipulate the stack without reading input symbol.

Languages accepted by PDA's There are two ways to accept inputs: The PDA accepts an input if after reading the input and the machine empty its stack. The set of inputs accepted by the PDA is the language accepted by empty stack. Some states of the PDA are final states. The PDA accepts an input if the machine enters a final state. The set of inputs accepted by the PDA is the language accepted by final state.

Definition of PDA's A pushdown automaton M is a system (Q, Σ, Γ, δ, q0, Z0 , F), where Q is a finite set of states; Σ is an alphabet called the input alphabet; Γ is an alphabet, called the stack alphabet; q0 in Q is the initial state; Z0 in Γ is a particular stack symbol called the start symbol; F, a subset of Q, is the set of final states; mapping δ: Q×(Σ∪{ε}) ×Γ → finite subset of Q×Γ*.

Moves: δ(q, a, Z) = {(p1, r1), (p2, r2), ..., (pm, rm)}, where q and pi, 1≦i ≦ m, are states, a is in , Z is a stack symbol, and ri is in Γ*, 1≦i ≦ m, means PDA in state q, reading input symbol a with top symbol Z on the stack, can enter any of the state pi and replaces top symbol Z by ri, and advances reading head one symbol. Example: δ(q1, 0, G) = {(q1, BG)} 1 q1 G R 1 q1 G R B δ

-Moves: δ(q, , Z) = {(p1, r1), (p2, r2), ..., (pm, rm)}, where q and pi, 1≦i ≦ m, are states, Z is a stack symbol, and ri is in Γ*, 1≦i ≦ m, means PDA in state q, without reading any input symbol with top symbol Z on the stack, can enter any of the state pi and replaces top symbol Z by ri, and the reading head remains at the same place. Example: δ(q1, , G) = {(q1, BG)} 1 q1 G R 1 q1 G R B δ

Instantaneous descriptions: If δ(q, a, Z) = contains (p, ), we say (q, a, Z) M(p, ,  ). Example: δ(q1, 0, G) = {(q1, BG)} 1 q1 G R 1 q1 G R B δ For the above case, we have that (q1, 010, GR) M(q1, 01, BGR). Let be the reflexive and transitive closure of M.

Languages accepted by final states: L(M) = {| (q0, , Z0) (p, , ) for some p in F and  in Γ*} Languages accepted by empty stack: N(M) = {| (q0, , Z0) (p, , ) for some p in Q}

Example: N(M) = {wwR| w in (0+1)*}, where M = ({q1, q2}, {0, 1}, {Z0, 0, 1}, δ, q1, Z0, {}), and δ is as follows: δ(q1, 0, Z0) ={(q1, 0Z0)}, δ(q1, 1, Z0) ={(q1, 1Z0)}, δ(q1, 0, 0) ={(q1, 00), (q2, )}, δ(q1, 0, 1) ={(q1, 01)}, δ(q1, 1, 0) ={(q1, 10)}, δ(q1, 1, 1) ={(q1, 11), (q2, )}, δ(q1, , Z0) = {(q2, )}, δ(q2, 0, 0) ={(q2, )}, δ(q2, 1, 1) ={(q2, )}, δ(q2, , Z0) ={(q2, )}.

Example: L(M) = {wwR| w in (0+1)*}, where M = ({q1, q2, q3}, {0, 1}, {Z0, 0, 1}, δ, q1, Z0, {q3}), and δ is as follows: δ(q1, 0, Z0) ={(q1, 0Z0)}, δ(q1, 1, Z0) ={(q1, 1Z0)}, δ(q1, 0, 0) ={(q1, 00), (q2, )}, δ(q1, 0, 1) ={(q1, 01)}, δ(q1, 1, 0) ={(q1, 10)}, δ(q1, 1, 1) ={(q1, 11), (q2, )}, δ(q1, , Z0) = {(q3, Z0)}, δ(q2, 0, 0) ={(q2, )}, δ(q2, 1, 1) ={(q2, )}, δ(q2, , Z0) ={(q3, Z0)}.

Equivalence of acceptance by final states and empty stack Theorem 1 L =L(M1) for some PDA M1  L = N(M2) for some PDA M2. Proof Let M1 = (Q, Σ, Γ, δ, q0, Z0 , F), and L(M1) = L. Construct M2= (Q{qe, q0'}, Σ, Γ{Z'}, δ', q0, Z' , {}), where δ'(q0', , Z') ={(q0, Z0Z')}, δ'(q, a, X) = δ(q, a, X), for all q in Q, a in Σ{}, X in Γ. For all q in F, and X in Γ {Z'}, δ'(q, , X) contains (qe, ). For all X in Γ {Z'}, δ'(qe, , X) contains (qe, ).

Theorem 2 L = N(M2) for some PDA M2  L = L(M1) for some PDA M1. Proof Let M2 = (Q, Σ, Γ, δ, q0, Z0 , {}), and N(M2) = L. Construct M1= (Q{qf, q0'}, Σ, Γ{Z'}, δ', q0', Z', {qf}), where δ'(q0', , Z') ={(q0, Z0Z')}, δ'(q, a, X) = δ(q, a, X), for all q in Q, a in Σ{}, X in Γ. For all q in Q, δ'(q, , Z') contains (qf, ).

5.2 Equivalence of PDA's and CFL's Theorem 3 L is a context-free language  L = N(M) for some PDA M. Proof Assume  is not in L and L = L(G) for some CFG in Greiback normal form G = (V, T, P, S). Let M = ({q}, T, V, δ, q, S , {}), where δ(q, a, A) contains (q, ), whenever Aa is in P. We have that δ(q, a, A) contains (q, ), whenever Aa is in P.

Example L ={anbn | n≧1} is a context-free language . L = L(G), G = (V, T, P, S) a CFG in Greiback normal form, where S  aSB, S  aB, B  b. Let M = ({q}, T, V, δ, q, S , {}), a PDA, where δ(q, a, S) contains (q, SB), where SaSB is in P, δ(q, a, S) contains (q, B), where SaB is in P, δ(q, b, B) contains (q, ), where Bb is in P.

a b q S a b q B S δ(q, a, S) := (q, SB) δ(q, a, S) := (q, B) a b q B a b q B δ(q, b, B) := (q, ) δ(q, b, B) := (q, ) a b q

Theorem 4 L = N(M) for some PDA M  L is a context-free language. Proof Let M = (Q, T, Γ,δ, q0, Z0, {}) be the PDA. Let G = (V, T, P, S) be a context-free grammar, where V is the set of elements of the form [q, A, p], q and p in Q, and A in Γ, plus the new symbol S.

P is the set of productions: S  [q0, Z0, q] for each q in Q; [q, A, qm+1]  a[q1, B1, q2][q2, B2, q3]… [qm, Bm, qm+1] for each q, q1, q2, …,qm+1 in Q, a in {}, and A, B1, B2, …, Bm in Γ, if (q, a, A) contains (q1, B1B2…Bm), for m>0. If m = 0, the production is [q, A, q1]  a.

The key concept of the construction is the following: A leftmost derivation in G of a sentence x is a simulation of the PDA M when the input is x. The variables that appear in any step of a leftmost derivation in G correspond to the symbols on the stack of M at a time when M has scanned as much of the input as the grammar has already generated. In another word, [q, A, p] derives x if and only if x causes M to erase the symbol A from its stack by some sequence of moves beginning in state q and ending in state p.

Example L ={anbn | n≧1} is a context-free language . Let PDA M = ({q}, {a, b}, {S}, δ, q, S , {}), where δ(q, a, S) = {(q, Sb), (q, b)} δ(q, b, b) = {(q, )} Construct G = (V, T, P, S) from M as follows: V = {S, [q, S, q]} P contains the following productions: S  [q, S, q] [q, S, q]  a[q, S, q][q, b, q] [q, b, q]  b [q, S, q]  a[q, b, q]