Pushdown Automata (PDA) : Reading: Chapter 6
Pushdown Automata (PDA) : Reading: Chapter 6
Pushdown Automata (PDA) : Reading: Chapter 6
Reading: Chapter 6
1
PDA - the automata for CFLs
■ What is?
■ FA to Reg Lang, PDA is to CFL
■ PDA == [ ε -NFA + “a stack” ]
■ Why a stack?
3
old state input symb. Stack top new state(s) new Stack top(s)
δ: Q x ∑ x Γ => Q x
Γ
δ : The Transition Function
δ(q,a,X) = {(p,Y), …}
1. state transition from q to p
2. a is the next input symbol a X Y
3. X is the current stack top symbol q p
No
4.
- d
it is in Γ* (a string of stack
e
Y=? Action
te
symbols)
m r
ii.
ii) Y=X Pop(X)
iii. If Y=Z1Z2…Zk: X is popped
and is replaced by Y in Push(X)
reverse order (i.e., Z1 will be iii) Y=Z1Z2..Zk Pop(X)
the new stack top) Push(Zk)
Push(Zk-1)
…
Push(Z2)
Push(Z1)
4
Example
Let Lwwr = {wwR | w is in (0+1)*}
■ CFG for L : S==> 0S0 | 1S1 | ε
wwr
■ PDA for L :
wwr
■ P := ( Q,∑, Γ, δ,q ,Z ,F )
0 0
5
Initial state of the PDA:
Stack q0
1. δ(q0,0, Z0)={(q0,0Z0)}
First symbol push on stack
2. δ(q0,1, Z0)={(q0,1Z0)}
3. δ(q0,0, 0)={(q0,00)}
4. δ(q0,0, 1)={(q0,01)}
5. δ(q0,1, 0)={(q0,10)} Grow the stack by pushing
6. δ(q0,1, 1)={(q0,11)} new symbols on top of old
(w-part)
7. δ(q0, ε, 0)={(q1, 0)}
8. δ(q0, ε, 1)={(q1, 1)} Switch to popping mode, nondeterministically
9. δ(q0, ε, Z0)={(q1, Z0)}
(boundary between w and wR)
10. δ(q1,0, 0)={(q1, ε)}
11. δ(q1,1, 1)={(q1, ε)} Shrink the stack by popping matching
symbols (wR-part)
12. δ(q1, ε, Z0)={(q2, Z0)}
Enter acceptance state
6
PDA as a state diagram
δ(qi,a, X)={(qj,Y)}
a, X / Y Next
q q
state
i j
7
PDA for Lwwr: Transition Diagram
q q q
ε, Z0/Z0
0 ε, Z0/Z0 1 ε, Z0/Z0 2
ε, 0/0
ε, 1/1 Go to acceptance
Switch to
popping mode