0% found this document useful (0 votes)
47 views31 pages

Flat Unit-4

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
47 views31 pages

Flat Unit-4

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 31
J Tie concept PushDown Automata (PDAs) is useful in designing parsers o syntax analysers. A parser verifies the syntax of the text. Parsing is a part of the compila- | ion process. So, knowledge of PDAs is useful in compiler design In this chapter, we introduce PushDown Automata (PDAs) and discuss how the language ie accepted, Theorems that show the equivalence of PDA and context free languages are iseussed. Equivalence of PDA that accepts language using empty stack and reaching to final state is explained. Finally, how to use PDA as a parser is described “The automata that we have discussed so far-haye very limited memory capabilities. It cannot recognize all CFLs. We understand that this is because Finite Automata have strictly finite memories; whereas recognition of a CFL r of information. For example, scanning a string from the langui not only check that all a's precede the first b, but ‘umber of DS. Since n is unbounded, this counting cannot be done with a finite memory. The difficulty can be avoided by adding an auxiliary memory in the form of a stack. All he aXare read and added to a stack, This is how they are remembered. When b’s are read ay require storing an unbounded amount }. We must Iso match the number of a’s with the atch the number of a's with the number of b's by taking out an a from the stack for each ‘b This is how we can strengthen the power of automaton, by adding a st We will now consider a new notion of automata, PDAs. PDAs are finite automatons a with a stack, ic, a data structure that can be used to store an arbitrary number of symbols (and hence PDAs have an infinite set of states) but that can be accessed only in a last-in= first-out (LIFO) fashion. The languages that can be recognized by PDA are precisely the free lan k structure: conte, ages. 5.1 Pushdown Automata As Figure 5.1 indicates, a PDA consists of three components; 1) An input tape, 2) a finite contra! and 3) a stack structure. The input tape consists of a linear configuration of cells ach of which contains a character from the input alphabet, This tape can be moved one cell atatimetothe left. The stack is also a sequential structure that has a first element and grows in either direction from the other end. The control unit has some pointer (head) which points the current symbol that is to be read. The head positioned over the current stack clement can read and write special stack characters from that position. The current stack clement is always the top clement of the stack; hence, the name ‘stack’. The control unit contains both tape head and stack head and finds itself at any moment in a particular state. al Languages and Automata Theory eT a pe Fig.5.1 Conceptual Mode! of a Pushdown Automation 202 | Forme Definition T: A finite state pushdown automation is a T-tuple M= (Q, Z, 8, & 4,» Z, F) where Qe a finite set of states Ya finite set of input alphabet Ta finite set of stack alphabet gy the start state. qg€ Q In words, ates con om the stack QX (Zu fe) xX) > QXxT* es Z, is the inital stack symbol. Z, € input sym PDA has? alphabets: empty, th explicitly #) An input alphabet 5: (for input strings) us b) A stack alphabet I'(stored on the stack) state and A move on PDA may indicate: i) An element may be added to the stack 5.1.2 | ii) An clement may be deleted from the stack: Dur (8.2) =(a.0)and any give iii) There may or may not be change of state content of Ea oe 2. xis 9 Baa, Z,)= (4g, aZ,) indicates that in the state q on seeing a, a is pushed onto stack ger There is no change of state, nd 3) 8G, a, Z,)= (4, €) indicates that in the state ' in the state q on seeing a, the current top is deleted from the stack. + ae el 41) 8(4, 42.) =(q, aZ,) indicates that ais pushed onto the stack and the state is changed to 4, aS shown t “ (a, ab. | 5.1.1 Graphical Representation of PDA TAM=(Q 5, 7,5, q,,2,, F) be a PD, e 2, %,8,4,,7,, PDA where Q = {p,q}, = FIP}, and 5is given by the lowing esuatiog ont z imc Atthis aq, 2=((q,a)} the origing Z,F)wh ned onto stack. t top symbol Z,, is changed to q, {a,b},q=4 ut ne Push Down Automata | 203 (a,b, 8) {.b)) HHEO=((re} + 8p, 9) = ftp, €) 3p.b.b)= (po! Ibis very hard to visualize what M does, Th r 5g, a,b) = (4,0) Fig. 5.20 Jn words, M works as follows: It stays in state q pushing input symbols ‘a’ and *b’ onto the stack (irrespective of what is at the top of the stack) until it encounters a“. Then it fnoves to state p, in which it repeatedly pops a and b symbols off the stack provided the jnput symbol is identical to that on top ofthe stack, Ifat the end ofthe string, the stack is capty, then the machine accepts. However, notice that failure in processing a string is not explicitly represented, For example, what happens ifthe input string has no e i i In that eae, M will never leave state 4, Once the input is finished, we find that we are nat in2 final state and so cannot accept the string. 5.1.2 Instantaneous Description of PDA During processing, the PDA moyes from one configuration to another configuration. At any given instance, the configuration of PDA is expressed by the state of finite conto the coment of stack and the input. The configuration is expressed as a triple (q,% 7), where 1. gis the state y 2. xis the input string to be processed. 3. zs the content of the stack where the leftmost and the rightmost isthe bottom element symbol corresponds to top of stack, synen string ababeby is processed, the instantarieous deseapuon Is shown below. (q,ababcbab, 2) = (4, babebab, a) = (4 abedab, ba) = a. bebab, aba) = (4, cbab, Hbaba) =? (p, bab, baba) = (P, ab, abs) = (p,b ba) = (P84) usted and the computation stops. We cannot accept Atthis input string is exhat ea, the ior pt state because the stack is not empty the original string although we are in an “accel 204 | Formal Languages and Automata Theory 9 }this example used c as a marker telling the jwew*|we {ab} : at such an expe ‘states, 1eturns out thi Jient is not needed because Thus we see that L(M) machine when to change sve have non-leterminism at our disposal 5.1.3 Language Acceptance by PDA A tanguage can be accepted by a PDA using (0 approaches: state: The PDA accepis its input by consuming itand finally J. Acceptance by enters the final state > Acceptance by empty stack: On reading the input string from the initial configura: tion for some PDA, the stack of PDA becomes empty FETED owscvs a sonar age = n= Solution: PDA can be constructed as follows: [Let g, be intial state, , final state and Z, bottom of tl ‘onto the stack. Then read each b and pop out from stack Joi are read ifthe stack is empty, then string is valid. [fany a's are ‘on inputfggpe then the string is rejected. Suppose the input is aaabbb, The steps involved are shown in Figure 5.3. The PDA moves are the following: the stack, Read each ‘a’ and push it 4 for matching with a's. When all left over on stack or b's Bq 2.Z,)=(a,aZ,) pusha Bq. a2)=(q,28) pasha 5 8iq..b.)=(G,,2) pop aand change the sate &q..b.2)=(q,.e) Popa &{g,,€.Z,)=(G,Z,) change to final state q, and halt ‘The moves of PDA can be shown as transition diagram: as in Figure 5.3. Fite contrt % Stop 2:ais pushed ; LJ fel > [> ye t = =e 5 ; [oe : laepsrew panned zm “ne POA for Example 5.3 IP fp fe ao - Finite Step 4: ls pushed Let us sligh Solution: The Ee To desen 2 Mette next Sirs op reid fe The PDA cs Push Down Automata | 205 ling the because - bye | falaja|o]o |o|e pena sealers Saar [a 4 Z change tonew state [2] Stop 6:popa finally it L EEE figura: - ‘Step 7:pop a 2, © Step 8: change to final state and halt d push it ames When all = ba ck orbs ee of \ 2S +f 9, — >{ aj} Yoo wy 4 he a) Fig.53 Continued a ahaa oe ame Design a PDA which accepts equal number of a and bS over ¥ = {a,b} i Solution: The input can start with eithera or b, and they can occur in any order, as bbaaba tr baba orbabbaa and soon ae al valid in the langage To design such a PDA, read the first symbol cither a or b push it on ‘the stack. Then: read the nent symbol Ifthe next symbol and tp of stack are same, push onto the tack Whenever top of stack and tape symbol are different, pop off the stack, When entire tape is. =e rea ifthe stack becomes emp, then strings accepted The PDA can be piven as follows * oe le [a |e ajo ]> [> j*[@ [5 Trias | _ prt rt » [8 ZV step tia comiguation [Zs] Step 221s pushew ap PPP la | pprPrre ao | rmiconeer) sont = [rng [Eb ceiere Bali WRG ra Swish * z MB 0q ue Vad YL, indus uoyAy 1, 989 oes 241 wo) yo dod ey IY y>eIS oH by om ‘OIDH -wopmas: : CT i 9q osyp ue Vad 20) = (73 bq GM%)= (0:9 %)9 %)= (4:2) (49%) = (4°49 (20%) = (2 jp C29) = ("24% (70°) = (72% p vad dues gy wee age saia'q eee “ria az" . ps oma on lu, umoys st pue yoeas owp Jo won0g oyp 247 pue ays jeu aq b ‘ms jan 34° 1 Wey pue ares teus 0} obueIp ders f= dod: das, 2 veel a Eel een a resues awa [3 yoquos onus =| qusnd:s dais b reauoo aw pais @%b)=(0'1 “be (ob) = 1 (0%) =(0'0 (70%)=CZ0"R faq pur aves yeuy 99/0 tri 99 % sons 3 3010104 ‘Wd 10} WUD MOLY JO al eam = = —{owna | Coie a an Ve Eto dues 99 “BIS ridtg ul UNOYS 1zEY9 woY Se *WONB 29 te Vd AHL sy 4 orp da sousonag 3oes 2 31 sIe}tduioo peas st mduy aHAN «LH Manas syn anuiuos 01 ayes nul 7 asap 302 pus Yow am wad BO St fy aBueyo pur ,1, 240 peas Ey) JUV “FOUTS 3H wou on ancy am “239 sMONMIOS: Leg pur 9's som nyss20ons pun $8990 NON “| puoDds PRO YOU “TPIS 1UOH2B|P tuo a1 ysnd pue §9 24) Pee “OS SI O44 HEM 0, {1 2) Fier uae (ee eno gf rohlreeeett Sanit aN a Y ype yee st oI * nea sen wonod “Te \ pee ayes voloy CBT) —_ateig danny ade85) 2693 BuyoauU00, . Jequuts vers (PRIS aundiy ut poureydya sjoquiss roads 5° omfg ur paumida sjoquucs iproads Sussn uous 9g oste wea Vd oz | eeworny unoa ysnd ‘ur wnoys St Pur wey pue axes 2°) = 073 59 1 Vc teu 24) one 2%) = (49 "VQ (4%) = (4°49 24%) =z q “be 02%) = 073%, C2") = 070 2y)9 (2%) = 07 0'by9 2") = (7-0 DQ 99 awe 1) eH Hoy B¢-By S Or Cas) 165 pur 9's somdiy wunoys spe ors antig oo fp pn, 8 289 ap ol ORD wen jut 39° 309 ur yonisayp onus 8 Pras un feu peas IPS. 9 uno Vid 2 (oz¥ aqe)=19tmoren yaar aia CERT einen Pu 3 Joquucs a suas ou a 6'¢ alduexq Jo) yod 1S "Bt W/o a C > 179 )Q | fo") = 01K Aooauy ereworny pue sabenGueyiewios | 90% 1D) 92 97 40) (0°40) (bb by Wg U9913 51 ¥aa uy ayy 2s axdwergs0) vag os -61g (2%)=(7:3"bg @'b)=(4'q "be Gb) =(@ be (a “b)=(q 2 b)g "by "be CZ") = 079 "bg. (49°) =(a'4 "big (4 %)=(e'4 “be 029%) = C7" “dy (ae) = by (28%) = (2 Tby9 (re 2-20 ors amy UW umoys se yes 24p Jo tHonog a4) >1°7 pu ayes feuy 2q7 ‘ores pentUL 99 % 191 ‘Smojo} Se Udi 24 ueD Va a4, paidaooe sy Buuns uow) ida Sounoaag yas so4dit09 peas sp nduy uougy joquiss own jo dod "ypevs aq) Jo doy a4p gua soyoreut ij “Joquuss o oro peos“ewp 4ay'y “> Siaxunonu 1 Un Yes ayy ONO 1! yshd pue m Buns on Peay G48) 29).0n)=r9koe ous vaaeioa EEE 5 der 10) Vos 6°58 2s 1 98ueyp pure, ys AE PES OM OWWO Sq Te p ae 2 ax een ea (3 —( 7 ef aN we N t aR zize “2hz'e 2/2" Cn \ \ (2 fv 6oz | eeWoIMY.UMEG YSN push Down autata | 211 tate QU laa) Fata. @ al state, then L A a, inital state Es 4, sL(N (My pis the strings by eng initial stack symbol is dened ns follows fl Blane Z)= (0.22) 4 Site the moves of M, on (4.4 X) =B (a0, 0) Forall ge (Q)).a€ and Xe f aif M emptcs the stack conten), here woul be Z,on the stack. Now move fo I state 84. Z,) =(Qu. 6 Z)- For all ge Q, To show x L(M)), (4% 2) (4) %Z,Z) 3 G62) 2 ZI he strings. 5.3 Types of PDAS 5.3.1 Deterministic PDA A PDA that has at most one choice of move in ny state i called a deterministic PDA. Non: eterministic PDA (NPDA) provides non-determinism in the moves defined. Deterministic move to 4, state, which PbAs (DPDAs) are very useful in programming languages. For example, parsers used in Yet Another Compiler Compiler (YACC) are deterministic PDA's (DPDA). Definition 2: \ PDA P= (Q.3, 4 1. 8(q,, X) has at most one move forqe Q.ac Dut dy Zn» F) 8 doterministic if and only it vand XE ) must be empty. > 1f8(g, , X) isnot empty for some ae E. then 84, &.% PDA ig es powerful than NPDA. The context free languages could be recognized by NPDAS Deterministic Context Free Language (DCFL) Mee faneumges accepted by DPDA isin botween tht of regular languages and empty stack, then Lis Fa eae sealed deterministic cones fee language (DCF) and isasub- cof languages accepted by NPDA, NPDA canbe consructe for accepting lanes of palindromes, but not by DPDA rie apna of programming languages canbe desribd by DCFLs. Compiler writing system eauies a etrited form of context ce grammar sls known as DCFG; LR gr mars are restricted grammars that enerate DCTL. Trac caetl ir te compiler designer to find out whether the given grammar is suitable we need to find for deni the oynan of the language, To find whether the language is a CFL, we ean e aoe thie penpang temma; bu his pumping Temma cannot be used to find whether the @e8) the strings by empty- a aia. | Formal Languages and Autom Te y rage is DCFL or not, we can use the clos - idemiy whether the language SDCFL- OF i grammars DCFL: Tope na closed on all properties 28 CTL properties of DCFL as they are DPDAS. e have discussed 80 fat ‘Note: Most of the examples we have disc 5.3.2 Closure Properties of DCFL DCP are closed under Union 2 Coneatenation & Kleen’ closure & Complementation / Note: CFLs are not closed under complement, but DCFLs are closed. Hence, if the CFLis found o be closed under complement, then itis a DCFL Normal forms for DPDAs: Any PDA is said to deterministic if it satisfies the following properties 1) Whenever 6(q, a, X) is non-empty for some a in E, 6(g, €, X) is empty, and 2) Foreach qin Q,ain¥ v {e} and X in P, 6(4, a, X) contains at most one element The first rule prevents us from considering the next input. The second rule prevenis 1 to two different IDs for the same input symbol The DPDA can be represented in normal form by imposing the following. two lemmas ‘on transition to restrict the opertation: Lemma 1: Every DCFL is L(M) fora DPDA M= X)=(p, 7), then bf <2 This lemma would restrict pushing more than one symbol onto the stack. Lemma 2: Every DCFL is L{M) fora DPDA M = (Q, ¥, x, 8, qy,Z,, F) such that if (4% %)=(p, then Yis either € (pop operation), X (no stack ope ee clement) ), X (no stack operation) of YX (push of Q.3,4,8, 4. ZF) such that. sat! Bs so lemmas, the DPDAS would be in normal form where th stack operations performed ae to erase the i change of stale. a the top symbol or to push one symbol or ot! ion * also a DCR edit the case of gular languages, but wth some modifications Sa Rita ne a me ons, This is because in the cs¢ rates soantlent language is regia, we could intrchie= nal States such that if st : ies th he apa gM EW 18 accepted nL, then sre 1. The original DPDA ng lever moves beyond some poi Reasons: This could happen, on ae Me point on an input string w: in L. There are two diffie '5 possible or moves are defined with eon neu Mif it reache nove 8 are defined with e, whi « ifit reaches an ID where no ™ considering the next input, S which forces it to make infinite moves wit? Problem: In cither case, orig iF SDPPA 0 accept the complement languages seeePt AY input with w as 3 pre 'S defined by simply changing fin! ® non-final states, it the resulting DPD complete string, 2, After proces Reason: The D states after others. Problem: By inte guage, it would sti These difficult 1. The DPDA accepting o} 2. Modify the final state 0 tence x by | DPDA. Theorem 3: The Proof: Let M=( Let M’ =( a=) P= The purpose 0 accepting stat. I, and irres + 1k =2,M or 2, depen + Forqand - 1G, k=1or + 1 8(q, 3 ta, respecti We can show t Suppose a, 4, simulating this s ‘Therefore, M’ doy Suppose a, a E-moves to make aa Ne, ifthe Ch fies the alin mpty, and jostone elena cond ving 0 py sien it : stack ps of yo oe Push Down Automata | 213 non-final states, it would accept every string with prefix w without going beyond w, Hence, the resulting DPDA still would accept strings with w as prefix without processing the complete strin 2, After processing the sentence x, the DPDA may take several moves on e-input Reason: The DPDA may be in final states after some of these moves and in non-final states after others. Problem: By interchanging the final and non final states in DPDA for complement lan- guage, it would still accept ». These difficulties can be overcome by forcing 1. The DPDA to enter an ID only after processing the entire input. This takes care of pling or rejecting the input only after processing the complete input. 2. Modify the DPDA by adding the second component to the state to record whether a final state of the original DPDA is reached or not, This takes care of rejecting sen- tence x by DPDA constructed for complement language; it is accepted by original DPDA. Theorem 3: The complement of a DCFL is a DCF Proof: Let M=(Q, ©, 1, 8, qy Z,, F) be a DPDA satisfying the first condition. Let M’ =(Q’, 5, 1, 8',q/,, Z,, F)) be a DPDA simulating M where Q= {lak |g Qandk=1,20r3} F’= {[g, 3]|q¢ Q} and {o.1] if qyis in F [4.2] if pis not in F % ‘The purpose of k in [q, k] is to record, between true inputs, whether it has entered an accepting state + k=1=M has entered an accepting state since the last true input ok + M’simullates the move of M and changes k to 1 or 2 when M reads a true input, k = 1, and irrespective of the new state, whether itis final or non-final + Ifk =2, M’ first changes k to 3 and then simulates the move of M, (or, depending on whether the new state of M is oris notin F * Forg and p in Q and a in ~ 1F8(g,€, Z) =(p, 9) thon for k = 1 or 2, (4, kl, Z) Jor if pis in F; otherwise k’ = 2 ~ 18(a, a, Z) = (p, for a in E, then (a, 2h & Z) = (Ip. 3}, Z) and 8, 1}, 4, Z) = 644, 3], a, Z) = (Up, K}, ) where k= lor 2 for p in F, or not in respectively. = M has not entered an accepting state since the last true input hanging k to | we define 8 as follows: (tp. k’L) where k’ = Lit We can show that L(M‘) is the complement of L(M), Suppose a, a,,a,...a,.is in L(M), then M enters a final state on a,. State Simulating tis sting will be 1 before it is possible for M’ to use ersfore, M’ docs not accept while a, was the last (rue input used Suppose a,, ‘moves to muke an of M’ while true input after a, iy-s- i8 not in L(M). M’ will some time after ret ading a, have 1d will have to use a true input symbol, The cine second component of M’ ara | Formal Languages and Automata Theory pling to use a tue xis notin L(M), M! will accept before ater eee input symbol. rammar corresponds to th NPDA. If L = N¢P) for DP IFL = L(P) for DPDA b 5.3.3 Decision Properties of DCFLS prefix property by adding problems that are decidable are From Ge hve con 6 asa production in G Let L be a DCFL and R, a regutarse, then the Definition 3 Now- 0S0|ISI] € is grammar corresponds to the language of palindromes, This language is NPDA. If L = N(P) for DPDA P, then surely L has an unambiguous CFG. I'L = L(P) for DPDA P, then L has unambiguous CFG, Convert L(P) to N(P) to have prefix property by adding an end marker $ to strings of L. Then convert N(P) to CFG G’. From G’, we have to construct G to accept L by getting rid of $, So add a new production $e as a production in G. {an unambiguous accepted by only Definition 3 Non-deterministic PDA (NPDA): The PDA that has more than one choice of moves in any state is called a non-deterministic PDA (NPDA) Read the string w and push it on to the st with top of the stack, pop off the symb empty, itis suecessfil a PDA which accepts L = {ww* we (a+b)*) lack. After that, read each symbol. If it matches bol. When input is read completely, if stack becomes The PDA can be given as follows: Leta, be initial state, be final state and Z, the bottom ofthe stack as shown in Figure 5.11 (dy, &, Z)) = (4, a2) Blay.b.Z,) =(a, b2,) (4 &, 2) = (4 88), (4), £) (q,, b, b) = (q,, bb). (4), ©) Ls. The Bq, 6) =(g, ab) ot same 5(q,, b, a) = (q,, ba) Bay a2)= (4.8) rack, 8g, b.)=@,2) ; inact 84, €.Z,)=(4,Z,) ail? - for a.2/a2, b.2je2, aaa mae 2, biab ee oe Pp petit ee os Fig.5.11 PDA forExample 58 ‘The final PDA is given by M={ (ay 4,4) (B) (4, b, 2), 8, dy Zy 9) 4 noc emp scape SONING Sting. 18 Af ‘ ‘ a odes" a iyi re TNE, Onbiof{ yeache, ® the final State en it y actepted eager be, 0% Alcerted : Design + fer aypes 4 OF! . > sin ne tao! . athe fllodi7) wre © type | 1 (i) Derrminutic PoA i Won Deterministic POA . wa. Détewninistic POAT p pron & 4TUA% Like M= (95,7564 B/D S yohae @ 4 Fini and Non empty Set 2 tite | POA - They EU Finite and nonempty set of i/p Alphabet Bi if 7 finite Set F stack symbols bet a, 8b O mMappiNa function wed For mapping fy) ms pouins trom CUVIENt cStat ‘to poys Sasa zi f be define = , 9[My KH) © (4,%, B) rohere 4 i ome Pi , YA tuvvent state Re ae | MB Uta She” ae Beye, riot - % ww wnent tp. symbo) : ’ % uw iivent Slack syria) fg Y 141, Next stole XB. uw shows top of he astatk. id 4 demtti- a unique tsamition wy tach ilp en 70H & daid tb be clete vind ttc fA gla,Gp\-260- CFA (PY son petermnistic PPA 5 WO) | (same a above) ; 8 | re emi cyevanes . (Mirr Be (14; i AS | (195.4, x0 9 4 PpA=d&r . 1) designs pop Hat accep equal i. 405 and 0) eign pea by b= Let (Az “e {aby ah nl) : Tele IE) 8 ee 1OoF Fintte A oes eke 8 (40) 3 (4o1 5 Ho) S(M% DPAIgn With ou PZY - Gp) a (ae) = are | ’ 7 ma - ’ bare G~ — b.sto9 Zam base 0,200 Qa adig POA =dB1Z\T 8,4 ZoiF ¥ as AS and &é Whee Be Mo.%%Y > God) > S l5jra,20) © (ase Ee4avby En Gabe} Ge (tui tay ty ; T= {Zo,04 Arey Sa te 1éh Vioof- 3t 4, 6%). doped aaabbb 5(4/000bbbEY , te 5[% bb t, az) 3.(4er gabwer, ax) S (Ww be, AR) 3 (4p, abbb©), aaze) 5 (Gq Ey Zo) S(%@rbbb E, 0.40%) 3 ( %%) " DOAISN POA Soy the fanguage Gating stems Wits €qual number of a's And bc eq Ee {a by = {€, 0,b, 2b,ba ,aa,bb, Qabb, Abab, bala, bhaa, — — Ck, ae eee) baba baa, - -—-J 5 = ETPPIED ifeiare, £98" — Czoaae a0) fz] G6) 9,0 sak aaa be [5 bb >be bb>b i i SE POP 2 (G12, 9514) Sy F) : i es a Ty 9p 181 39,1818) = (401% =| ; pegs ti 5 (prbr%) © (Ga ib%) zach (ob i a rb EG 3 (grasa) ~ (4/00) en nie ene i Nee Ta peeve 1+ &® Pant 0) eles ROR Ineo 1 Ben a) be 7 w 2 2) bbb aS »bb bbb A f | | Pole Jt the storing Synbo\ ts to Binony We use Gan Consider a8 this ove “Te. OF CFG will be Tn that State of PDA pues Poy each Won-kymical odd the following 3(2,5f) -8 (2) Pros = “~ se qabagbb + (414.4 baal bb, %) L=Yabbaabh), food Lets. gd ce Seesaee (ale) eal] | & (t, abaabbb, A%)=) 1(%1b4 bbb, 99%) 5 Gy, | HG, 1abbb, 44%) =) (er bbb, 140%). I (Hy )Lb J OP Gerbs a2), 5b Qerb Fo) Dh (9p. 7%)” 1D Reign PDA: fr L= 100b?/n>= ap 1S | ld i Given. (= dal ine Es pi (rh wing re \) Deri sol) ¢ of IWhbd (= 1043) Doe c ie z ee Re iagee te L9CHr tea bol?) Given = qwcw/oetarpye yey NF Gordahba ay (-4ata, beb, aabbacabsaa, ___ 4 ~ br 7b, 0935 w= aabtbaa My ES gy o0re ert Sameer oe Oe bpse On ae ; 8, %ePALo Proof 9,0 50a vopag bora g oD bob 3 (4p) 20b0R00 7 Tee Pe addion o> dod gt abepday @ bef bb>bb (ota a0 ® 4b ab a4 3 Uday chase ie { : a; b0o %) » : + e908) =\6liy929 | ; 3 lter : sale! ty 5S) Debign PDA. toy bef wC"/ 0, > 44 ovey E=dayb, Cy Given, , L=qo Be? nj m>2y va, ==4Q,b, Cy Ledabe, avec, abet, Qarbe, Gabbee Aa abbbe, m+ i4 ’ US= AQabbbe ef a 4 laJaya) bY C 297 ho b,0-7€ base “GH mt oe weaaabbly Qr2p-202, PrOF_S(9o1 AA Abb c) Q,a-raa 36%. 0abbb ¢) § (00997 3 [a00%— bb 3 abt glen) -8 (a) ie : gee boites ff DS Plowhi- 19 a.aalebhC is = §(%,aaabbbe) U age? ‘ 2a bbb bbb | w: C mn en PDA by L=40"6 Jom si OVE 0p, Lega n,ma>1y = l= qabbc, Aabbbe, abbb & Aabbbbce, - - We caubbbbece st { rev ga Et ope? Te ) re on Che , ' aan Garg > Basoo Proof 19+ KObbMB CAC At TM es) ap Gmb=) S(GoiGabbbbb ceeg z > fice aE ul deri. rinals Ick to Vari- re are ss the could re not fimost ase the me the ief, the jormal” ariables ck rammar ) where normal ved by @ fier pro- Sal RK | Finite contro! = Ta [8] | nt | al f Fine cont | is | Le : Step 3: Pop A Step 4: Pop A Fig. 5.12 PDA for Example 5.9 4.2 Constructing CFG for the Given PDA Theorem 5: Suppose M is a PDA. Then there is a grammar G such that L(G L(M) is context free. L(M), ie., Proof: The previous construction spelled out in full would look messy: but is in fact quite simple. Going in the reverse direction, i.e, converting a PDA to a CFG, is more difficult. The tusie idea is to consider any two states p, q of PDA M and think about what strines could be consumed in executing M from p to q, Those strings will be represented by a variable [p.a.a) in G, the grammar we are building, By design, the strings generated by [p, 2. d] would be just thowe substrings consumed by M in going from p to q. Thus S, the start variable, will stand for all stings consumed in going from q, to an accept state. This is clear enough, but as always for PDA, we must consider the stack, hence, the stack will be more involved: for example, wwe will use funky variables of the form [p, A. a], where A represents the top of the stack. The construction goes as follows: given PDA M = {Q, ®, t, 8, dy, Z,, 9}, we will con- struct a grammar G such that L(G) = L(M). To convert the PDA to CFG, we use the following three rules RI: The productions for start symbol S are given by $ > [ays Za] for each state qin Q. R2: Each move that pops a symbol from stack with transition as 3@.4Z)=(,°) induces a production as [4 Z, 44] > afor g, in R3: Bach move that does not pop symbol from stack with transition as Ce induces a production as aes eee & Push Down Automata | 219 S142.) (9p Za 9g) bay. 2,41] [4,2 9] {4,2 44) > {a,.Z.4,) > b lq. 2.441 f4,,Z.4,) {a,,Z.,1 > ala,,2, 9] {a,.Z.q,] >> [ay Ze 4) Lay. 4) (CFGI(This does not accept nested if statements). {a}, fice}, [X,Z}, 8.4, Z, O), where 8 is given by Letthe PDA 8(q, i, Z)= {(, X2)}. &(q,e, X)= {(@, €)} and 8(q, €, Z)={(4.8)} Solution: Non-terminals are {S. (qXq]. {4Za]}. Equivalent productions are S > [aZq] {aZa] = ilaxallaza} [aXq] > laza] > IF |g2a) is renamed to A and {qXa) is renamed o B, then the CFG can be defined by G=({S,A, BJ, fie}, BS) where P is SoA AiBA |e Boe Convert PDA to CFG. PDA is given by P= {{p.4}, (0, 1}, {XZ}, 8.4.2, 0), ‘Transition function 6 is defined by 8g, 1, Z)= (a, XZ)} (a, 1,X)= (a, XX} 8, €, X)=1(4.8)} 8g,0, X)={(P. X)} 220 | Formal Languages and Automata Theory 8p, 1, X)=(P.0)} 8(p, 0,2) = 1. 2} Bs aX4q], [PP]: [PZa]. 142), tg, inals are (8, [pXp], [Xa]. [aXp], [aXah. EP , Solution: Non-terminals are {S, Add productions for start variable S = laZq] | [92p) ' For 5g, 1, Z)= {(q, XZ)} [azal > aXqllaZa) {aZq] > 1[aXpItpZ4] [aZp] > IaXqllaZp] {aZp] > I[aXpI[PZp] eet. [aXq] > I[aXqi[aXq} [aXq] > IaXp][pXq] [aXp] > 1[qXq]fqXp] [Xp] > 1[qXp][pXp] For 8(g, €, X) = {(q, €)} [4Xq] > For 8(q,0, X) = {(p, X)} [4X4] > 0[pXq] [4Xp] > O[pxp} For Bp, 1, X)={(p, e)} [PXp] > 1 For 8(p,0,2) = {(4,2)) [24] 0{qZq) [Zp] ofqzp] naming the variables i BPA L921 0B, tpza) 1c, A Peay ta [ey w Foxe]? TWA} 001, the equivatem Cr {02 © D, [aXq] 10 & [qXp] ‘G can be defined by S°08,A,B.0:0.E-8 a, 4), 10, H.R), ingly: The HONS OFR also are to be renamed accord Bo eB | pp BS 1EE | 1FH : PEE |1RG > e|0H Bhi: P00 nut On simpl Solution: The {Sa Z,.q Wha. had | S- productio (1) The CFG 1 [4,24] > 2) The CFG fi £9,2,4] fq,2,9,] > Push Down Automata | 224 aot - C508 i9Zq)} a} poo (On simplifying the above grammar, we got soB B > 1EB| FD E = 1EE F51EF|1FG Ese F306 cea p30 PESITIERED oe caste 0 re aig 8 M = a 8h 7. , dy ZO} where Bis defined by Blay 82) =) (qq, 0, Z) = (Ips 029) Bay, 0.0) = (4, 00) 3(q,, 1,0) = (ay 10) Blay 1.1) = (4 11) &(q,,0,1)= (4,8) (a). 0,1) = (4,8) 86q,,0.0= (4.8) &q,.£, Z,) = (4,8) & Xp] to Gand Solution: The states are q, and ,; and the stack symbols are Z and Z,, The states are P 1854, Zo dh Edy Zp 94 (9 Zn Sal ry 2 Glo 4 Ah [4p O91 E89 Bl C8 10, a} Lay, Hs gh [4p 1s 4] 4) 1s Gol L4> tall S- productions are given by rule 1 S$ fajZa) |L4,204) (1) ‘The CFG for 6(ay #2.) = 488 faZ.a1> © (2) The CFG for 8(q,, 0, Z,) = (ay 9Z,) is {aZ,a) — 0a, 0a,lla 2,96) 016,09 15,244) {42,011 > 014,04,)19,2.41] 1404) (4,284) 222 | Formal Languages and Automata Theory 3) The CFG for 8(q,, 0, 0) = (q, oo val [4,0q,1 | OL4,04, 14,094) (4,04,] — 0 [4,04,}f4,0441 | Ola, {4,04,1 = 0 14,0q,}l4,04,1| f4,04,1 19,04.) CFG = (q,, 10) is (4) The CFG for 8(q,, 1,0) = (q,, Laglagl > Haytag]la0a9I | Malaita a {4,193} > Ha,taglfa,a,) 14,14, 114,24, 5 =(q) Dis (5) The CFG for 8(q,. 1, 1) =(a, Nfq, 14, 4, ! 4) [aglqg] > ayaa, 144) | 14, tate) > Maglaglg,ta,] | Ua, taiIlq,!a) (6) The CFG for 8(q,, 0, 1) =(q,, 8) is lala] 20 (7) The CFG for 8(q,, 0, 1) =(q,, €) is {a,14,] > 0 (8) The CFG for (4,0, 0) = (4,,£) is 19,04] 30 (9) The CFG for 5(q,,€,2,) = (4,,8) is [9,2,9,] > 5.5 Two-stack PDA fame languages that are not CFL can be accepted by a two-stack PDA. Definition 4: Let us define a two-stack pushdown automaton to be a six-tuple: M=(Q,2,1.8,q,,F) Q-isa finite set of states, an input alphabet, T~ isa stack of symbols, 4 © Qis the initial state, F< Qis the set of final states, and 6, the transition relation, Hpafinitesubsetof(Qx 2U (e}) xP*x re) =3(QxI**! where inthe left-hand side, the thitd parameter Indicates the first stack symbol the Parameter indicates the second stack symbol. On the right-hand side, the second param” indicates the ©Pperation on the first Stack, and the third param the second Stack, eter indicate: Example: Design a two. stack PDA for the language | = fatbre" ne Np not solvable with @ normal PDA, but a defined by * 11 do 8.6.6}, (8,0). 8, gy a) 5q,, a, €, ¢ dy», &) 9,4, &) =(@,, aa, e) Solution: Thi a two-stack P ‘The PDA where 6 is 5.6 Appl PDAS can be u Itis also used tion of the inp 5.6.1 PDA During compil the language. 1 Using these rexr*) the fourth parameter eration jth a wo Push Down Automata | 223 Bq 8. 6.8)= (4,86) &(q,,b. 4, €)= (4,4, b) 8(q,, b, a,b) =(g,, a, bb) 3Gq,,¢, a,b) =(4,, 8,2) (qc, a,b) =(q,,€, €) 5G,,8.8.8)= (4,68) Solution: This is another problem that is not solvable with a normal PDA, but solvable by a two-stack PDA. The PDA M is defined by M = {4,. 4,4, 4y4,}s(a, b, where Sis defined by }, {a,b}, 8.4.4.) Bq 88) =(,.8,8) 3(qy, a. a, ©) =(4,, 22,8) 864.5 5.2)=(4,.88) 8Gq,,b, 8,8) =(,.2.0) 3g... a,b) 8(q,.4, ab) = (4,6, >) (4,4, a, b)= (4, b) (a,b, #,b)= (a, 8(q,,b,£,b)= (4&8) B(qy £ &, €) = (G4, &€) a, bb) €.8) 5.6 Applications of PDA PDAs can be used in compilation process in checking for the syntax of the input program. Ivis also used in converting the given infix expression to postfix expression, or in evalua tion of the input expression. 5.6.1 PDA as a Parser During compilation it is required to check the input validation according to the syntax of the language. The syntax for writing arithmetic statements is given below S>iABT ESiOB|i O5+|-|*1/ Aa= TH) Using these rules, we can frame a statement in the Source program as Lia poten te ate? calbe ne Mts ppesig PO" bases nage 1S 93100) E _ Given that, CAGEAYIA SY Whe) V> 45 AY “efi 4) EY Se iY i 3) Conse uct POA by FG» : S>aABB/anA 9>0BB/q 55 bap / 4 MW the d.,. iy GiStion 9 string eymins WEE OVE given Qiip sttings then nit ne-of stale= 4 F 2 40,9,2)> (90,92) F (446,09 1 (Ai, boy 2 8 (%,9,%) = (%, 2a) 8 (9, b= "(4,2 g lt ba) = (Po,baqy IF %,2) = 144, €) g(% b= (4,9) "Equivalence Of C FQ a PD AY ~ Alanguage ts ta Context Free longuage to thés\c FL) % genemt ing by Contert Pree Grammar (When ever Wwe ave Covey). 1FE ‘Some Sa PDA: when evey WE Ave Converting CFG into PDA de follouo Qule-T the gien Qrammoy “Ss converting into Greeback Normal a . form Pola: PDA of Preduction having Only one State: ie, £25 Pole-D- Jf the storing Syrnbol {5 to binary valves [tke OO then we Can Consider 05 this ave Terminals The ‘ital Symbol Gf CPq will be in-that Stale of PDA Pile, Forgach mon-krmital odd the following yvle $50) -8 (ee) (vam) Pole-7» for each taminial addthe following role 3 (49,9 = #14) Crate)

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy