Presentation is loading. Please wait.

Presentation is loading. Please wait.

6. Pushdown Automata CIS Automata and Formal Languages – Pei Wang.

Similar presentations


Presentation on theme: "6. Pushdown Automata CIS Automata and Formal Languages – Pei Wang."— Presentation transcript:

1 6. Pushdown Automata CIS 5513 - Automata and Formal Languages – Pei Wang

2 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

3 Pushdown automata: definition A pushdown automaton (PDA) P = (Q, Σ, Γ, δ, q 0, Z 0, F) where  Γ (Gamma): A finite stack alphabet  δ: Q×(Σ  {ε})×Γ → 2 Q×Γ*, a transition function that specifies the set of possible next state and the new content at the top of the stack  Z 0  Γ, the start symbol in stack The other components are like in an ɛ -NFA

4 Example: transition table A PDA for the binary language {ww r }: P = ({q 0,q 1,q 2 }, {0, 1}, {Z 0,0,1}, δ, q 0, Z 0, {q 2 }) 1. δ(q 0, 0, Z 0 ) = {(q 0, 0Z 0 )}; δ(q 0, 1, Z 0 ) = {(q 0, 1Z 0 )} 2. δ(q 0, 0, 0) = {(q 0, 00)}; δ(q 0, 0, 1) = {(q 0, 01)}; δ(q 0, 1, 0) = {(q 0, 10)}; δ(q 0, 1, 1) = {(q 0, 11)} 3. δ(q 0, ɛ, Z 0 ) = {(q 1, Z 0 )}; δ(q 0, ɛ, 0) = {(q 1, 0)}; δ(q 0, ɛ, 1) = {(q 1, 1)} 4. δ(q 1, 0, 0) = {(q 1, ɛ )}; δ(q 1, 1, 1) = {(q 1, ɛ )} 5. δ(q 1, ɛ, Z 0 ) = {(q 2, Z 0 )}

5 Example: transition graph

6 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 β

7 ID transitions: an example

8 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

9 Exercise 6.1.1 Solution

10 Two types of acceptance A PDA can define a language in two ways

11 Equivalence of the two types Proof: P F can be obtained by adding an ɛ -transition to a final state whenever the stack in P N is empty, with the help of a new stack-symbol below Z 0 Proof: P N can be obtained by popping out all stack symbols in final states in P F, with the help of a new stack-symbol below Z 0

12 Exercises for Section 6.2 6.2.1(a): Design a PDA to accept {0 n 1 n | n ≥ 1} 6.2.2(a): Design a PDA to accept {a i b j c k | i = j or j = k} Solutions: http://infolab.stanford.edu/~ullman/ialcsols/sol6.html#sol62

13 CFG to PDA From a given CFG G = ( V, T, Q, S ), a P N = ({q}, T, V  T, , q, S ) can accept L( G ) by simulating the leftmost derivation to expand the symbols in stack to match the input When P N 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

14 CFG to PDA: example

15 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, Y 1 Y 2 …Y k ) in δ(q, a, X), R contains X → aY 1 Y 2 …Y k, where k ≥ 0, and Y i can be a variable, a terminal, or ε

16 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

17 PDA to CFG (cont.)

18 PDA to CFG: example

19 PDA to CFG: example (cont.) 6.10: δ(q, i, Z) = {(q, ZZ)}; δ(q, e, Z) = {(q, ε)}

20 Exercises for Section 6.3 Solutions: http://infolab.stanford.edu/~ullman/ialcsols/sol6.html#sol63http://infolab.stanford.edu/~ullman/ialcsols/sol6.html#sol63

21 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

22 PDA, DPDA, and DFA The languages accepted by DPDA are between those of PDA and DFA DPDA accept all regular languages, but only the context-free languages that have unambiguous CFG


Download ppt "6. Pushdown Automata CIS Automata and Formal Languages – Pei Wang."

Similar presentations


Ads by Google