You are on page 1of 20

CS 25

Automata Theory & Formal Languages

Lecture 6

PUSHDOWN AUTOMATA

The PDA is an automaton equivalent to the CFG in


language-defining power.
Only the nondeterministic PDA defines all the CFLs.
But the deterministic version models parsers.
Most programming languages have deterministic
PDAs.

PUSHDOWN AUTOMATA
A pushdown automata (PDA) is essentially an NFA with a
stack.
On a transition the PDA:
1. Consumes an input symbol.
2. Goes to a new state (or stays in the old).
3. Replaces the top of the stack by any string (does nothing, pops
the stack, or pushes a string onto the stack)

PUSHDOWN AUTOMATA

Schematic of a pushdown automaton

FORMAL DEFINITION OF A
PUSHDOWN AUTOMATON (PDA)
A pushdown automaton is a 6-tuple (Q, , ,, q0, F), where Q, ,
and F are all finite sets, and

1. Q is the set of states


2. is the input alphabet
3. is the stack alphabet
: Q x x P(Q x ) is the transition function
5. q0 Q is the start state, and
6. F Q is the set of accept states

FORMAL DEFINITION OF A
PUSHDOWN AUTOMATON (PDA)
TRANSITION FUNCTION : Q x x P(Q x )

Takes three arguments:


1. A state, in Q.
2. An input, which is either a symbol in or .
3. A stack symbol in .

(q, a, Z) is a set of zero or more actions of the form


(p, ).

p is a state; is a string of stack symbols.

FORMAL DEFINITION OF A
PUSHDOWN AUTOMATON (PDA)
Actions of the PDA
If (q, a, Z) contains (p, ) among its actions, then one thing
the PDA can do in state q, with a at the front of the input,
and Z on top of the stack is:
1. Change the state to p.
2. Remove a from the front of the input (but a may be ).
3. Replace Z on the top of the stack by .

EXAMPLE OF PUSHDOWN AUTOMATA


EXAMPLE 1: A formal description of the PDA for the language {0n1n|n0}

Let P1 be (Q, , ,, q1, F), where


Q = {q1, q2, q3, q4},
= { 0,1 }
= { 0,$ }
F = { q1,q4 }, and
is given by the following table, wherein blank entries signify .
0

Input
Stack

q1
q2
q3
q4

{(q2,$)}

{(q2,0)}

{(q3, )}
{(q3, )}

{(q4, )}

EXAMPLE OF PUSHDOWN AUTOMATA


EXAMPLE 1: Transitions of PDA for the language {0n1n|n0}
0

Input
Stack

q1
q2
q3

{(q2,$)}

{(q2,0)}

{(q3, )}
{(q3, )}

{(q4, )}

q4

(q1, , ) = {(q2, $)}. Push the $symbol to mark the bottom of the stack.
(q2, 0, ) = {(q2, 0)}. Push 0 onto the stack for each 0 read from the input.
(q2, 1, 0) = {(q3, )}. When we see a 1, go to state q3 and pop one 0.
(q3, 1, 0) = {(q3, )}. Pop one 0 from the stack for every 1 read from input.
(q3, , $) = {(q4, )}. Accept if stack bottom is reach and last state is accept.

EXAMPLE OF PUSHDOWN AUTOMATA


0

Input
Stack

q1
q2

{(q2,$)}

{(q2,0)}

q3

{(q3, )}
{(q3, )}

{(q4, )}

q4

q1

, $

0, 0

q2

1, 0

q4

, $

q3

1, 0

State diagram for the PDA P1 that recognizes {0n1n|n0}

Actions of the Example PDA


000111
q1

Stack is empty

11

Actions of the Example PDA


000111
q2

12

Actions of the Example PDA


00111
q2

0
$

13

Actions of the Example PDA


0111
q2

0
0
$
14

Actions of the Example PDA


111
q2

0
0
0
$
15

Actions of the Example PDA


11
q3

0
0
$
16

Actions of the Example PDA


1
q3

0
$

17

Actions of the Example PDA

q3

18

Actions of the Example PDA

q4

Stack is empty

19

EXAMPLE OF PUSHDOWN AUTOMATA


EXAMPLE 2: A PDA that recognizes the language
{aibjck|i,j,k0andi=jori=k}.
c,

b,a

q1
, $

q3

,$

q4

q2
a, a

q5

b,

q6
c,a

, $

q7

You might also like