Você está na página 1de 18

Push-down Automata

Section 3.3
Fri, Oct 21, 2005
Push-Down Automata
Recall that DFAs accept regular languages.
We want to design machines similar to DFAs that
will accept context-free languages.
These machines will need to be more powerful.
To handle a language like {a
n
b
n
| n > 0}, the machine
needs to remember the number of as.
To do this, we use a stack.
A push-down automaton (PDA) is essentially an NFA
with a stack.
Definition of a Push-Down Automaton
A push-down automaton (PDA) is a sextuple (K, , ,
, s, F) where
K is a finite set of states.
is a finite alphabet of tape symbols.
is a finite alphabet of stack symbols.
s e K is the start state.
F _ K is the set of final states.
is the transition relation, i.e., is a finite subset of
(K ( {e})
*
) (K
*
).
Transitions
Let ((p, a, ), (q, )) e be a transition.
It means that we
Move from state p.
Read a from the tape,
Pop the string from the stack,
Move to state q,
Push string onto the stack.
The first three (p, a, ), are input.
The last two (q, ) are output.
Transitions
We will draw it as
p q
a, |;
Pushing and Popping
When we push , we push the symbols of as we
read them right to left.
When we push the string abc, we push c, then push b, then
push a.
When we pop , we pop the symbols of as we read
them from left to right (reverse order).
When we pop the string abc, we pop a, then pop b, then
pop c.
Pushing and Popping
Thus, if we push the string abc and then pop it, we
will get back abc, not cba.
If we wanted to reverse the order, we would use three
separate transitions:
Push a
Push b
Push c
Configurations
A configuration fully describes the current state of
the PDA.
The current state p.
The remaining input w.
The current stack contents o.
Thus, a configuration is a triple
(p, w, o) e (K, E
*
, I
*
).
Computations
A configuration (p, w, o) yields a configuration
(p', w', o') in one step, denoted
(p, w, o) (p', w', o'),
if there is a transition ((p, a, |), (p', )) e such that
w = aw', o = |q, and o' = q for some q e I
*
.
The reflexive, transitive closure of is denoted
*
.
Accepting Strings
After processing the string on the tape,
The PDA is in either a final or a nonfinal state, and
The stack is either empty or not empty.
The input string is accepted if
The ending state is a final state, and
The stack is empty.
That is, the string w e E
*
is accepted if
(s, w, e)
*
(f, e, e)
for some f e F.
Accepting Strings
One may define acceptance by final state only.
The input is accepted if and only if the last state is a final
state, regardless of whether the stack is empty.
One may define acceptance by empty stack only.
The input is accepted if and only if the stack is empty once
the input is processed, regardless of which state the PDA is
in.
Example of a PDA
Run the following PDA on the input string aaabbb.
s p q
a, e; a
b, a; e
b, a; e
a, e; a
Example of a PDA
The steps in the processing are
(s, aaabbb, e) (p, aabbb, a)
(p, abbb, aa)
(p, bbb, aaa)
(p, bb, aa)
(p, b, a)
(q, e, e).
The Language of a PDA
The language of a PDA A is
L(A) = {w e E
*
|A accepts w}.
What is the language of the PDA in the previous
example?
s p
e, e; e
b, a; e a, e; a
Example of a PDA
What is the language of the following PDA?
Examples of PDAs
Let E = {a, b}.
Design a PDA that accepts the language
{wcw
R
| w e E
*
}.
Design a PDA that accepts the language
{ww
R
| w e E
*
}.
Examples of PDAs
Design a PDA whose language is
{a
m
b
n
| 0 s m < n}.
Design a PDA whose language is
{a
m
b
n
| 0 s n < m}.
Examples of PDAs
Design a PDA whose language is
{a
m
b
n
c
n
d
m
| m > 0, n > 0}.
Design a PDA whose language is
{a
m
b
m
c
n
d
n
| m > 0, n > 0}.
Design a PDA whose language is
{a
m
b
n
c
p
d
q
| m + n = p + q}.
Design a PDA whose language is
{a
m
b
n
c
k
| m = n or m = k}.

Você também pode gostar