0% found this document useful (0 votes)
15 views20 pages

Pushdown Automata

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views20 pages

Pushdown Automata

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 20

Pushdown Automata

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.

Here the pushdown automaton is nondeterministic, the


deterministic version accepts only a subset of all CFL's.
Description of pushdown automaton (PDA)

A PDA has
an input tape,
a finite control, and
a stack.

0 0 0 1 0 0 0 (input tape)

step1: read 0, push 0, and move to right

q1 q1 q1 step2: read 0, push 0, and move to right


0
(finite control) 0
(stack)
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.
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.
Definition of PDA's

A pushdown automaton M is a system (Q, Σ, Γ, δ, q0, Z0 , 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. q0 in Q is the initial state;

5. Z0 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×Γ*.


Moves:

q and pi, 1≦i ≦ m, are states, a is in , Z is a stack


δ(q, a, Z) = {(p1, r1), (p2, r2), ..., (pm, rm)}, where

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 pi and replaces top
symbol Z by ri, and advances reading head one symbol.

Example: δ(q1, 0, G) = {(q1, BG)}

0 0 1 0 0 0 1 0
δ B
G G
q1 q1
R R
-Moves:

q and pi, 1≦i ≦ m, are states, Z is a stack symbol,


δ(q, , Z) = {(p1, r1), (p2, r2), ..., (pm, rm)}, where

and ri 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 pi and
replaces top symbol Z by ri, and the reading head remains
at the same place.
Example: δ(q1, , G) = {(q1, BG)}

0 0 1 0 0 0 1 0
δ B
G G
q1 q1
R R
Instantaneous descriptions:

If δ(q, a, Z) = contains (p, ), we say


(q, a, Z)  M(p, ,  ).

Example: δ(q1, 0, G) = {(q1, BG)}

0 0 1 0 0 0 1 0
δ B
G G
q1 q1
R R

For the above case, we have that


(q1, 010, GR)  M(q1, 01, BGR).

Let  * be the reflexive and transitive closure of


M
 M.
Languages accepted by final states:

L(M) = {| (q0, , Z0)  *(p, $, ) for some p in F and


M
 in Γ*}

Languages accepted by empty stack:

N(M) = {| (q0, , Z0)  * (p, $, Z0) for some p in Q}


M
Example: N(M) = {wwR| w in (0+1)*}, where

M = ({q1, q2}, {0, 1}, {Z0, 0, 1}, δ, q1, Z0, {}), and δ is as
follows:

δ(q1, 0, Z0) ={(q1, 0Z0)}, δ(q2, 0, 0) ={(q2, )},


δ(q1, 1, Z0) ={(q1, 1Z0)}, δ(q2, 1, 1) ={(q2, )},

δ(q1, 0, 0) ={(q1, 00), (q2, )}, δ(q2, , Z0) ={(q2, )}.

δ(q1, 0, 1) ={(q1, 01)},


δ(q1, 1, 0) ={(q1, 10)},
δ(q1, 1, 1) ={(q1, 11), (q2, )},
δ(q1, , Z0) = {(q2, )},
Example: L(M) = {wwR| w in (0+1)*}, where

M = ({q1, q2, q3}, {0, 1}, {Z0, 0, 1}, δ, q1, Z0, {q3}), and δ is
as follows:

δ(q1, 0, Z0) ={(q1, 0Z0)}, δ(q2, 0, 0) ={(q2, )},


δ(q1, 1, Z0) ={(q1, 1Z0)}, δ(q2, 1, 1) ={(q2, )},

δ(q1, 0, 0) ={(q1, 00), (q2, )}, δ(q2, , Z0) ={(q3, Z0)}.

δ(q1, 0, 1) ={(q1, 01)},


δ(q1, 1, 0) ={(q1, 10)},
δ(q1, 1, 1) ={(q1, 11), (q2, )},
δ(q1, , Z0) = {(q3, Z0)},
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, Z0 , F), and L(M1) = L.
Construct M2= (Q{qe, q0'}, Σ, Γ{Z'}, δ', q0, Z' , {}), where
δ'(q0', , Z') ={(q0, Z0Z')},
δ'(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 (qe, ).
For all X in Γ {Z'}, δ'(qe, , X) contains (qe, ).
Theorem 2 L = N(M2) for some PDA M2  L = L(M1) for
some PDA M1.

Proof
Let M2 = (Q, Σ, Γ, δ, q0, Z0 , {}), and N(M2) = L.
Construct M1= (Q{qf, q0'}, Σ, Γ{Z'}, δ', q0', Z', {qf}), where
δ'(q0', , Z') ={(q0, Z0Z')},
δ'(q, a, X) = δ(q, a, X), for all q in Q, a in Σ{}, X in Γ.
For all q in Q, δ'(q, , Z') contains (qf, ).
Example L ={anbn | n≧1} is a context-free language .

L = L(G), G = (V, T, P, S) a CFG in Greiback normal form,


where S  aSB, S  aB, B  b.

Let M = ({q}, T, V, δ, q, S , {}), a PDA, where


δ(q, a, S) contains (q, SB), where SaSB is in P,

δ(q, a, S) contains (q, B), where SaB is in P,

δ(q, b, B) contains (q, ), where Bb is in P.


Equivalence of PDA's and CFL's
Theorem: L is a context-free language then there exist some
NPDA M such that L =L(M).
Proof: let L = L(G) for some CFG in Greibach normal form
G = (V, T, P, S).
Equivalence of PDA's and CFL's
Theorem If L = L (M) for some npda M, then L is a context-
free language.

Proof Let M = (Q, T, Γ,δ, q0, Z0, {qf}) 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.
P is the set of productions:
4. For each transaction (qi, a, A) =(qj, A).
[qi, A, qk]  a [qj, a, qk]
for each qk in Q,
Example L ={anbn | n≧1} is a context-free language .

Let PDA M = ({q}, {a, b}, {S}, δ, q, S , {}), where

δ(q, a, S) = {(q, Sb), (q, b)}

δ(q, b, b) = {(q, )}

Construct G = (V, T, P, S) from M as follows:

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, b, q]  b [q, S, q]  a[q, b, q]

You might also like