A pushdown automaton (PDA) is a nondeterministic finite automaton that uses a stack to process input symbols. It has a finite set of states, input symbols, stack symbols, and transition rules that can push symbols onto or pop symbols off the stack. The transition function defines the state and stack changes for each input symbol. A PDA accepts a language if any path through its transitions leads to an accepting state.
2. Pushdown Automaton (PDA)
F
q
q
a
q
Q
P n
k
m
i ,
,
,
),...
,
(
)
,
,
(
,
,
, 0
0
Q: A finite set of states.
: A finite set of input symbols.
: A finite stack alphabet.
: The transition function with input:
qi is a state in Q.
a is a symbol in or a = e (the empty string).
m is a stack symbol, m .
and the output is a finite set of pairs:
qk the new state.
n is the string of stack symbols that replaces m at the top of the stack.
If n = e, then the stack is popped.
q0: The start state.
0 : Initially, the PDA’s stack consists this symbol and nothing else.
F : The set of accepting states.
3. PDA Example: }
1)
(0
|
{ *
w
ww
L R
wwr
The language, Lwwr, is the even-length
palindromes over alphabet {0,1}.
Lwwr is a Context-Free Language (CFL)
generated by the grammar:
e
|
1
1
|
0
0 S
S
S
One PDA for Lwwr is given on the following
slide...
5. A Graphical Notation for PDA’s
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 (ai, m)/n from state q to state p
means that (q, ai, m) contains the pair (p, n),
perhaps among other pairs.
6. Graphical Notation for PDA of Lwwr
q0 q1
q2
q3
start
(ε, 0) / 0
(ε, 0) / 0
(ε, 1) / 1
(0,0)/ε
(1,1)/ε
(ε,0) / 0
(EOF,0) / 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, 0)/00
(1, 0)/10
7. 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.
8. Exercise 2
Design a PDA to accept the language:
}
or
|
{ k
j
j
i
c
b
a k
j
i