Download presentation

Presentation is loading. Please wait.

Published byTrevon Daymon Modified about 1 year ago

1
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. 5.1 Pushdown Automata Here the pushdown automaton is nondeterministic, the deterministic version accepts only a subset of all CFL's.

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

3
There are 2 types of moves: 1.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. 2.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.

4
Languages accepted by PDA's There are two ways to accept inputs: 1.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. 2.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.

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

6
Moves: δ(q, a, Z) = {(p1, r1), (p2, r2),..., (p m, r m )}, where q and p i, 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 p i and replaces top symbol Z by r i, and advances reading head one symbol. Example: δ(q1, 0, G) = {(q1, BG)} 010 q1 G R 0010 G R 0 B δ

7
-Moves: δ(q, , Z) = {(p1, r1), (p2, r2),..., (p m, r m )}, where q and p i, 1 ≦ i ≦ m, are states, Z is a stack symbol, and r i 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 p i and replaces top symbol Z by r i, and the reading head remains at the same place. Example: δ(q1, , G) = {(q1, BG)} 010 q1 G R 0010 G R 0 B δ

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

9
Languages accepted by final states: L(M) = { | (q 0, , Z 0 ) (p, , ) for some p in F and in Γ*} Languages accepted by empty stack: N(M) = { | (q 0, , Z 0 ) (p, , ) for some p in Q}

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

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

12
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, Z 0, F), and L(M1) = L. Construct M2= (Q {q e, q 0 '}, Σ, Γ {Z'}, δ', q0, Z', {}), where δ'(q 0 ', , Z') ={(q0, Z 0 Z')}, δ'(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 (q e, ). For all X in Γ {Z'}, δ'(q e, , X) contains (q e, ).

13
Theorem 2 L = N(M2) for some PDA M2 L = L(M1) for some PDA M1. Proof Let M2 = (Q, Σ, Γ, δ, q0, Z 0, {}), and N(M2) = L. Construct M1= (Q {q f, q 0 '}, Σ, Γ {Z'}, δ', q 0 ', Z', {q f }), where δ'(q 0 ', , Z') ={(q0, Z 0 Z')}, δ'(q, a, X) = δ(q, a, X), for all q in Q, a in Σ { }, X in Γ. For all q in Q, δ'(q, , Z') contains (q f, ).

14
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.

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

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

17
Theorem 4 L = N(M) for some PDA M L is a context-free language. Proof Let M = (Q, T, Γ,δ, q 0, Z 0, {}) 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.

18
P is the set of productions: S [q 0, Z 0, q] for each q in Q; [q, A, q m+1 ] a[q 1, B 1, q 2 ][q 2, B 2, q 3 ]… [q m, B m, q m+1 ] for each q, q 1, q 2, …,q m+1 in Q, a in { }, and A, B 1, B 2, …, B m in Γ, if (q, a, A) contains (q 1, B 1 B 2 …B m ), for m>0. If m = 0, the production is [q, A, q 1 ] a.

19
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.

20
Example L ={a n b n | n ≧ 1} is a context-free language. Let PDA M = ({q}, {a, b}, {S}, δ, q, S, {}), where Construct G = (V, T, P, S) from M as follows: δ(q, a, S) = {(q, Sb), (q, b)} δ(q, b, b) = {(q, )} 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, S, q] a[q, b, q][q, b, q] b

Similar presentations

© 2016 SlidePlayer.com Inc.

All rights reserved.

Ads by Google