0% found this document useful (0 votes)
113 views65 pages

CS1603 Class Notes

Notes of compiler Design

Uploaded by

2021ugcs032
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)
113 views65 pages

CS1603 Class Notes

Notes of compiler Design

Uploaded by

2021ugcs032
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/ 65
[C s1603 TTan Dot] Oe Dine kumar ~—Gemapiler Decign — hunger cce@ ioe niWjsr-acin Pas. enter Tag x pA, = ie Bind poe Sooes Coda a yy Level Atom Prodctiviry OX A txecuHon Tim a= EoR TRAN 195 <> Compiler Fanon foil ro tals high el engine Ney Pog TRAN Wiha Gecko } fe } Formolw at Es _____| tami Un LLL Hie lewd lan quage + Dele _of _(oungilec et} J (tie a { [Lexical paelyien| = FRONT aed Suiupre wee] ioe ert eg ea tof Target code Generation Joe 0S Thean be abject cods - AveembY Foot, lenguage any Pring. yD on —dlyeda ats Poa te a Qenvrohon ao which has low over head | Pore) mul byalis ahi fl \ aden Cx porsey divisn & Swag, Ora nad —* “Te_eady Poi Weel + TOC, CFG, cer NLA 2 FA ¢ min chive Neng Crete eye = Regula, Ranular Fike Nea i en = cP cPG Pa Mealey Cent tinct) * eee Conkxt 5 Er Sohal sn) a ae R. ees Lung sea ge Torn \ Rabing _ RSI Ne | CREC) naw Xi Papas ~— Recurnne Ene mirabls Me) Aga ee 5 era bn ars Sy Coneniine ) ne Vo cabulen = 5 . Dict Ee Swe Asctt S40 cn) ve ake > are Dichonary , Key uw od, = a 4. Semon ic Li yo Scrof rule Cre igen play Pugminted Crummar (Pruchrals.) Fig mane | freee ae (Gse yadd™ Tt aoe is my ( Sears) js np- Habe PF ruteraton if Ming : So & Choe Y»yo - adc mm brary Bey eae = WV Jon toa Wid Sea pag —Onet ome di Pelt) @ Tit modtlar € no. ortr Lappin, Gee go ide v7 Gara Dstes x elie lie ale-]u Pon a] = 2| bela Keyoord XR 0 perahy *Seaec—ipocting ” ie oe Fs a FAj=> RL<> Rue RE Av @ aad phase) 1 Exam ple if (oe= 0) E— €+e leve Via tide id je [id F © ce oo T \ ia / ere e * B I | id id 1d id Ever handing 1 nek don oy compiler bu- Afou Eror : Ta Ger Bere a ( t a Q Sra recovery ) © take Chock 4 Sit §. > Conc adenahs eo Type it ath 7 eo Conrvol Flaw chart B,+he= s Unig venos Unecte day “SST he pehin 4 d ot F bated on dare type Cress; tory eee? Tor get code @ Ye Xx = Qty @ 4 MWe xy x20, fj = Y¥Kio|-y dens aUel 22xKta Nery POOR va OER. a ee & Codt yao nen — oe a oe Qe ce _ ‘ _ _ for Ci2ojicn ine 14 ry Cid Ca \ _ Ae Bs —¢217 pe Cizo+ On, a9) & - yc) eMg kekic i) pis 2A ‘1 Prene “x pix RO pO S As _ « 3 wn Neo \srees + pe oF ie Pc 2 Attn Ze M__— selaM X 2 + Ic3 4 ont De» 4 = 218434 to € “4 = 24 0 1 pis iy KX RRR Area = 256 Prea 2 Ux PIxexe = > Voloms = UNG Xe KR Vol owas = Pree. & a (UM) overhead A¢B > otead —— th Prosesaa | ~ 7 = — _ dyakx. — “— J oe ys SESS Z~ ae a S = co Tune apinsizaben | AN N\ b_\y Nee Move, Nor Cte MoM Ce v an? TNS \. De a Cre ©. 0 i CMoy Do High tevel of Abpradion Wot How ta dew —| ear hee g | compte 7 | MI G vest Took Caag Leos Uvet(L LD Abshach., rm caomple y Ga > EY Cid pt GOas ml oe SR — , ee keniced ae SS. Cerra KI il id 3D nt se Float 4 60 brery Langueqe wild aye ip om anktemediab & id, ee / Par eres - a || ede: Digi os oes | , eee Ta coeds cpt cks _ L,2 idx 60.6 soit nok Chea ope Id,= id, + t PR rep ce cuales \ == Lor kp ide —Mulf_*, #4609 Cpe €, id, [es1603} \T Jan dora chp- De Lexical Anvyrte Ctik phace of Cornpiley ) + Recognise tokens Jl anore tile = Spaces ve Kem Clip Wy a-b:; I ¥ ALPES To Te tye Tr Te J= [875] Abin Syntnelye E Category * Uxtrme * info in tok, Heognice yore Lb NIK Gace weal her be stoppma, erika A A VEde , ie nics eae oe * Grey - eck, ~ HOY Onin z 2.00% ge Mogh Using Regula aoe Uxpresitory, #freeenise gal finite. : NFA Revise aes _ynechinte ynechwe Kora Re TronsrHon Diagrams Ke dian C2 > Sid 2d C4>M14/37 % Ignore While spaces, Commids Gnd efia -~. * Conswuck Conshanh. * Racog nite key wordy ; Vdentihea: jheif+ gee xe! 5 elie x= 1; evex = \ il fist pis tees Syntax Avutyar lp ta Seu | _Y Seo vp r ails building back exhs ally DIST character Cock Ahead if KC 1 Cae Bran D Sranple | te X ' ® Untigred no. heh = emerh \zlel digit of 1)2ial..-. ls digrk— digit* Trackon — * ‘digik lem ” emphy Oy Expomnrs (eGte )dign)le Lo pore ese ahy wes Nomber digik; Fraction | Exporsah sx \denbhe; Chw) G Biphanenedc © underscore Chit « @pylel lef ghe olsi2l..19 \ dank Reg Goa Sig Deg L se L@}) 9 L(R) J (ered Poreby tis ) Yes/No “Token porn yelakion oprador + <|>\=-|¢>| C= l= Counr 4s. Regula, ve Hinton, z= Co oNHF a; Priority White Sanat 9. Moimal munch prea ignored flee x = Ke es rewnad \. Write fu Regular &¥precsion Boy Lexem of each token, 7 RoR. Ra Number — sign? 2s R= Rt Rar Rot... Ry ton 30 Toleen hx pes) 8. Ler t/p WX Kee Ky, Sor (SUE check Xe. EUR) yw. Ky Ay € uw > Ky Xy ELK) Poo tome Dvn Vet fuch ) boken last of xyes Xj S Remove Kye From In pur > ge + (3) Xyecee Kp ] LH Kye KP E LW ge Ace Fo marin ad monch princi Cdependny on RES word bomdary )— J7 1 CLl603 (pee eee \. \npor Maciel BA a. Setol shite. L \9 Fan 2023 t 8. Sek of Transiko, oO =) gn J WA serok Kad ule ¢ GS. Srey) Sake OQ 0 =m Srart Vraasikion [Exempk ef eats of lar Exprestiond Tithe, atmtet =. -\9 idem key 3 letter Chobler| digit ) Perm 9 digh CV dig! ) 1Ce Cl) 7 digth4)f digit + oft) cake J blank] pb | neal wt — delimit 4 Spend) ee ¢ wi-op 2 <\>|e-\= Latte| digie ‘2 Sr Z,0e1r Os Pie voi Ck, Bea abt ribute) aa fia) (Wok: # on OF mane TF WD thin lookanad] nie ote a Sf Lethe digit) set of olf symbols Oats * Be —{O) Crop, gt > @, 7 Po anus dingrans For AA Rhee oF Numbew . e. 7 Gar, Hear ex) Num dign Cidige IE Crh) 9 diya!) 9 Sa / tht diagrams of Mitr and Phe ou, pp, ah ee EL UW 2WIM_Exporenr ; digit \ceEueus 1\23.4e44S Priorily tle Pregeas 1, Re a NFA I, NFA— DEA UMintntce AY ne *Ke of crokts m DFA ae = ARG © PEAS ey ta + FILM Grr matahey ¢ *CRQ eo) fesigo3) (za San 2073] Chap & Syntax Anabysic C TV Green ines Sit pore tre Shy W Contex flee Samm iy WE L(G) pripecning langues ‘whe piery wk of fe 2nd pee ote (, Qengret. farse tee v. Ewev Reporting & Recovery 9. Model sn Cea 4. POA [Tare driven farser Tire type oF x preation Commer lec dataed by PA: — dy CCas)ee) +a) ay (iw) i+ ae bit) WWE of. nse deals T se of Terminals P ai: Pradicke. Kale ce eis shady Coy meet) eat & 6=stu Or Lisk @ \ie + dign YU-SABRY Nig) 3 Ver - digit PA vir dig Gur ¢ digih ot v ) digit olrle} --- 43 AT ) LG): 3 List of digs separatid by oer ee Gee BHU gy Beek LN Ser lish > List - digsy Le Choose Pre (correct) production he tn Choose Tha rode /aymiel oe Vist + digit - digir pene — digit + digit - digit 4 Btdigr- digit i 324 Y- digr v Sioa G Example of Am bigueus ramen Eee \exe Ws eee \ digsr Be arate digas 3 ofilz|-- ‘3 Vee Citas eau i eae) ELE as - as | dit dy eat vaubdebvad oThe no tua algoath, 1 wmove Om bi gui y of ata Oproemmnar + Pome it wold be doar maavelly, , L Precedence € Anoaabviby L Rewrite Pe Grammer #¥ Ambiguity can oe Yeroved by euirigniny prionke, a OR see mT example below ter — Em eHT (Exe ikea see) \e ie lia Hess Jig ea ASL A Leak nodes of pare pee MI Ft Jermiinad & internale aif be te denne. id tid.*lsa Paar ead at ee € D.LeFb Factoring. wan (sie | | \ Ler mesh Foe. td Right mas | 4 id ih Yu er A> Aaa | [ ex") > A>RAl A /\ pi aa’\e . A Be eva a /\ “~ A’ i Wake Rx Pans AS AX A> AX) AX Je } @, \6, Ar EN A B.A’ | 6,4/ Ais aa bs le E> Te’ ei aT EE TORT qa weve Eo Mid depedaseniprongss Tyre > simple Ji dant Pee Jarray Cetmpl] of hype Simp => che \ mteger ) num detdek num eoey, \Georsmctrer rel aor il Orray Crom dokdot num] of wikeger look Ahead Reovsive » Hype aol i : ee eae, poaeg ve hey Ber iy Frek(ep Ze Fin rom ple) 2d chew smh, num) (Porse Wer Be) arey Love dobeet mal of ineg ics eyo | ore pba’ ow eylsimp ly) of type it Sdmple \nbeqer A > x@|x<éo C Lett Factoring) Wurm dokde ny, Aw AS A'> @ (8 fredickve Parter A\gon Por |B How > build be 1) Phis forser (ile GE) i Left te LeFt ynost Po Right deriv akon Scamming is Nal N— Ac |Sdle Am ale] the ee fe, Be |G Reset A> Ac\Aad|bdle Aleseeaac le Ga oe 3 Ub)= LG) pia cA’ \aga‘le Predichve Parser CULK) Parsers) idtideid QI Which predv ction ehnores) ie (2) Which Symbol tv expand 9 ale eo ie) c & t| Z e'— Te! Je ESET T (eFr pen git TaATREIE LD carton — av_y we Tle E> ceplid Fo ©)lid eau draby - ergy id + * ( ue © | eo-Te’ \ eote! ef e/a +e! eee ee | eer Tet! me tive |Toeer' eyes | epee F | Rid FOE) \ \ay S[Mid- Sem Por Kon [+)p \4 fa @ oil) Lexical © Ook pr Syntax Aredia, ; Ee te Sok Table poi Symbo} ob top of sinc 9! Trike) vymboh jd tid € id . icy VE x=e ash, frm halh Th xseatf, Per pore? and ip tt TEX ie ane erminal Yo uvw wx] por 4? and posh (wVU) whee, Unyet AcKo> fe \dtidetdf Expand 69 Te/ fer fusidard f + Ohi! ERECT tda rd wid¥ Poxid felrid \dtidaidy popd) f elt! Hidxiat The aide id ere. fe pets $id *idt PoP (yy fe'T jd wid Tort fever id eid f fold felt laa Forse? fer kids To xFT! fever kid poe ) 4 OTE idf Foid feltid iat popts) pert! 4 Tiss eloae fe’ 4 $4 ¢ x Ea €+e sa es est|t ExE | <> TOT*FIE = poorly \e) & F7() \digr | digir yems ang Ambiwity aarndes ee AE Nee, Hou h @ngrucr Coton c3 Te! Rey i hae! a eee Prsk() PolJoo) Le reels ©) ldigir LL) Possess oo poe - dé - > Mao 1 A> x, 3 Able Aa, ~ Input ~ ofp idsidwidt €> Te es ate’le To eT’ Tl xrtle Fo ©)|id Frat) fallow C ) Tetm nals Mi eX € e/! T , Non - Termindo Fit(E) = Frar 7) > Frat(F) = ceaad This vs Sperny backer fox expressing — Id t id did f ZN, LN, I~ (ie 1d € Far(E) = Prat (1) = Prerey z olid CY Frse (ED = L403 Pro (T7 2 Xe, e5 A AAAS Re ee he Bee, First @)> Frsr(A,) = Fiat Ge) ~ Por Gs) RyeH(A? cenrairs & jdeidt weird side 1 4 will bem Blow i= 2.A7 xe a Polls (@) contare Fet (2) M4 Phe | Pol lo o(@) contains tellooA) Pollo 7 conmis + B.D KOR > eve Foltea(@) conlars bello) e — Te ef tele TFT’ TL ete Fo wld M Lao] id ae e3Te’ E>Te! tela +7! t! io | toe JarT eT Toe Foid Foe) ; Toe | The 7 Ambiguous Grammar Ss ite'ss'] a QS bo onder Fijo bye: velk f pe i'—# ede O SIL tome Ev b Polos Wi) = Pollos &) = de, $3 folloo ts = Ker 4h \h & Pen if €, Thy ©, dee Ey Che Cy Poge No.: Oife. CS1603 | Fey 2023 gh te Furey : Dore Ua | i Meroe Pasta g AO eb progranynns wl me 7 oF programms Whi Fotlacs) f “t pil Bs dt ee Monn Netwane, te Tapa AS Hdl halle Tel obs Sl > @meinahow of n Peri € aa cn) lookothrad Boi oO. E Bice LL) Ex = SSA eG ee a A> Abel @ 1 aade @ RB->d ® aAbed C : 2 bho d @. {ny hottom up ue do, Riverine of nigbbmetk dodvatios Abbede ; = ahkbede ~ Ade ABe —_ . Shi bt Ra dap Et whit trea pq Ee tate pag — ; fr op pq At po, => 6 n When fo shit} Roduce 7 J wWhicts tutor blag. Is. Recen © ee eee rokbcde Avie die mitt o ; Shift Raduse~ hitt oA tede OUR eda: Abb cde &®Abowde Bb A.cde AAr.de. abAc-de aAAd.e abAcd aA Re abAc Qe aAARe- ft. tobb cde or teal andre) Jiadele pre fs oo Asbede abbede ———— Nor © handle a Ae. OL cde anAR.e ab A-cde Gace): & We use pea. te betton, up Porce Wi woke C1 ge. ese, lll poscreiliie.) JO MARKS IN HMIDSEM fore VV T eat Mefhed (L147 Peete 1 : ce as n oo edocs td tA de foal arora fee id= id + 1g Eee idsig J iE = Roduce Ea id tid Con Flick Et id. sig Shifty ) Reduce ame Ee tt 4. id Ext + tid Ee E atd Eesid Bx E Lids Ex. id Eeete- Erids Exe. Ete. oF VE (sey PAL all ea Date: / of lookahead PAUL Pate (gations wy) Left bo Rorverce of aga ban sk | Righy dence. Wednriy oF Vp abbcde -— afecd i $ — 6Ade eA Kc Jo] aS. te | [Paves L ty 1 Shrek w Pacts Te role ee Achion [ek gE re ee epee tet QQ eB) eg we <= ‘[Poge No.: Doe; 77 ll Ex cumple EA a Sa Emest|T a eee aee SS FE €)lid _ bite | id Lie te | iC | pig tle ° cs uy 214 : $4 Cc : x2} 5] y2|ez = a 24 1 +4 M 3 sy om 4 t xf «6 rf zB 6 sf st] os 18 4 <& oy \o & wa 5 ei | 07 it’ [cl | —| chro] bo 4 v3 x4 | 43 sat ta re rt TS i iL a ais $= rhnift id eta 4 id tl ze E> FAT o £-7°T (E> ie ToTxe +4—T = £ x Ese) 1 ote —Laeuk 3 id eid tld 4 Shipt id_ocd goto section | I oid T ada Lid ¢ Rodice OFR didsid 4 ST2 zid+ id f oT2* 7 jd tid OTL #7 dT tidt OTZ£TFID tid f OT2 +\d Oe4 Aidt OE I46 Jat Off £idS 4 OLLEEES g Oclt 6T9 b a fekcal if Accepind Wee C Wushing fas falls i Rugmest? dhe Oueugmae Gs On,T, 9 0 (Mes C Py Ps cost) ) -E DP E¢T =a *D pth Sh ne ba ert} Else To TeKEIE ertert|T fb tale) Bid sem — 46h 1 unis Lx (0) ides et els e- emery © > e4T Eo -€4T DET SS e4t ett: “(e' 9 we \ carer, Spat t&— -erT ei’ -t -T ea Ta tte F \ —? (es) £47 oF a 2+ © | ia / 375 Txe “F Cy ar Y Closer C) re PT Peo efoe (elo ey eve ee Ein le ern mM id yA) § r Pa ge te Ci 4) a ey. 'P \ 2 / T -TxP Nie eect Sean Tap “ED Qa de(T x 2 phigh 2 id Closuye (Ly e-waste ol ~ x = Wwe - wilt Vie Ot pin cee ol pouibhs “Y pk 4 oth ft Viabl abbed L f ret AD Place Ae Abc ahd td Ake w dao nh’ ee aa ae ee Seb of all viable pcb ice rey leaguages) fe _ Botlom up parser | zw > . . - PR A Ge Hh — Gmsdauch oa table A‘ Jody b _ fs re ‘ tw! | aan fA Pt eae = —tagul FD | TT 3 Te . I SS 3 f at bal ta’ ‘aa vd gf. : [fa] A, Fe le) ) I$, (E16 y : [\ Ep err jy 4 A EDE+T | T - Consider a grammar TOT*FEIF Example and its parse table F>(E) id action = = = Se ~ LR 0, ; —] _ : = = - ). ole l —lALR “wl ls v an Lookahendl L 2 UR Par ven y St Failos (aa) SI A phe CE aT. DE Tn S|) a Bb \t3 T¥é 2} Bad 8 Abbecde i QAb:tde Je Z ; Fy ” aA bode GAAA-Cde - WNd.e o Sb 1 2 3 4 Sy a £ i] : 3 Hy q | axe LRU) jdem ZC LR Le) them last abou yas) poser oy patel hse B= Fas eBB, 2 6B, 4 i BRB: % dont Leg. a Sa Ah. 240.b Galo Jes. aA Q abaah - pob MA» baab — : i aabs aab Pe 4% x Rely Ashi St Y 4A. co, . = OP aah 7 _ BR $ 2 AGL, a og -f fdsa, tt a0. 6 ecceeph ) pais 7 heb = Le Le) _ a Ta stk aR pt Recluce Ae petal follow : 2 T YS ymiselt (1) terms = — i feat gaat i lo axyz, a look aheac) — : b2¢,b 4296p) 1 [be foblw (0) (oa Go D ; ! i i 3 | | 1 7 - \ Kieolest tot oh petseles A Merge oll Px Matte iia ee ee i, hl A CLK ay hy Si —' “Jo05 -B0nn., £4 20,000 a 1 COR a bh ot ean Py >a ar i byaltlt y Page No Doe: / 7 Weg on ta ADaA ft A— -0A _alb bo aA ( A “bp aly poo oi dt } + SN EE Redvee yi GLE + Rode 2 -kuluc 7 on ~ wont Vice may ig Oc Cems air z — Xa VY x L Qe Bas — pg 7 ) > _ pl ee an as Q & (ok at ya 4 i x 7 the Yh t Poge No.: —4A it be ee tee ae ee ee eee er E>er,e 4 ae. ad Paced etn Ef» 4Te’ le Ek E es ALE ele. ~* Che Eo * eT Ce) ; € te) Ad Lol 1 Renate Pre x id 4 id x Id Opfotenen 21 : 2. Make Par pole al posses SUC 2 ipl @ CLAUD Sa cig at wnat Power tr | {lL 2) S LARS CIRG Lau) = Lez) < cet ae at Rte puta! < La s : yAcc £ison _} An Ute $ | Pare [fee Foc Mid fe254' —4 Aucu + Chp 1 C2 _ a ch p23 CShip 2.6- | tes Cy os Pacer Cc a ) : . a \ { [ SUR()) | L{cR(o “Page Wo. Dote B Hen = wy part Os ai Ope voce Pov ale fe Cunaineiyoor yAcc ete & reici) NK | mEM(O7 wSLKU? Che OF +t . =A oo Ax glee = Fallows (A) (BAD FE highw Cos Jd Wrigherh Cage ea i gt — ee - wm. SPEED Yee | fi i : cee eee ee ) on revit CBE} LaF pep te aay | Inet eae iin prides —— bree. PLS) 2 Arb roe Pt) Bebe ata Ri NL Ap Ie LR CU —¢ CESS 2 £1 = Boer f ‘pa BEE eEtreE duthin ony emt cee Y ai, res i steatt sym bel O fon denna 7 ____# ee by ¢ siya mann —— tl i aie dy pe dist 4 fe ones I dy pes gmk / look | chon ans ae | bis $2 moe Hhtun One {slemb Hedy t= va a marimar Ge = { g : | a fh : ype Olgh # Se {ie H ae Le ts c| best: | oe Pn Oo bo. ret Vos TY ma catee Eee f Oe ie: ~— etmembt A ; ra Ee Lo] ? +) o0\ ry, 1 —A)oN Terre | urmboeras sim , a's} pots svn =P : at + Ly's4 ist; bat } _ i" oo a ar q a ko _ Abba bbe a, get eR { Pu f Stmmenbic Rules fp 7 arb 5 b> 46 i aid Fre YA iol a 7 i ah Y= €& £3f+6 e = a a 30 l aA \ Tal ? | : Ld 2 > le a b Lik epiype at fe type than. 1 xl ese | €) ceo te ik léydipe = &o- type then & aia elie 2 von. ey ates + og et ik (fo-}ype = ‘float? thon £,+ Value = i 2q + Vvedue + &9 value. Atdarbule. (1 ype , CD Laksne. { —- equvalonr Acc, Lc st603] ly Feb 202d Page Ne, FE MANTIC AEE Si Mh ee Norn lex Nomves A m7 . a Pee g a 4 Jr 4 c eit TH - 7 ® saa Nor wr 1 = . Ie Ne nigger ya rca bit = 4 a t a bit —» 9 si _ Diieibote Cyce tes C a Role) Rule, doc abbvbvkeo Nurabpew albu ‘ ie = iar Vale i : bit value : position Nuraber ponkion 20 (ish. pesibon o—Nunaber posit tort valize = ot ih posi Lif yolie - f) Page No.: Ca) Noraber. 9 Osukinn 2 Mist posihon = Nycher postition it} Mite = tick valent bit. volte nik h’o Neb aden. : ct Mates = Lik. valece L Lbpasitea = Sey posting ign valien 2 TRUE ge valu > Pare IP tiga valere 2 TRUE Numer -valta = Noer abe aloe h ¢ aston « teh wafase speeu 8 jar ae, = deal! as PepOnere lich int Wrest , 2 Bleak Steck wall cha eae : tar o be . Lier > Lise id nt Cul ish eo id Ce Wr Ca Yn Oh oat (aonb) eae | Lupa biehabyge [12 ft wares addenriy (i iets inv adden, | D tat Ey at 4 ——=

You might also like