A Finite Automton A Pushdown Automton 0000 000 red unred b b pop red unred push 2 An Exmple A Pushdown Automton Recll tht 0 n n not regulr. cn push symbols onto the stck cn pop them (red them bck) lter stck is potentilly unbounded Consider the following PDA: red input symbols for ech 0, push it on the stck s soon s is seen, pop 0 for ech red ccept if stck empty when lst symbol red. reject if stck non-empty, if input symbol exist, if 0 red fter, etc. 3 4
Forml Denition Non-Determinism PDA my be non-deterministic. PDA must be non-deterministic. Unlike nite utomt, non-determinism dds power. Use dierent lphbet for inputs nd for stck ;. rnsition function looks dierent. From: current stte: Q next input, if ny: " stck symbol symbol popped, if ny: ; " o: new stte: Q stck symbol pushed, if ny: ; " non-determinism: P() : Q " ; "!P(Q ; " ) 5 6 Forml Denitions Conventions A pushdown utomton (PDA) is 6-tuple (Q ; 0 F), where Q is nite set clled the sttes, is nite set clled the input lphbet, ; is nite set clled the stck lphbet, : Q " ; "!P(Q) is the trnsition function, 0 2 Q is the strt stte, nd F Q is the set of ccept sttes. Question: When is the stck empty? strt by pushing $ onto stck if you see it gin, stck is empty. When is input string exhusted? doesn't mtter ccepting stte ccepts only if inputs exhusted! 7 8
Exmple Nottion rnsition he PDA $ 2 0, $ mens red from input pop b from stck push c onto stck b! c Mening of " trnsitions: if = ", don't red inputs if b = ", don't pop ny symbols if c = ", don't push ny symbols ccepts 4,0,$ 3,0 f0 n n jn g : 9 0 Another Exmple Another Exmple A PDA tht ccepts n o i b j c k ji j k > 0 nd i = j or i = k Informlly: red nd push 's either pop nd mtch with b's or else pop nd mtch with c's non-deterministic choice! Note: non-determinism essentil here! $ b, c,,$ 3 4 2 5 0 7, b, c, A PDA tht ccepts n o i b j c k ji j k > 0 nd i = j or i = k Unlike nite utomt, non-determinism dds power 2
Yet Another Exmple Yet Another Exmple his PDA $ 2 0, 0, A plindrome hs the form ww R. \Mdm I'm Adm" \Dennis nd Edn sinned" \Red rum, sir, is murder" \In girum imus nocte et consumimur igni" 4, $ 3 0,0, ccepts binry plindromes. 3 4 If Prt heorem heorem: A lnguge is context free if nd only if some pushdown utomton ccepts it. his time, both the \if" prt nd the \only if" prt re interesting. heorem: If lnguge is context free, then some pushdown utomton ccepts it. Let A be context-free lnguge. We know A hs context-free grmmr G. on input w, the PDA P gures out if there is derivtion of w using G. Question: How does P gure out which substitution to mke? Answer: It guesses. 5 6
Where do we keep the intermedite string? Informlly: P pushes strt vrible S on stck keeps mking substitutions when only terminls remin... tests whether derived string euls input red 000 unred A A 0 $ pop push intermedite string: 0AA0 cn't put it ll on the stck only symbols strting with rst vrible on stck 7 8 Need shorthnd to push entire string onto stck. Informl description: push S$ on stck if top of stck is vrible A, non-deterministiclly select rule nd substitute. if top of stck is terminl red next input nd compre. If they dier, reject. if top of stck is $, enter ccept stte. (Relly ccepts only if input hs ll been red!). (r w) 2 ( s) Esy to do by introducing intermedite sttes.,s z,s xyz r r x y 9 20
rnsition Function Initilize stck ( " ")=f` S$g op of stck is vrible (` " A)=f(` w)j where A! w is rule g Sttes of P re strt stte ccept stte loop stte ` E sttes needed for shorthnd op of stck is terminl (` )=f(` ")g End of Stck (` " $) = f( ")g 2 22 rnsition Function Exmple S$ S! bjb! j" l,a, w Initiliztion: S$,$ l 23 24
Exmple Exmple S! bjb! j" S! bjb! j" Rules for S Rules for S$ S$ l, l, 25 26 Exmple Exmple S! bjb! j" S! bjb! j" Rules for terminls ermintion: S$, l bb, S$, bb l, $, 27 28