250 likes | 437 Views
CS 3240 – Chapter 7. Pushdown Automata. Where Are We?. A Pushdown Automaton Machine for Context-Free Languages. Take an FA and add a stack A restricted form of unbounded memory Operations: Pop Push Ignore ( λ ) (Pop always precedes push). PDA Operations.
E N D
CS 3240 – Chapter 7 Pushdown Automata
Where Are We? CS 3240 - Introduction
A Pushdown AutomatonMachine for Context-Free Languages • Take an FA and add a stack • A restricted form of unbounded memory • Operations: • Pop • Push • Ignore (λ) • (Pop always precedes push) CS 3240 - Pushdown Automata
PDA Operations • Three items per transition edge • <read>,<pop>,<push> • any or all could be λ • A PDA accepts when: • An accepting state is reached, and • The stack is empty • Different from book! • The machine crashes when no move is possible • implicit jail CS 3240 - Pushdown Automata
A PDA for anbn (n > 0) A deterministic PDA (no choices; λ is okay sometimes). The stack alphabet (Γ = {X}) can differ from the input alphabet (Σ = {a, b}) . Trace aabb… CS 3240 - Pushdown Automata
Tracing the PDA(<state> | <input> | <stack>) q0 aabb λ q0 abb X q0 bb XX q1 b X q1 λ λ Traditional notation (see book): (q0,aabb, λ) ⊢ (q0,abb,X) ⊢ (q0,bb,XX) ⊢ (q1,b,X) ⊢ (q1,λ, λ) Also: (q0,aabb,λ) ⊢*(q1,λ, λ) (⇒ aabb ∈ L) CS 3240 - Pushdown Automata
A PDA for anbn (n ≥ 0) CS 3240 - Pushdown Automata
A PDA for anb2n (n ≥ 0) How would you do a2nbn? CS 3240 - Pushdown Automata
a2nbn Each b must pop 2 X’s CS 3240 - Pushdown Automata
A PDA for wcwR Is this deterministic? Trace the string abaacaaba. CS 3240 - Pushdown Automata
Transition Functions for PDAs • Input: (state-1, input character, pop character) • Output: (state-2, push character(s)) • Example: The edge (a,λ,a) on previous slide: δ(q0,a,λ) = (q0,a) • Exercise: • Rewrite wcwR in functional form CS 3240 - Pushdown Automata
A PDA for All Palindromes Is this deterministic? Trace the string abaaaaaba. Trace the string abaabaaba. Trace the string abaaaaba. CS 3240 - Pushdown Automata
A PDA for ambn, m ≤ n ≤ 2mNon-deterministic The grammar: S → aSb | aSbb | λ Trace aaabbbb CS 3240 - Pushdown Automata
A PDA for Equal Trace ababbaab CS 3240 - Pushdown Automata
A PDA for nb = na + 1 CS 3240 - Pushdown Automata
A PDA for Twicebnb = 2na • Reasoning: There must be 2 b’s for every a. When we read an a, there are three possibilities: • Its 2 b’s have already been read • 1 b has been read and 1 remains • Both b’s are yet to be read Try abababbbb. How would you do Twicea? CS 3240 - Pushdown Automata
What Language Is This? CS 3240 - Pushdown Automata
aibjck, i,j,k ≥ 0, i = jor i = k CS 3240 - Pushdown Automata
anor anbn CS 3240 - Pushdown Automata
Formal Definition of PDAs • Q: set of states • ∑: input alphabet • Γ: stack alphabet • δ: Q x (∑∪λ) x (Γ∪λ) →finite subsets of Q x Γ* • q0: start state • F ⊆ Q: final states • (z ⋲ Γ: optional stack start symbol) CS 3240 - Pushdown Automata
Using Stack Start Symbols • Not strictly necessary • Can serve as a “bottom marker” to allow detection of an empty stack • A convenience • Can make things easier to design/understand • Sometimes handy when seeking an associated CFG • Can eliminate some lambda pops • Handy later CS 3240 - Pushdown Automata
anbn with a Start Symbol CS 3240 - Pushdown Automata
A PDA for EqualUsing a Stack Start Symbol (“Almost” Deterministic) CS 3240 - Pushdown Automata