Pushdown Automaton

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 8

Pushdown Automaton

(PDA)
A Pushdown Automaton is a nondeterministic
finite state automaton (NFA) that permits
-transitions and a stack.
Pushdown Automaton (PDA)
{ } ( ) F q q a q Q P
n k m i
, , , ),... , ( ) , , ( , , ,
0 0
t t t o I E =
Q: A finite set of states.
E : A finite set of input symbols.
I: A finite stack alphabet.
o: The transition function with input:
q
i
is a state in Q.
a is a symbol in E or a = c (the empty string).
t
m
is a stack symbol, t
m
e I.
and the output is a finite set of pairs:
q
k
the new state.
t
n
is the string of stack symbols that replaces t
m
at the top of the stack.
If t
n
= c, then the stack is popped.
q
0
: The start state.
t
0
: Initially, the PDAs stack consists this symbol and nothing else.
F : The set of accepting states.
PDA Example:

} 1) (0 | {
*
+ e = w ww L
R
wwr
The language, L
wwr
, is the even-length
palindromes over alphabet {0,1}.

L
wwr
is a Context-Free Language (CFL)
generated by the grammar:
c | 1 1 | 0 0 S S S
One PDA for L
wwr
is given on the following
slide...
PDA for L
wwr
) 1 , ( ) , 1 , ( ) 0 , ( ) , 0 , ( ) 1
0 0 0 0 0 0 0 0
t t o t t o q q q q
) 11 , ( ) 1 , 1 , ( ) 10 , ( ) 0 , 1 , (
) 01 , ( ) 1 , 0 , ( ) 00 , ( ) 0 , 0 , ( ) 2
0 0 0 0
0 0 0 0
q q q q
q q q q


o o
o o
) 1 , ( ) 1 , , ( ) 0 , ( ) 0 , , ( ) , ( ) , , ( ) 3
1 0 1 0 0 1 0 0
q q q q q q c o c o t t c o
) , ( ) 1 , 1 , ( ) , ( ) 0 , 0 , ( ) 4
1 1 1 1
c o c o q q q q
) , ( ) , , ( ) 5
0 2 0 1
t t c o q q
) , ( ) , ut End_Of_Inp Read_Past_ , ( ) 6
0 3 0 2
t t o q q
} { } , 1 , 0 { } 1 , 0 { } , , , {
3 0 3 2 1 0
q F q q q q Q = = I = E = t
( ) F q Q P , , , , , ,
0 0
t o I E =
= o
A Graphical Notation for PDAs
1. The nodes correspond to the states of the PDA.
2. An arrow labeled Start indicates the unique start
state.
3. Doubly circled states are accepting states.
4. Edges correspond to transitions in the PDA as
follows:
5. An edge labeled (a
i
, t
m
)/t
n
from state q to state p
means that o(q, a
i
, t
m
) contains the pair (p, t
n
),
perhaps among other pairs.
Graphical Notation for PDA of L
wwr
q
0
q
1
q
2
q
3
start
(, t
0
) / t
0
(, 0) / 0
(, 1) / 1

(0,0)/
(1,1)/
(,t
0
) / t
0
(EOF,t
0
) / t
0
All possibilities that do not have explicit
edges, have implicit edges that go to an
implicit reject state.
This is a nondeterministic machine.
Think of the machine as following all possible paths.
Kill a path if it leads to a reject state.
If any path leads to an accept state, then the machine accepts.
(0, 0)/00
(0, 1)/01
(1, 0)/10
(1, 1)/11

(0, t
0
)/0t
0
(1, t
0
)/1t
0

Exercise 1
Design a PDA that recognizes legal sequences
of if and else statements in a C program.

In the PDA, let i stands for if and e stands for
else.

Hint: There is a problem whenever the number
of else statements in any prefix exceeds the
number of if statements in that prefix.

Exercise 2
Design a PDA to accept the language:

} or | { k j j i c b a
k j i
= =

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy