Pushdown Automata: Recognizing Context-Free Languages
Pushdown Automata: Recognizing Context-Free Languages
a + b * c
Just Recognizing
The insight: Precisely what it needs is a stack, which gives it an unlimited amount of memory with a restricted structure.
( ( ( ( ( ) ) ) ) ( ) ( ( ) )
( Finite
( State
( Controller
(
( (
(K × (Σ ∪ {ε}) × Γ* ) × ( K × Γ* )
[//[
s
]/[/
Important:
This does not mean that the stack is empty.
An Example of Accepting
[//[
s
]/[/
∆ contains:
[1] ((s, [, ε), (s, [ ))
[2] ((s, ], [ ), (s, ε))
input = [ [ [ ] [ ] ] ]
An Example of Rejecting
[//[
s
]/[/
∆ contains:
[1] ((s, [, ε), (s, [ ))
[2] ((s, ], [ ), (s, ε))
input = [ [ ] ] ]
First we notice:
• We'll use the stack to count the a's.
• This time, all strings in L have two regions. So we need two states so that a's can't follow b's. Note the similarity to the
regular language a*b*.
a//a a/a/
c//
s f
b//b b/b/
a//a a/a/
c//
s f
b//b b/b/
∆ contains:
[1] ((s, a, ε), (s, a))
[2] ((s, b, ε), (s, b))
[3] ((s, c, ε), (f, ε))
[4] ((f, a, a), (f, ε))
[5] ((f, b, b), (f, ε))
input = b a c a b
trans state unread input stack
s bacab ε
2 s acab b
1 s cab ab
3 f ab ab
5 f b b
6 f ε ε
a//a a/a/
ε//
s f
b//b b/b/
a//a a/a/
ε//
s f
b//b b/b/
[1] ((s, a, ε), (s, a)) [4] ((f, a, a), (f, ε))
[2] ((s, b, ε), (s, b)) [5] ((f, b, b), (f, ε))
[3] ((s, ε, ε), (f, ε))
input: a a b b a a
a//a b/a/
b/a/ b/ε/
1 2
b/ε/
Accepting Mismatches
L = {ambn m ≠ n; m, n >0}
a//a b/a/
b/a/
1 2
b//
4 b//
A PDA is deterministic if, for each input and state, there is at most one possible transition. Determinism implies uniquely
defined machine behavior.
b//
4 b//
b/Z/
4 b//
ε//Z a//a
S S' machine for N
a// b,c
S→A
S→B
A→ε
A → aAb
B→ε
B → bBa
A DPDA for L:
More on PDAs
Example: Accept by final state at end of string (i.e., we don't care about the stack being empty)
We can easily convert from one of our machines to one of these:
1. Add a new state at the beginning that pushes # onto the stack.
2. Add a new final state and a transition to it that can be taken if the input string is empty and the top of the stack is #.
Converting the balanced parentheses machine:
But what we really want to do with languages like this is to extract structure.