1 / 31

Pushdown Automata

Pushdown Automata. Juan Carlos Guzmán CS 6413 Theory of Computation Southern Polytechnic State University. Summary. Definitions Languages recognized Equivalence to Context-Free Grammars Deterministic PDA’s. 0. 1. 0. 0. 1. 0. 1. 1. 0. 1. 1. 0. 0. 1. 0. Pushdown Automaton.

Download Presentation

Pushdown Automata

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Pushdown Automata Juan Carlos Guzmán CS 6413 Theory of Computation Southern Polytechnic State University

  2. Summary • Definitions • Languages recognized • Equivalence to Context-Free Grammars • Deterministic PDA’s

  3. 0 1 0 0 1 0 1 1 0 1 1 0 0 1 0 Pushdown Automaton • A pushdown automaton is • ε-NFA • States • Transitions • Tape • Read-only • Read-once • Finite • Plus a stack • LIFO

  4. Pushdown Automaton • A pushdown automaton P is a seven-element tuple P = (Q,Σ,Γ,δ,q0,Z0,F ) • where • Q is the set of states • Σ is the alphabet of the input tape • Γ is the alphabet of the stack • δ is the transition function • q0 is the initial state • Z0 is the initial stack symbol • F is the set of final states

  5. 1,0/ε q1 1,0/ε ε,Z0/ε start q0 q2 0,Z0/0Z0 0,0/00 ε,Z0/ε Pushdown Automaton • L = {0n1n} • P = ({q0,q1,q2},{0,1},{Z0,0,1},δ,q0,Z0,{q2}), where • δ(q0,0,Z0) = (q0,0Z0) • δ(q0,0,0) = (q0,00) • δ(q0,1,0) = (q1,ε) • δ(q0,ε,Z0) = (q2,ε) • δ(q1,1,0) = (q1,ε) • δ(q1,ε,Z0) = (q2,ε)

  6. Instantaneous Descriptions • The instantaneous description of a PDA is the triple (q, w, ), where • q is a state • w is the remaining input •  is the stack contents

  7. Movement Relation • Establishes the relation between different instantaneous descriptions • (q,aw,X) ├ (p,w,) • if (p,)  δ(q,a,X )

  8. Languages of a PDA • Remember that languages are sets of strings that satisfy a property • For a phrase, the automaton, started in its initial state, lands in a final state with the input tape completely consumed • Acceptance by final state L(P ) = { w | (q0,w,Z0) ├* (q,ε,), qF } • For a phrase, the automaton, started in its initial state, consumes all stack symbols as the input tape completely consumed • Acceptance by empty stack N(P ) = { w | (q0,w,Z0) ├* (q,ε,ε) }

  9. L(P ) vs. N(P ) vs. CFL • For a particular PDA P, L(P) and N(P) may be different • Take the families of languages implied by L(P) and N(P) over all PDA’s P • Do they refer to the same family?, or • Is there a language in one of these families and not in the other? • Is one of them more powerful than the other? • How do these families relate to the Context-Free Languages?

  10. Th. 6.13 Th. 6.9 Context-free Grammar PDA by empty stack PDA by final state Th. 6.14 Th. 6.11 Equivalences • These families of languages are equal • Context-Free Languages • Languages accepted by final state of a PDA • Languages accepted by empty stack of a PDA

  11. From Acceptance by Empty Stack to Final State • For any L, if there exists PN such that L=N(PN), then there is PF such that L=L(PF) • If a language is accepted by empty stack by a PDA, then construct a new PDA with an augmented stack: • A new initial stack symbol (X0) • A new initial state (p0) • A new final state (pf) • Augment the transitions as follows • The initial state should insert Z0 (old initial stack symbol into the stack) • All old states should have a transition to move to the new final state if X0 is visible

  12. PF ε,X0/ε ε,X0/ε PN start ε,X0/ε ε,X0/Z0X0 p0 q0 pf ε,X0/ε From Acceptance by Empty Stack to Final State • PN= (Q,Σ,Γ,δ,q0,Z0,) • PF= (Q {p0,pf},Σ,Γ{X0},δ’,p0,X0,{pf}), where • δ’(p0,ε,X0) = {(q0,Z0X0)} • δ’(q,ε,X0) = {(pf , ε)}, for qQ • δ’(q,a,X) = δ(q,a,X), otherwise

  13. From Acceptance by Final State to Empty Stack • For any L, if there exists PF such that L=L(PF), then there is PN such that L=N(PN)

  14. PN ε,any/ε PL ε,any/ε start ε,any/ε ε,X0/Z0X0 p0 q0 p ε,any/ε From Acceptance by Final State to Empty Stack • PF= (Q,Σ,Γ,δ,q0,Z0,F) • PF= (Q {p0,p},Σ,Γ{X0},δ’,p0,X0,), where • δ’(p0,ε,X0) = {(q0,Z0X0)} • δ’(q,ε,X) = {(p,ε)}, for all qF {p},all X ΓU{X0} • δ’(q,a,X) = δ(q,a,X), otherwise

  15. From Grammars to PDA’s • Given G, construct a PDA P that simulates leftmost derivations of G • A sentential form can be characterized as xA, where A is the leftmost variable • We will call A as its tail • We want to make sure that • S* xA * xy, iff • (q,xy,S)├* (q,y,A)├* (q,ε,ε)

  16. From Grammars to PDA • Let G = (V,T,Q,S ) • P = ({q},T,V T,δ,q,S ), where • δ(q,ε,A) = {(q,β) | A βQ } (derive) • δ(q,a,a) = {(q,ε)} (match) • Note that there is not a one-to-one correspondence between the leftmost derivation in the grammar and the movements of the automaton • Nice automaton but, does it recognize the same language as the grammar? Prove by induction (on the number of derivations taken to obtain the phrase

  17. Example • Let G = ({A,C},{0,1},R,A), where R = {A 0 C | ε, C 0 C 1 | 1} • The PDA is P = ({q},{0,1},{0,1,A,C},δ,q,A), where • δ(q,ε,A) = {(q,0C ),(q,ε)} • δ(q,ε,C) = {(q,0C 1),(q,1)} • δ(q,0,0) = {(q,ε)} • δ(q,1,1) = {(q,ε)}

  18. (q,000111,A) ├ (q,000111,0C) ├ (q,00111,C) ├ (q,00111,0C 1) ├ (q,0111,C 1) ├ (q,0111,0C 11) ├ (q,111,C 11) ├ (q,111,111) ├ (q,11,11) ├ (q,1,1) ├ (q,ε,ε) Grammar vs. PDA A 0 C 0 C 1 0 C 1 1

  19. Correctness • L(G) = L(P) • Vw, S =>*w iff (q,w,S) |-*(q,eps,eps) • By induction on the number of derivations

  20. From PDA’s to Grammars • This is a more complex construction, since we have to deal with different states

  21. From PDA’s to Grammars • Let P = (Q,Σ,Γ,δ,q0,Z0) be a PDA • Let G = (V, Σ,R,S ), such that • SV • For all p,q  Q, X  Γ, [pXq]  V • For all p  Q, S[q0Z0p]  R • If (r,Y1Y2…Yk) in δ(q,a,X) • then, for all states ri • [qXrk]a[rY1r1][r1Y2r2]…[rk-1Ykrk]

  22. Example • Recall sample automaton

  23. S [q01q0] [q01q1] [q01q2] [q11q0] [q11q1] [q11q2] [q21q0] [q21q1] [q21q2] Grammar – Variables [q0Z0q0] [q0Z0q1] [q0Z0q2] [q1Z0q0] [q1Z0q1] [q1Z0q2] [q2Z0q0] [q2Z0q1] [q2Z0q2] [q00q0] [q00q1] [q00q2] [q10q0] [q10q1] [q10q2] [q20q0] [q20q1] [q20q2]

  24. S S  [q0Z0q0] S  [q0Z0q1] S  [q0Z0q2] δ(q0,0,Z0) = (q0,0Z0) [q0Z0q0]  0[q00q0][q0Z0q0] [q0Z0q0]  0[q00q1][q1Z0q0] [q0Z0q0]  0[q00q2][q2Z0q0] [q0Z0q1]  0[q00q0][q0Z0q1] [q0Z0q1]  0[q00q1][q1Z0q1] [q0Z0q1]  0[q00q2][q2Z0q1] [q0Z0q2]  0[q00q0][q0Z0q2] [q0Z0q2]  0[q00q1][q1Z0q2] [q0Z0q2]  0[q00q2][q2Z0q2] δ(q0,0,0) = (q0,00) [q00q0]  0[q00q0][q00q0] [q00q0]  0[q00q1][q10q0] [q00q0]  0[q00q2][q20q0] [q00q1]  0[q00q0][q00q1] [q00q1]  0[q00q1][q10q1] [q00q1]  0[q00q2][q20q1] [q00q2]  0[q00q0][q00q2] [q00q2]  0[q00q1][q10q2] [q00q2]  0[q00q2][q20q2] Grammar – Productions

  25. δ(q0,1,0) = (q1,ε) [q00q1]  1 δ(q0,ε,Z0) = (q2,ε) [q0Z0q2]  ε δ(q1,1,0) = (q1,ε) [q10q1]  1 δ(q1,ε,Z0) = (q2,ε) [q1Z0q2]  ε Grammar – Productions

  26. The generated grammar has 28 variables 25 productions However, most of them are “useless” The highlighted variables and productions are not useless Variables [q0Z0q2] [q1Z0q2] [q00q1] [q10q1] Productions S[q0Z0q2] [q0Z0q2]  0[q00q1][q1Z0q2] [q00q1]  0[q00q1][q10q1] [q00q1]  1 [q0Z0q2]  ε [q10q1]  1 [q1Z0q2]  ε Grammar – Notes

  27. (q0,000111,Z0) ├ (q0,00111,0Z0) ├ (q0,0111,00Z0) ├ (q0,111,000Z0) ├ (q1,11,00Z0) ├ (q1,1,0Z0) ├ (q1,ε,Z0) ├ (q2,ε,ε) PDA vs. Grammar S [q0Z0q2] 0 [q00q1] [q1Z0q2] 0 [q00q1] ε [q10q1] 0 [q00q1] [q10q1] 1 1 1

  28. (q0,000111,Z0) ├ (q0,00111,0Z0) ├ (q0,0111,00Z0) ├ (q0,111,000Z0) ├ (q1,11,00Z0) ├ (q1,1,0Z0) ├ (q1,ε,Z0) ├ (q2,ε,ε) PDA vs. Grammar 8 1 S 8 1 [q0Z0q2] 7 2 8 7 0 [q00q1] [q1Z0q2] 6 3 7 6 0 [q00q1] ε [q10q1] 5 4 6 5 0 [q00q1] [q10q1] 1 1 1

  29. Let’s rename the variables: [q0Z0q2] ↦ A [q1Z0q2] ↦ B [q00q1] ↦ C [q10q1] ↦ D Productions S  A A 0 C B | ε C 0 C D | 1 D 1 B ε Equivalent Grammar A 0 C | ε C 0 C 1 | 1 Grammar – Notes S A 0 C B 0 C ε D 0 C D 1 1 1

  30. Deterministic PDA • There is never a choice of movement in any situation • δ(q,a,X) does not contain more than one entry • If some δ(q,a,X) is nonempty, then δ(q,ε,X) must be empty

  31. Recognize some CFL’s Recognize some languages that are not regular Do not recognize all CFL’s Deterministic PDA PDA’s DPDA’s FA’s

More Related