Professional Documents
Culture Documents
Lecture-5 - Pushdown Automata
Lecture-5 - Pushdown Automata
Lecture-5 - Pushdown Automata
C OMPUTATION
P USHDOWN AUTOMATA
Input is read
left-to-right
Control has finite
memory (NFA)
State transition
depends on input
and top of stack
Control can push
and pop symbols
to/from the infinite
S LIDES FOR 15-453 L ECTURE
stack
9 F 2015
ALL 3 / 17
P USHDOWN AUTOMATA – I NFORMAL
, → $
start q1 q2 a, → 0
b, 0 →
q4 q3 b, 0 →
, $ →
, → $
start q1 q2 0, → 0
, →
q4 q3 0, 0 →
, $ →
1, 1 →
S LIDES FOR 15-453 L ECTURE 9 FALL 2015 10 / 17
E XAMPLE PDA
a, s → xyz represents ⇒ , → y
q2
r
, → x
r
S LIDES FOR 15-453 L ECTURE 9 FALL 2015 12 / 17
PDA S AND CFG S
T HEOREM
A language is context free if and only if some
pushdown automaton recognizes it.
L EMMA
If a language is context free, then some pushdown
automaton recognizes it.
P ROOF I DEA
If A is a CFL, then it has a CFG G for generating it.
Convert the CFG to an equivalent PDA.
Each rule maps to a transition.
start qstart
, → S$
, $ →
q2
P ROPERTIES OF CFL S
L EMMA
If a PDA recognizes some language, then it is context
free.
P ROOF I DEA
Create from P a CFG G that generates all strings that
P accepts, i.e., G generates a string if that string
takes PDA from the start state to some accepting
state.
C LAIM
If Apq generates x, then x can bring P from p with
empty stack to q with empty stack.
C LAIM
If Apq generates x, then x can bring P from p with
empty stack to q with empty stack.
C LAIM
If Apq generates x, then x can bring P from p with
empty stack to q with empty stack.
C LAIM
If Apq generates x, then x can bring P from p with
empty stack to q with empty stack.
C LAIM
If Apq generates x, then x can bring P from p with
empty stack to q with empty stack.
C LAIM
If Apq generates x, then x can bring P from p with
empty stack to q with empty stack.
C LAIM
If x can bring P from p to q with empty stack,
∗
Apq ⇒ x.
C LAIM
If x can bring P from p to q with empty stack,
∗
Apq ⇒ x.
C LAIM
If x can bring P from p to q with empty stack,
∗
Apq ⇒ x.
C LAIM
If x can bring P from p to q with empty stack,
∗
Apq ⇒ x.
C LAIM
If x can bring P from p to q with empty stack,
∗
Apq ⇒ x.
C LAIM
If x can bring P from p to q with empty stack,
∗
Apq ⇒ x.
C OROLLARY
Every regular language is context free.
C OROLLARY
Every regular language is context free.
P ROOF .
Since a regular language L is recognized by a DFA
and every DFA is a PDA that ignores it stack, there is
a CFG for L
C OROLLARY
Every regular language is context free.
P ROOF .
Since a regular language L is recognized by a DFA
and every DFA is a PDA that ignores it stack, there is
a CFG for L
Right-linear grammars
Left-linear grammars
We divide s
into uvxyz
according to
this figure.
Upper R generates
vxy while the lower R
generates x.
We divide s
into uvxyz
according to
this figure.
Upper R generates
vxy while the lower R
generates x.
Since the same
variable generates
We divide s
both subtrees, they are
into uvxyz
interchangeable!
according to
this figure.
Upper R generates
vxy while the lower R
generates x.
Since the same
variable generates
We divide s
both subtrees, they are
into uvxyz
interchangeable!
according to
So all strings of the
this figure.
form uv i xy i z should
also be in the
language for i ≥ 0.
S LIDES FOR 15-453 L ECTURE 10 FALL 2015 28 / 29
P ROOF – H OW TO C HOOSE A S TRING
P ROPERTIES OF CFL S
L EMMA
If L is a CFL, then there is a number p (the pumping
length) such that if s is any string in L of length at
least p, then s can be divided into 5 pieces s = uvxyz
satisfying the conditions:
1 |vy | > 0
2 |vxy | ≤ p
3 for each i ≥ 0, uv i xy i z ∈ L
u vxy z
| · {z
Only b’s: a · · ab} b
| ·{z
· · b} b
| · · · bc
{z · · · c}
2
u vxy z
3 Only c’s: |a · · · ab
{z· · · bc} c
| ·{z
· · c} c
| ·{z
· · c}
u vxy z
u vxy z
| · · · ab
Only b’s and cs: a {z · · · b} b
| ·{z
· · c} c
| ·{z
· · c}
2
u vxy z
S → aA | bA | a | b S → AB | BA
A → aS | bS A → ZAZ | a
generates L1 B → ZBZ | b
Z →a|b
generates L2
S LIDES FOR 15-453 L ECTURE 11 FALL 2015 14 / 16
CFL C LOSURE P ROPERTIES IN ACTION