PDA example

Report
PDA to CFG
Toqa Manasrah
Example
• Convert the PDA P={{p,q}, {0,1}, {X,Z}, q, Z, { }, δ}
to a CFG if δ is given by:
States Q:
q,p
Stack
symbols:
x,z
inputs: 0,1
1. δ(q,1,Z)={(q,XZ)}
2. δ(q,1,X)={(q,XX)}
3. δ(q,0,X)={(q,X)}
4. δ(p,0,Z)={(q,Z)}
5. δ(q,Λ,X)={(q, Λ)}
6. δ(p,1,X)={(p, Λ)}
2 stack symbols
1 stack symbols
0 stack symbols
Each
stack
symbol
 one
path
Step 1
Initial production S for each variable
S [q0z0q]
S [q0z0p]
Variables:
q,p
(q,a,Z) = (p,X)
q
a, Z  X
q
a, Z  X
p

consume a
pop Z
push X
move to state p
X not yet processed
consume a
pop Z
push X
move to state p
p
?
process
X
Since we don’t know which state
the PDA will be in after
processing X, define a
production [qZr]  a[pXr] that
ends in each possible state r
Step 2
Λ transition
Pop x,
consume Λ
5. δ (q Λ x ) = {( q , Λ )}
Pop x,
[q x q]Λ
consume 1
6. δ( p , 1 , x ) = {( p, Λ )}
[ p x p] 1
Step 3
Regular transition
Pop x,
consume
0, push x
3. δ(q,0,X)={(q,X)}
[ q x r ]0[ p x r ]
[ q x q ]0[ p x q ]
[ q x p ]0[ p x p ]
r = all
states in Q
Step 3
Regular transition
4. δ(p,0,Z)={(q,Z)}
[ p z r ]0[ q z r ]
[ p z q ]0[ q z q ]
[ p z p ]0[ q z p ]
r = p or
r=q
Pop z, consume 1, move to
state q, push x, mover to k,
push z, move to r
Step 3
Regular transition
1. δ(q,1,Z)={(q,XZ)}
[qzr]1[qxk][kzr]
[qzq]1[qxq][qzq]
[qzq]1[qxp][pzq]
[qzp]1[qxq][qzp]
[qzp]1[qxp][pzp]
[qzq]1[qxk][kzq]
[qzp]1[qxk][kzp]
Step 3
Regular transition
1. δ(q,1,X)={(q,XX)}
[qxr]1[qxk][kxr]
[qxq]1[qxq][qxq]
[qxq]1[qxp][pxq]
[qxp]1[qxq][qxp]
[qxp]1[qxp][pxp]
[qzq]1[qxk][kxq]
[qzp]1[qxk][kxp]
S [q0z0q]
S [q0z0p]
[qzq]1[qxq][qzq]
[qzq]1[qxp][pzq]
[qzp]1[qxq][qzp]
[qzp]1[qxp][pzp]
[qxq]1[qxq][qxq]
[qxq]1[qxp][pxq]
[qxp]1[qxq][qxp]
[qxp]1[qxp][pxp]
[ q x q ]0[ p x q ]
[ q x p ]0[ p x p ]
[ p z q ]0[ q z q ]
[ p z p ]0[ q z p ]
[q x q]Λ
[ p x p] 1

similar documents