Lec 17 Pda CFG
Lec 17 Pda CFG
IITB, India
cbna CS310 : Automata Theory 2019 Instructor: Ashutosh Gupta IITB, India 1
Recognizing “by empty stack” to “by final state”
Theorem 17.1
Let P = (Q, Σ, Γ, δ, q0 , Z0 , F ) be a PDA. There is a PDA P 0 such that
L(P 0 ) = L (P).
Proof. Let us construct the following PDA
P 0 = (Q ∪ {p0 , pf }, Σ, Γ ∪ {X0 }, δ 0 ∪ δ, p0 , X0 , {pf })
I new initial state p0 , accepting state pf , and initial stack symbol X0
I Extra transitions δ 0 are defined as follows
(
0 {(q0 , Z0 X0 )} q = p0
δ (q, , X0 ) ,
{(pf , )} q∈Q
, X0 /
, X0 /Z0 X0
start p0 q0 P , X0 / pf
cbna CS310 : Automata Theory 2019 Instructor: Ashutosh Gupta IITB, India 2
Recognizing “by empty stack” to “by final state” II
Proof(contd.).
claim: L (P) ⊆ L(P 0 )
Let us assume w ∈ L (P), i.e., w is accepting by P by empty stack.
Only the last transition can pop X0 and no old transitions of P can push or
pop X0 .
(p0 , w , X0 ) `0 (q0 , w , Z0 X0 ) `∗0 (q, , X0 ) `0 (pf , , )
P P P
| {z }
X0 is always on stack
P = ({q0 }, {0 (0 ,0 )0 }, {Z }, δ, q0 , Z , {})
0 (0 , Z /ZZ
, X0 /Z X0 , X0 /
start p0 q0 pf
0 )0 , Z /
P 0 = ({q0 , p0 , pf }, {0 (0 ,0 )0 }, {Z , X0 }, δ 0 ∪ δ, p0 , X0 , {})
, any /
, X0 /Z0 X0
start p0 q0 P , any / p
, any /
cbna CS310 : Automata Theory 2019 Instructor: Ashutosh Gupta IITB, India 6
Recognizing “by final state” to “by empty stack” II
Proof(contd.).
claim: L(P) ⊆ L (P 0 )
Let us assume w ∈ L(P), i.e., w is accepting by P by final state.
Proof(contd.).
claim: L (P 0 ) ⊆ L(P)
Let us assume w ∈ L (P 0 ), i.e., w is accepting by P by empty stack.
Since the P transitions cannot pop X0 , the empty stack is reached only at p.
Therefore, (p0 , w , X0 ) `∗0 (p, , ).
P
cbna CS310 : Automata Theory 2019 Instructor: Ashutosh Gupta IITB, India 8
Topic 17.1
cbna CS310 : Automata Theory 2019 Instructor: Ashutosh Gupta IITB, India 9
CFGs and PDAs
We have defined
context-free grammars (CFGs) and pushdown automata (PDAs).
It is no coincidence that
cbna CS310 : Automata Theory 2019 Instructor: Ashutosh Gupta IITB, India 10
Topic 17.2
CFGs to PDAs
cbna CS310 : Automata Theory 2019 Instructor: Ashutosh Gupta IITB, India 11
CFGs to PDAs
Theorem 17.3
Let G = (N, T , P, S) be a CFG grammar. The PDA
Initial No final
Input symbols state state(why?)
A = ({q}, T , N ∪ T , δ, q, S, {})
Single state Stack symbols Start Stack
symbols
recognizes L(G ) by empty stack, where δ is defined as follows.
1. P → 0P0 3. P →
2. P → 1P1 4. P → 1
, P/1P1
, P/0P0
, P/1
start q
, P/
1, 1/
0, 0/
cbna CS310 : Automata Theory 2019 Instructor: Ashutosh Gupta IITB, India 13
Proof : CFGs to PDAs
Proof.
Let w ∈ L(G ).
(q, w , S) `∗ (q, yi , αi )
A
xi has been matched and
such that yi is to be matched by αi
I there is an xi such that w = xi yi and γi = xi αi and
I if αi 6= , then αi begins with nonterminal .
xi yi
αi
cbna CS310 : Automata Theory 2019 Instructor: Ashutosh Gupta IITB, India 14
Proof : CFGs to PDAs II
Proof(contd.)
base case:
For i = 1, γ1 = S. We have
induction step:
By induction hypothesis, (q, w , S) `∗ (q, yi , αi ) such that w = xi yi and
A
γi = x i αi .
cbna CS310 : Automata Theory 2019 Instructor: Ashutosh Gupta IITB, India 15
Proof : CFGs to PDAs III
Proof(contd.)
case αi = Aαi0 , where A ∈ N:
xi yi xi yi
A β
αi0 αi0
...
cbna CS310 : Automata Theory 2019 Instructor: Ashutosh Gupta IITB, India 16
Proof : CFGs to PDAs IV
Proof(contd.)
Two sub-cases
xi yi xi yi xi xi0 yi0
xi yi
β ∗ β ∗ A0
αi0 αi0 αi00
cbna CS310 : Automata Theory 2019 Instructor: Ashutosh Gupta IITB, India 17
Proof : CFGs to PDAs V
Proof(contd.)
Proving the other direction
cbna CS310 : Automata Theory 2019 Instructor: Ashutosh Gupta IITB, India 18
Proof : CFGs to PDAs VI
Proof(contd.)
base case:
n = 1.
We can finish the run in a single transition only if B → ∈ P. Therefore
induction step:
n>1
Let B → Y1 ...Yk ∈ P is used in the first transition of A, which pops B and
stack is filled with Y1 , ..., Yk without consuming anything.
x Y x
1
B ..
.
Yk
cbna CS310 : Automata Theory 2019 Instructor: Ashutosh Gupta IITB, India ...19
Proof : CFGs to PDAs VII
Proof(contd.)
x Y x x
1
.. ∗
B .
Yk
Proof(contd.)
Therefore, we have (q, xi , Yi ) `∗ (q, , ) in less than n steps.
A
∗
⇒ xi .
Due to induction hypothesis, Yi =
cbna CS310 : Automata Theory 2019 Instructor: Ashutosh Gupta IITB, India 21
End of Lecture 17
cbna CS310 : Automata Theory 2019 Instructor: Ashutosh Gupta IITB, India 22