You are on page 1of 23
Compiler Desqye UNVT Snbroduckon’ A compiles Avomslates Bre code vofitlen Sm one langisat Xo. some othes language. withok chaveing the | seariva, of She regan Hk 45 also expected Yak 0 compiles should make dhe asaet code efficent and opined In Aerms of Aine | and space + Comptes design f@vess basic Arandkdion mechantsrn lank eros deletion & Ke COVES SX includes lexical sytar, and semankic onallysis as front end, and cede | ognesatton and opkntaaion ay beack-end, | SHE PR tee] oie roggaan SO [emg Obigch proc FA Sceraier }lasack purqa.rn Execution process of Souste. ee “ compile, the stractue of 9 congles$ Any Large Slo %$ eaSer 40 undewtand and Fenplement: GAs devided “who vce defined modules. The thrackure ok a Compiler ts divided as {dlovos, feeb ne, al : Target prgamn Caserbly cede) | Swikially we have too phases a cralysts and ; surtheats pro Where anodlusis phase? poe an wWesme | | -Atode representation from the diver sousce code *) | Saynthests pros crecles an equivalent Norge preqvam H toon. jhe wees mediate representation iE cy E . The complation proces contains the sequerice of vations | phases, Each prose fakes source proqiam in one i“ Yepreserttaton and produces olp Sn anclhes sepreserttin N » Eack ‘nput from ts previ lace. Each phase takes mupuct from As previous ey ey . Dhent cak Analy sis' : w Lexical awalyre r prase fo Ye prase of compl akton NV process. HL Jakes source cede as inpul. : Mk seads the source progam ore chatactes at a time 4, i ‘ Fond convérls Tk into mneavinvaful \exemes ee | Levical avalyrer vepresents Ae lexemes in the cv fom of tdkens SAuce Prapam *) lexical avalazes| blexemes, Aokens | FySurlar_cmaly sis’, wagon analysis as the ot prase of cemptladfon, j proceys wd takes Aokens as ‘mput & genescles a passe tree: las owkpud boda Aafs prase, Ane patses checks heat he expression made by Ye jokens is synlackeally coneck os net. t Ss _jctien ne Ole parse tree A)Semanic analyse? rah ts Wid prase of compilation, proces, 2h checks icheMner the Parse Lree follows the sules nus [i oor MK keeps krack of identifies és Anypes and eaprerdions : WhBre Supeloo\ Acble fs a dala chauclures used and Woinkined by compiles, consists all dhe Fdentifies!s | Nome along woth Aber Aypes. “Ole of this prose fs the annetaked tree syntax. ~ [W)Sntermedioke. code ge nevalfon = «An Wes prose, the com@ler aereraes the source. code. j feto the intermediate, code. | dntemmedtoked cate 4s geveroted bho Ane \iqh-level | m Yon \anquace and We mackie language. i WCede opXiwititakion + aM WS an optional phase. : eM fs used to impove Ye indesmediate code so Yat F Ake olp of Me Program could sun fastey ank tate | \ess space. . | : +S semoves dhe unnecessary Wes of the code and | arranges the sequence of statements in order to speed Fup she progam execution. Vi) Code generadiions ©. SES the {mal phase of Me compilation process : St Aakes the optinfized Intermediate code’ ax Spat Q maps i do the Aangek “machine larquage. | Sk ksanslates Te ‘wermedicde cade tile the machine | code of the spectffed computer. f Eqs sum: = Old sum 4 Rake ¥S0 [Lextcal Analyzes | edt SA aie | ae | : ® fates % adn: x ge ne M4 fae eee Semavdic avalyres | § bo a ids eA ‘Wdoread | ao tales penemtor| tempts = intloreal(so) Lemps: =8ds% S00 fda tle Lemps oe fas, RU MULF 459.0 RE Move id2,R2 ADDE Re RL MOE pt dt @Ahe sence of building a compiler + Sa OR RR ne + Brblging a comple, fs a challengire, fast. The mein fp of the compiler fs to accept the source Promam of any Se & Convert WK Fnko suttable targek Program: - Compilers dudy gs focused enatinly on study ot hoe to design the comeck modhemedtiak model and choose Coweck abgorithmns , Kee fing, an mind 40 balance re need for generality and efficiency, + Fite lake machines & requlat expression uditch woe have already shudted Sn FLAT ave the pievequisttes el Rese sting Ye leak unis of porrams(tokens) for descrstng the algodthns used by compiler to. entfy Whese Aokens. “Se comeler design Yhe term “Code Optimization” indicates We attempts made oy a compiler to produce code idhich % more efficienc Ahan the previous code. ha This code shold be faster Yran any other code that pervfowms the same task. We objecktves 4o be fulfilled by the compiles z e optimizations ancludes the manning! ot the comptled progam must be. preserved. 5 OpXimtzadion should Smprove programs perfornvnce. Time required fox completion shoud be vecsoreh le. > The engneesing, effort sequived vmuct be. acs mance able Gress ASUS ay stotic| Durante Atainction = stoke can be decided ok compile Aime et protic ved wainl .) ee nersenbecdon : 4 SS ence oceues ‘ud Seon =TuMms 4 run 2 as te 4 » Dyrarnlic can be decided ak run Mime. fvek Nuomd, Wn? 5, ky puldic void wont ) & Wk a=03 ink num = \Olas - are \ 1 |) Environments and stares ¢ Enviroment fs) mapping {ror ames bo locerkions 8ni he ove. Since vartables refer +0 lo cations, WE cold adkenartvely, KelBne or envivonment ak mapping from names bo veutables sThe skede fs a Mappira, from lecatins (store \ do Mnety Values. ; ane vit Be veanees, \ocodfons Values i. Wwatiable) aa Wstedic scope ¢ Hock k_struclures | a The vasiable Aedacaons uit An dhe sdfrends & . Enon as sholic- seepe. An C, fov declattag Ae vatiahly spe usiva pullfc, ate ond Protecked Kequords. Ah Bock ws a sequence of declarcdions fcllowed by a sequence of statements, all sucrounded by oO _ byecces. : - Blocks are allowed to be nested tside each other. } Tis nesting Property ts refesved fo as block struckuwe 9 *y)Eypictt Access Control? v Clases e structures ‘Introduce A Ned Scope tox i Weir members . «Through Ye use of Feyooids REE public priveck & | protected. , Chieck ofented languoggs provide explicit conta joves acces do members remes rn a super cla. *Privede rames axe includieg only the medhed declarakions ¢ deftniions associated wilh, Anat class ard any “fend” dorses. Protected names ave accerdible to suloclasser. -Prslic. vamer ate accesible {rome cuclside the clams, e | < namic Score. 3 rami scoping the compiler fevsk seavches on ne \ode & Xner succetfively all the calllivg he : ee aka hoo me execution of program 12s | pcauesiray yp Patameder parsing meclantsins amag sa band Hey . mre. vital i A Program volhich performs leical analigis is heaved wacakion nedium Vico procedures 4Ates | the Coram | guce Age parameter paanirg. The values of Bre vottables from a calling procedure | ave Aanstered do he cabled precede by Some mechanism: To proces Mis, meckartsm, some meth |. ke cath by value, call by seference OF bah. and also Bete call-ty mame: WAKastng « Akasivg, describes a Stwaion tw which a deta, esse Vnvcugh efferent ° cure, seg locodion Sn rremony coe be acc suribaltic names tn the Progen. -4§ Khe wo formal patarneless can refer to the same \ocakion; such variables ase sath Xo be alfase of one anclves. Kase Arts + herteal analysts ts the proces of convertirg, a Sequence of charackers from source — Program ‘who & sequence of tokens. os a \exicadd avoluper (lene), Lokenizer ov scanner, * chemeal awaliysis congisks of 2 stages of PrOceAsing axe’ » Scannt + Tokernizadion. Read hata Tokens Dee eae t Neue Terme EAS » A> lextcal Loken ts a seguence of chatactacs Rat can be dreated ag a’ unit MW the Qammat of Ave progamveting, Lanaurages & “Tyre token Cid, number, veal, - ) « Punchuodtion Aokens Cvotd , veluem,. -.) ~ Alplabette Aobens Ceeqoordaridentiier operaters,..J shereme &s a sequence of chatacters thot comprises q “single Loken eq? {leak New 2 2G ots CUMWe Bde of He leet soap? Source Progyarn 5 Saas owaleped) actNedToken( ) sbetcall avalypes Ferforms She following tastst Reads the scurce prgam, scans dhe Sip chatachers opoup Wem Avelo lexemeg & produce Me token ar 0/P: Enters the fdenkfted Aoten tro Whe symbe| Aable, me? | _daips cut whike spaces £ Comments from. aolasce: poy: | _condakes exor messages ut the source Preyam hey Bisley esvor wnessage use As occunence by specttyirg the Wire swurnloe’ taes of lexical avalyned fs divided Into’ 2 Precemed: | Scanning — Pevfomms reading of Alp chotackers , yemoval | ok whtle spaces @ comments. {herted oxen) Produces tokens a& the ofp. Heed of Leta arabes ‘ Reni of design of compiler — We semoal of hike Spaces & comments enables the sytan ay | 40° efficent syydackic ceonsbucks. Res J comgtles efficiency is Impeved - Specialized buffer! a | Aechutques fos recdirg chosackers speed UP Loe compiler | process. Assucyy “tw \patoal ovallx's tentaetia)e atl a «Compiles poralstty ts enkanced— Specialized tocls FT have been dertgned. fo help autowale Lhe constwuclion OF leweal awolygess ke patsers when weg Axe Sepmearteel. Osea Batfedige Snpat b tert ao ee ‘ mT yer 1S Tea vam Part characte > | Nay cheracker. 8 ry f : Eo avolygey wrk Anke as to S0% of Ane | Corny Kime. ‘ Usually, scanner (lexical avalyres) uses look-whead with Qouble _bufferivg 40 wtinineze the overhead eA means one buffer Con toe xeadivg & second buffer can be aa chockahead fs vegutred to lectde uchen one token vill end and the neat token’ will beain. cherical qnalysts reads several chotactess these chatack, cabled as lenem, These lexem metched wilh Me patter, Crequlaa expression ov giarnmat wula) , once its mathe, tt genresates tokens acordigly * thes Aoken ack 4 tput for parser. wVheve Gre 2 buffer Spot Schemes {or leckeaheacl + Bolter pots «Sentinels % f° y (al Cus * a Buffer 1 divided Into% N-clataclers halves. LN. fs wurnbey of chotacless. IDA oY OTE vd half 4 2 ay Jek us tonsider aa ceds - } ee =a Seg “Tee boo paihers a fpand loreme-befining leneme sepa boegitg chereme begin points to the kegiontyg of The canon [erene | which fs ytk to be found. ie fForwoad scans ahead until a walk for a pattern & | T Scand fo her Acpasakieg, aise : ARC Now" j-Jalsle\ailiaey ya \ererme begining Hee kekers ater a, =/C, 4,4 gnervaded, i Me input bes News have Ni bytes, pub a special EOF wastes “mn the buffer. When one butter yas beer procemed, vec nN bates faho Yue other buffer half. |f) Sentinels ¢ | An Yhe previews scheme, each, | ywoid, a check tg done to ensue Hat one Vall of the buffer Agme vohen the'ep" fs” has rick weve off. S¢ WK % dene then Whe other half must be «loaded S. The evds of Ane nutter valves requived Lio Kests [for each advance of Me forccudl pefnter- | Test dy For end of brutes Taka To delew@ne hak dotactes ts read J |The usage of senting reduces the two tests 40 one by, extending each buffer belt 40 held a sentinel catacley ok he end The sentinel 8S a special coracker Yak canner be patt OF he sounce Preqam. Leof clasacker ts used at sonnel el teoflals et) ewe al Fo Recogaition of Aotens Iwas Ver a nw « Recognition ot tokens can be done oy finite autowela so Wot % can be secogytited: by ming whe transkfon ogee Oo Acansition table - Nasialde] Sdentifrer] constant / keyroord = Tokens can be wd Yecogntzed wth he, Velp of Arvcnsiifon Aiaguams. PRecoauttfon of tokens Cidentetters) leer a albl-- - tel Ala). 2 le AigA —s olshel.. - lq 1 ~ leltoL leer Laigit)# Aeveldegt STWonsWon Moguam, © 6 Reco Wikion of Kequoords € We cn use Longiion Bagims te vecognve Feqwords ~< Vike te) fleck double Beh Men, else ck, whe OOO+H B fe & ic R)Rewanilion variables’ I< Vke can use — (underscore) cok beginning, 08 letter ard _ Joker digit or lekker but cannot stack withthe digi ; Undesswie —> | ; \eher —s allel. - -(2\ All. -- = A alah... ; Vor > (leerforderseore flere atl ee of hike Spaceas ‘alo ee a ee mee ex Othe \extcal-analyner Generator heey We AAR shear is a Progam Mok agnor lexical a onliges MA ts used wir NAC patsee generator SL veads dhe Anpad Sream & produces Lhe source cele : olp Hwwough Senplementing Me lexical avalyser in the, C program, Funchtons of, Lent + Festly \entcall: ovalyeey creales a progam lev d nr the Jonguoge. Wher Len compiles suns the lex. progar and, produces aC Program Lexyyc » Finally, C comptes runs the lex.yy-¢ progam 2 produce iN an alfeck proggarrn a. oh, rorouk %s— lente owalzer Awat Avansforms om. tpt ¢ Srseam (who a sequence of Ackens. eke leg’ —a] cof | m8 anpet Sequence of lok ens sivean : Len tile forivat: a cA Vex Provan vs separated Who dee seckions by 4 ofo deXintkers. The farrroh Of Ler Source {5 a8 follows, ° Q defi ousk a hh drwlek hh Pusey subroutinesl I -Ddbintlfors Anclude declatedions of constared vatiable & sequiat definitions, ' Rules: Adine te statement of fom patacious petal | : Pafackiong Uhere P% describe She vequlas expression & acliond decors, € fre acon, chek aclon she lekeal awalyyees shod take cchay pattem Py modches: a lexeme, © User surculines? Gre awailiany, procedures needed dhe ackions. The subrackine can be loaded with, P dhe \ewead owolyres compiled, seperately, } Fike artlomaka fs a sole worline drat taker a | caving of syrmleds as tpt and charges ths state | sccordioaly | rtwthe curtomata “sa secogniter for vequlas enpreesions | hen & xqular enpreraion. sting Ss ; fed ilo finite | automata , 4 changes rs state for each \esal. At Ane put sive fs saccersfully processed 2 the | qukomala veoches As Knal slate, TE fe acepted sre, Hw sting {ust fed was sold fe be a valid teen + of Pre larquage in Vand. Mathematical wnodel of FA donsists of) | 1.2.4, 8, Ff ustere Qa sek of Fintke shater £ = sek of input sypnlds | Go = ivtltal shade F sek of Kral stoles | § = Avanstlien furckion(@ xs Q) | Tramstion Kaggor fer ace ova Bawquosp of OL awd 7H) edna ws Y 6 “2 20) QEror eeulat expersions Xo aulomalat Tokens | y | Requtar @xprertior\ ‘ Aeuite arcowahd } AR vee) JI oes of token r 2 m Dal + Regalos eypewion sa seh of shvings which also 7% fadudea these + Qwton) ov / Cunfon) = K— 0 oF more occavences (eos 4+ - Loo more occusrences « — Wneolerdion Eqgi We a RE fx fabh widh shattig ‘a! erdicg wilh Sab! RE = Wy assaryt « From vequlos. expression +o ones have Some melhods. woe efficied “wakine sHee DEA must be wvirfmived means FH sheuldett Contes, useless. shades. “AA can be done by hoo methods: §) Transitfon . block method. iar of DFA bmell paless a) Mini osieed RE NFA —5 DEAS Mobea Gy R= Bak Cthempserts construction) rt based ans sporteiaaton oF OFF De - A Reqwlot eAprension — \alb)¥ ab /\ Caoak? surtar twee /n b rluwkes We \eog nodes me Find ullable of each node i. : Find shyos of each vote Find Jaslpos of each ede Le Find follacpos of eadv node / N, a > iz , woe then Hsshpes(o) ladposes) 7 3) vn Men E 5 FivskgasCr) lastposin) a Node Nallable Faestpos(n) Lastpos() | Nolofe Tue p D Noleg(f) False ¥y Lik IN em Tne. Firstpastcr) Las\pos(ci) oF U NullableCcr) —{Erstposler) Nash pesl b> Nullableta) — -Firstpes(cr) Saskposcc,) U Q Nullaet,) —“HLullaleCed) FH GOallates) and forshpos(er) Jaalpeecer) °® Nhullatecer) —_UftveAgess) —_ gastpostes) else ; £4 (cy alse fen) Sty) Wh tok ee yur, ‘ey = se ish oo a « Ls Gi PA t% Ack o ee me WAY yh . j dh / 2 j a0 pW ek ao ae & BAL NY f YU Phy Joss £18 | Fh stpos(Rootmode) = $112,244) (Aca) =. Lat = Fopli) U FoP(s) FU AUSROL Ry : 22/344 Qib) = deh = Fore) = ask ® (BA = 11,34 > Fopcy) OU Fos) 2 W2, 4h —® bb) = 42, ay i = Fop(2)u Fop(4) = Liarshu dsqatenag ee Toh A ee a al ya tuss oAIB OA ; (aa u = FORWIVE SRLS) 2 er Seek p\P eC 2 Uh acl BR A ee = Fop(2) 24k Oe AS winingeed DEA for ven RE. @ Destan of a Lexical - Avalhyzer Gene reckos — AS ne, ok RAR shecal analyzes gerereclor ‘nbeeluce a eck called per, whitcr allows. one to spec Aeweok away ser vy spectiging reqular expressions to describe paces for totens The Alp for lec Aol fs lee Sawa : | » Struclare of Generator cwvolurer eee on ala Ley poyor >| Cougiles |°A lex Poyam ts) timed trite a -hensitfon table JO} WANG ; oF MS, vohich axe used ya finike ccetometor, | | Simulates sThe actions from dhe Input Peyam okich APpeat ag Fragments of cele bo be eavoted. ak the arp propriate time by dre aulomaton stimulator. A dvanattion table for the automedon, furckons ae parsed directly Abrough ke Ay he ele. Te constuck the cudowellon , we begin by salting each requlax ~eaprewsion pathan Mm fe lecprogan e Crverdig th, Usivg, adgpiitim to ah MRA. & RE sak R562 SHO CNFA) ". Podkern matching, based on NFA — Sf the lexkal avaliges simuleles on NFA, ther TH Much reed spd begianrivg, ak Ane pom on ts Input which we have sefened do ad \exemebertin As tk moves phe potules called faced ahead in dhe frpur A calculdtes ne “sed of shectes “k ts trad each poi ah vlnlleen Gk venches to ftral’ shade, i ts said to he accep\ing, wide there? use can dectde She Norges prefix Clereme) wodchirg some pecthenn, L DEAS for lexical owclupe cs — Another architecture, Yeserblirg he ofp ot lex, {s to convert the NFA tov all the patlerns rhe an equivalent DEA, “we can Converk “he “NOEAEG bo DEA boy vain He algorithms tohich. we have used &n FA. “ (we weed Lo implement the lookahead — gt alloos 4o peek akead, 80 0 read & re 4 dhe Spa ser eavee wothaut | pada ® a portion oO | ecually fowoarding We 0 Herzction of DEA a % @ lecadton of the stream, Raed mdlern welder’ wre ch at

You might also like