CIS 5513 - Automata and Formal Languages – Pei Wang 6. Pushdown Automata CIS 5513 - Automata and Formal Languages – Pei Wang
Pushdown automata: idea Context-Free Languages can be accepted by pushdown automata A pushdown automaton is an ɛ-NFA with a stack with unlimited capacity Its transition function also takes the top of the stack into account, and may change the top item in the stack It accepts at a final state or an empty stack
Pushdown automata: definition A pushdown automaton (PDA) P = (Q, Σ, Γ, δ, q0, Z0, F) where Γ (Gamma): A finite stack alphabet δ: Q×(Σ{ε})×Γ → 2Q×Γ*, a transition function that specifies the set of possible next state and the new content at the top of the stack Z0 Γ, the start symbol in stack The other components are like in an ɛ-NFA
Example: transition table A PDA for the binary language {wwr}: P = ({q0,q1,q2}, {0, 1}, {Z0,0,1}, δ, q0, Z0, {q2}) 1. δ(q0, 0, Z0) = {(q0, 0Z0)}; δ(q0, 1, Z0) = {(q0, 1Z0)} 2. δ(q0, 0, 0) = {(q0, 00)}; δ(q0, 0, 1) = {(q0, 01)}; δ(q0, 1, 0) = {(q0, 10)}; δ(q0, 1, 1) = {(q0, 11)} 3. δ(q0, ɛ, Z0) = {(q1, Z0)}; δ(q0, ɛ, 0) = {(q1, 0)}; δ(q0, ɛ, 1) = {(q1, 1)} 4. δ(q1, 0, 0) = {(q1, ɛ)}; δ(q1, 1, 1) = {(q1, ɛ)} 5. δ(q1, ɛ, Z0) = {(q2, Z0)}
Example: transition graph
Instantaneous descriptions of PDA The configuration, or instantaneous description (ID), of a PDA: (q, w, r), where q is the state, w is the remaining input, and r is the stack contents Here “state” only specifies the “control unit”, not the stored “data” in stack If the value of δ(q, a, X) contains (p, α), then the ID transition is (q, aw, Xβ) ˫ (p, w, αβ), for arbitrary w and β
ID transitions: an example
Properties of ID transitions ID transition with multiple moves is shown as ˫* Symbols may be added or removed to input or stack in ID transitions
Exercise 6.1.1 Solution
Two types of acceptance A PDA can define a language in two ways
From Empty Stack to Final State PF can be obtained by adding an ɛ-transition to a final state whenever the stack in PN is empty, with the help of a new stack-symbol below Z0
From Final State to Empty Stack PN can be obtained by popping out all stack symbols in final states in PF, with the help of a new stack-symbol below Z0
6.2.1(a): Design a PDA to accept {0n1n | n ≥ 1} Exercises for Section 6.2 6.2.1(a): Design a PDA to accept {0n1n | n ≥ 1} 6.2.2(a): Design a PDA to accept {aibjck | i = j or j = k} Solutions: http://infolab.stanford.edu/~ullman/ialcsols/sol6.html#sol62
CFG to PDA From a given CFG G = (V, T, Q, S), a PN = ({q},T, VT, , q, S) can accept L(G) by simulating the leftmost derivation to expand the symbols in stack to match the input When PN is in ID (q, y, Aα) where A is a variable and there is a rule A→β in Q, the next ID can be (q, y, βα). Remove the common prefix of βα and y. Repeat until the stack is empty
CFG to PDA: example
PDA to CFG:simple case If a PDA is P = ({q}, Σ, Γ, δ, q, Z), the equivalent CFG G = (Γ{S}, Σ, R, S), where R contains S → Z, and for each (q, Y1Y2…Yk) in δ(q, a, X), R contains X → aY1Y2…Yk, where k ≥ 0, and Yi can be a variable, a terminal, or ε
PDA to CFG: general case Use a grammar variable [pXq] to represent the state change from p to q for the popping out of a stack symbol X
PDA to CFG (cont.)
PDA to CFG: example 6.10: δ(q, i, Z) = {(q, ZZ)}; δ(q, e, Z) = {(q, ε)}
PDA to CFG: example (2)
PDA to CFG: example (3)
Exercises for Section 6.3 Solutions: http://infolab.stanford.edu/~ullman/ialcsols/sol6.html#sol63
Deterministic pushdown automata A PDA is deterministic (DPDA), if Each δ(q, a, X) has at most one element If δ(q, a, X) is nonempty, then δ(q, ɛ, X) must be empty Lwcwr = {wcwR} with a marker c
PDA, DPDA, and DFA The set of language accepted by DPDA is a subset of CFL, and a super set of regular language, so the capability of DPDA is between those of PDA and DFA DPDA accept all regular languages, but only the context-free languages that have unambiguous CFG