Chapter 7 Pushdown Automata
Chapter 7 Pushdown Automata
1
Difference between FA and PDA
An informal definition of PDA
An input string
A read head to exam input once cell at a
time
A finite state machine to control moves
LIFO push down stack
DPDA is not equivalent to NPDA
2
Definition 7.1
A nondeterministic pushdown accepter
(npda) is defined by the septuple
M = (Q, Σ, Γ, δ, q0, z, F)
Q, Σ, δ, q0, and F are the same as they are in FA
Example 7.1
sample NPDA transition rule
δ (q1, a, b) = {(q2, cd), (q3, λ)}
What does this transition rule mean?
Two things can happen when in q1, read
a, and top of the stack is b
1. Move to q2, and the string cd replaces b
2. Move to q3, and pop b
3
NPDA Examples
FA → NPDA
Every FA can be transformed to a PDA
{anbn, n ≥ 0}
Can you design an algorithm for this PDA?
Example 7.2. L = {anbn, n ≥ 0} ∪ {a}
PDA design and implementation
Design an algorithm first
Present your design in transition function, TG, or in
picture notation (in Cohen book)
Example 7.3
TG for npda in example 7.2
4
The Language Accepted by a
PDA
M = (Q, Σ, Γ, δ, q0, z, F)
5
More examples of NPDA -2
Example 7.4
Construct a npda for the language
L = {w ∈ {a, b}*: na(w) = nb(w)}
Algorithm design for this npda
Counter 0 is pushed into stack for each a read
Negative counter 1 for counting b’s that are to be
matched against a’s later
TG in next slide
6
Exercises from Linz 7.1
Construct npda’s that accept the
following languages on ∑ = {a, b, c}
Exercise #4
(c) L = {anbmcn+m: n ≥ 0, m ≥ 0}
Try it in class
Algorithm first
Implementation next
7
Example 7.6 - 1
Construct a pda that accepts the language
generated by grammar S → aSbb | a
Example 7.6 - 2
In an analogous manner,
A → bB gives
8
CFG for PDA
Theorem 7.2
If L = L(M) for some npda M, the L is a CFL
Proof.
A constructive proof to show that it is always possible to
construct a grammar from a npda.
This theorem tells us that there always a CFG for
a language represented by a npda.
In practice, one may design a CFG directly from
the give CFL