1 / 10

PDA to CFG

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, Λ )}.

gunnar
Download Presentation

PDA to CFG

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. PDA to CFG ToqaManasrah

  2. 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

  3. Step 1 Initial production S for each variable S [q0z0q] S [q0z0p] Variables: q,p

  4. (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

  5. Step 2 • Pop x, consume Λ Λtransition 5. δ (qΛx) = {( q , Λ )} [ qxq]  Λ 6. δ( p , 1 , x) = {( p, Λ)} [ pxp]  1 • Pop x, consume 1

  6. 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

  7. 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

  8. 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]

  9. 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]

  10. 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

More Related