100 likes | 469 Views
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 : 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, Λ )}.
E N D
PDA to CFG ToqaManasrah
Example • Convert the PDA P={{p,q}, {0,1}, {X,Z}, q, Z, { }, δ} to a CFG if δis given by: 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, Λ)} States Q: q,p Each stack symbol one path 2 stack symbols 1 stack symbols Stack symbols: x,z 0 stack symbols inputs: 0,1
Step 1 Initial production S for each variable S [q0z0q] S [q0z0p] Variables: q,p
(q,a,Z) = (p,X) consume a pop Z push X move to state p q q a, Z X a, Z X p 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 processingX, define aproduction [qZr] a[pXr]that ends in each possible state r Xnot yet processed
Step 2 • Pop x, consume Λ Λtransition 5. δ (qΛx) = {( q , Λ )} [ qxq] Λ 6. δ( p , 1 , x) = {( p, Λ)} [ pxp] 1 • Pop x, consume 1
Step 3 Regular transition 3. δ(q,0,X)={(q,X)} [ qxr ]0[ p xr] [ qxq ]0[ p xq] [ qxp ]0[ p xp ] Pop x, consume 0, push x 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] [ q x q ]0[ p x q ] [ q x p ]0[ p x p ] [qzq]1[qxq][qzq] [qzq]1[qxp][pzq] [qzp]1[qxq][qzp] [qzp]1[qxp][pzp] [ p z q ]0[ q z q ] [ p z p ]0[ q z p ] [qxq]1[qxq][qxq] [qxq]1[qxp][pxq] [qxp]1[qxq][qxp] [qxp]1[qxp][pxp] [ q x q ] Λ [ p x p ] 1