0% found this document useful (0 votes)
28 views30 pages

C D

The document outlines the components and phases of compiler design, including lexical analysis, syntax analysis, semantic analysis, intermediate code generation, code optimization, and final code generation. It distinguishes between compilers and interpreters, highlighting their differences in execution time and code generation. Additionally, it discusses the importance of compilers in programming language design and their application in various computing problems.

Uploaded by

shiva751514
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)
28 views30 pages

C D

The document outlines the components and phases of compiler design, including lexical analysis, syntax analysis, semantic analysis, intermediate code generation, code optimization, and final code generation. It distinguishes between compilers and interpreters, highlighting their differences in execution time and code generation. Additionally, it discusses the importance of compilers in programming language design and their application in various computing problems.

Uploaded by

shiva751514
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/ 30
jaloul2 2 ‘A —- Fl 09 “interface between too lan wages ram which bakes HLL as Into low level languages. compler ‘ Gn g4 terms => Com wee IS 0 i ‘ip and translates 2 a Att 6 parts AD Compiler design = 6) Lecal Onalysis 6) syntax onalys's () semantic Analysis ( Inlet medaile Code generation (9 Code optimization © code generation lon vag e ¢ anslalor ‘- o ad lee 6 Tints pret program i Sel of a parteulay problem “nstucton perforro or solve Surte: iad ene level langaage sare es Compiler — ee eure 4 J ss low level “Pl e (or) Tonge Prog rany tee ct, Cobol Cuses Grn java, python (uses Enters ele) s TN > Compiler also ueriffes dho error Proay arn. source Alncompatabilty Staclemen!s which are nol able to Convert ‘into lous level language ()' ( Paid byte Code Sour Ce 5 Interpreter, ~—s Proguam ‘ target da Difference belween Comp iler and Inlerpretor ~ 3 G 7 Compiler Anker pretos ; ~> compiles the Promame > exeuiles Boe al ao time °ne e “I > Compile takes less —S lakes More time Lime > will enerate Intemedrate ~S Doe sat ce object lode tntenmediate object Code —s i is Machiene independent Coole > Compiler generated Code ° S machiene dependent Code => puis are ae for > Req ure fey time, execubon ot ins buckon i for @xecufoo 8 ela t ov NEe ° | oth wee oH 4525. Some ri inshuct OD becau se ONE programs 40 Conuerl tk generates byte ) into object Code A) Code dutdmg beall Flow, What are these othe: Pro Tan $s required | Lo ronvert — urce’ Code ‘nto’ objeat Code 7. AT Te ye re called as Cousins of Compiler and they are Riled Ou follows — ¥ pre - proce ssor * loader * linker ole y des 2 S we need +o Know Compiler 190 : ° a . KNOW the process of Com pila tion S Target progra Source Progra bonple] large p q a Exror mtbieae How te ‘osbuct the compiler _ ¢ write a program Using O progueming langue e hgh level ‘abshact esotption S hegpmtesio, talk Jn absnply pia. + low-level’ implemen tation detals program ae tongien 2 Compilers guege prgeamong tanslaton language 7 ; * Input tp the Compiler. — standard Imperabve language Cerctt, java) > slate Cvatables, Stuctures, “Anays) > Computation C €x pressvons ( airthemete, logical, etc) Ryranment Steilemenls, Contr) flow ( - Condifiona) loops) , procedures) a Output of Com piler —> state | ‘Peagtsters wth Plat Addies s. : | me moe ow 0 | * machion, cate : “h toad! store architec ture _> load, Store Sn stre HOU = avdhmete ; log? cal operations iin structions _ Branch Major parls of Compiler = J , takes O pw A compile SO prrgrans a | ge and tran slal es toitlen 9 -sownce language 34 into equin alent prograro iD a beget lonwiag SourlCe pryqram Farget eee fs} ype | ST” Compiler . There ave two majo Parts of a Compulee: Ana ly $s and synthes's a gq 2 9 => In analysis phase, an Inlermedrale veprosental: ts trealed fiom the gives Source prgram- # dexica) analysts » Syotar analys?s and 5 Serge analysts Ore parts - this phase as => Jo syorthests phase, the equivalent target pregsamn 38 Crealed fom thes witaeee pale. representation . , 4 Intleunediale Code aenraton, ard code optimgation are lho pals of this Phase: Sou C Progra y exical analysis J tokens: > atypia 1 Parr burs hye man tic eet we 1 Qaur te Mw ON gate ' met Code - \., q inc tb : JAc . epnrto/ 1 tac Code generates L , target Program phases of 0 Compiler => ach phase "transforms th 2 Source Prograny from One representatoo “wtp another vepresenla bon with erp, handlers = They Commun’cate Sy bal table <> They Communidale with dow points obo about Compiler r > Compilers ie i level progioning Tongua- es -Ore amon larger and moe Com plex suftioare and —oriainal languages include - for boo Cobo). = often poulligas Com p #1" (to facilitate , ‘ memory vestue) belte 4 lompiles cle veloproen't helped in eyraming language desgn | 4 iq ua a eng - SS Carly development {olusser” On yes Ona ly sis and opbmige action- => Commer crally, Compilers ase developed by US lage Software gos = tunent fas ts an ophmz ation and Smort Oh ve sources for worden BSC (reduced Tnstruct set Command ) arch*teckure Othe ppt eiona * In additon “the develop ment tf © Compiler the dechrique used % Compiler destqn Can be apphable 45 man wblems 19 Compiler Science > Techiiques used in a letical analyzer Coo be used 9 tet edit, Snformalio vebieval system and partlern eCoani tion programs —x Techniques usecl “9 a tan porsr Con he “pal ina querd processing Syr tem Such aus A mary Sef tw0are hauing a Compiex +troot and "a Need techsiques deer wy Compiles design SAS 1m bo iC equation Soluer which sla kes an equaliye as ‘in pull she geyer should par se lhe ae oudput eq ay mot of Ki ‘techniques ted Compiler deniga: Can he used in Natural language | Proceving Culp) Syptems- : | rey clan Compiler { public lexical ©) Syn tox) Semanticc) Tntor todo enec) Code ophc) Code gene’) 6 Lexical Anal Sst : lexical. Bie reads the Source Program characte: Py characte, ‘ond returns she token of the Qrmaram. eIL is ditided ‘wl » Sequence of forens (words: stan eh : * A token’ descnbes o pottery of characlens hating Sothe ‘meaning 1 the Source pe aor Couch as “adentifies | 6 perators, Keqword L delimneters “So 60), : & bre (0 identfers (9 operate» (2) Number : @ Kegwords @& Syen bots tx re. New: vabic. old val 42 SS toe i mew \lalue i dentfher ‘ f= ASSiqnment, Opera tos old value ?dentfc u ‘ add operat» (2 a number = Or=hic# 5 al=lblelel4 Ps boausc + ost KOM is “he * put itor ation oboucl “dont fien InN symbol table - gong 4p Apseathe oven Sn) # Regula ex pressrom < +5) . Genego Finile Slatt Automata %» be used 10, Ahe ‘implementa bn Hen nia Analy 30 ext Ashtta BO as lexical Analyge b idx . v idizid, tidg kee ia ACaszb)y. © tdi Cidy sa id30 5 la suceH idycidy -tdy i a-b ~ else a x . fi else id, =id, tid acath tayo tia ly 4 no & token le @ syntax analy ger - * A Syrian ana a treates “the syntactic Structure Caenpealy a par bee) 4 the gives . Proqrary L : +* A syoton ana lyse y Ser ‘ i Q syntactic 5 tuctwe mA. par seo tite decides 4 also called a a oie a.ssiq. stmt a OO ‘dentifie ie ex preiion pew vel . , Cxpresss expression Tt . K pression ident fer mumpber va “ts old val G ’ veer Pov se tree _all terminals, Axe at leave * All poe Noda are non~ terminals m @ Context free gramme ey ar = ial Ss id Je as 25 7 . “ted ed * The syritax of a lan uage Ss spec e 4 Context free grammar Cera) Ee + Tho mules inva CFG ae mostly recursive 4 4 - syntax ang ly 3er Checks whether a qe? program satis hes the rules 1m pli hed ee - lyzer © sof it Satishe the syrilar analyze eo Parse ee for lhe pellowing program Cx we use a Bal ( Backus Nour joo) Specify a CFY ja ? ass ohn » mined fier .# exprenion ex preston —s aclen ifr Cx presioy — ny m ber a eres —_ e@ xprevien + expr enon % Analy Verius lox cal Analyier & * cohich ee of a see should be Boi, sed by th lerxca analy we Land which | by “the suntan analyser, 2 => Both af thers do similar albing : Bud the lextcal analy ser deals. with Siriple — Non ~ recurswve “constructs Of ‘he langua => The syntax analyse deals torth recurve constucls of the language = Th lexical analyse Sim pli firs cthe job a the suntan .2Palyser- => The’ syrtar lexical analyser. 1 QPBU she smallest. $roaning ful units ¢ toxens) A a Source pr add : ; > The ales analyzer Corks oO» the Smallet meaning ful unrts C4o Kens) INQ “source » poe +5 FeClognige reeariing ih Streietures > Be Sun 0 euy repering language. Passio techniques eG i> ®ependin a) how -the parse shee sta © Ot the ae and — prteeds: towards the leaves ¥* Cfe cent” top -dews Par Sers Can be easy J _ Top down Pasin ~_ potlb™ YP panih ~ Top 408° pasin | > Cons Hu ch Gn arfing Starts at the root and preedes towards U the feques Ly effecent

Relursive redschve parSin predictive Parsing ¢ Ut povndh Botor uip. paring + | = constucten of the the leaves and precedes towards effecient bottom up Parsers are holp of Some software. consbucted b hand 4 he easly non - Recursive arse Wee Starts at the root = Nomally, created twith the ool s- ; 2 pitorm Up parsin es also Known’ O38 shi{{- reduce parsing: dence parsio simple, tiny plement eral form of Le, str, Wale. — pperdlor— prece rostictve, ea to — LR parsin Hench gen shift - reduce parsing 9 semantic Analyzer | Ch <= A seman tC “analyser checks 7 oad garce program fer sap oN the ° informa #6 y calls ihe “ype Code genesclion : ee Types check Ts an ‘important port ! Semantic analyser S SS Nlonmally — Semantic 1 information cannes ted represepted by a. CFL Used | Sy otoa analy ser Ccrq iiged ay sho syntax | Analyse Are ‘integrated. with athtbales CSemoy, =tic rules) me : * the results tn a syntax —Areclid trans (aly *® Adtnbale , grammars: : _ &' New vals bldval 4 12 ; * The type of the den bfer, neaoval mut math toith the ty pe | tho expression . Coldval4n) ’ frat Gebioe rg! idte pay tad “LC : JN AX intte real OR if m0 ual ¥ id, ae oo ia el . /) TR coe Te | idg 27f Cais) intermediate ° Code Gene ralisn - A-Compiler Prrduce an ex phat i aleme - diate Codes representing _ the sowce propor * Those intermediate Codes are generall Machiene Corchitecture independent) Rut é levol a) intermediahe “Coder 7s Close ty “the Level sh machiene Codes. . i | sant 4 wrote ag : ———s [rp] got] machina Ox eostable fm) Three Adven' cods Tae’ ° . ae Understandalsle oon FAC - OP11 OP, nd Ops. ‘ : vdie tds tid, € 25-0 Phase tie mE to veal (25) Paw — Siboprogr bee fda #44 tne alle 43,2 .'d,+bz idi = £3 gern MELD vali= Oldval + tact +1 Tdvyctda 434) 2 Pestermediate é L : ~ Mult idz, tds, temps. . Codes (Quadraple) ADD . tempt, tri, temp2 ey Mov temp2 ,:d a a 5) (ode op fmiger (for intermediate Cod € The Code optim ger 6 Hmize Generate produced by the intermediate Code generat 2) the terms oh fine and Space tpeidg tnt ty real (26) - td eid, £6 bet MULT ids , ids, tem pl: Rop tempt, #1, id 6 Code Generator i— . produces the, . target “Langucge “8 9 petite: architec tare 3 Fv sarget Pq? > vs is normally _eerprmerreareene a mm ( ZZ” Zz re llocertable objet Codes: Ex @sume loith insbuc tom File contamning machione that we have an Orchitec lave tohose atleast one of it : re ste Operands ia machiene , q ) Mov tdy a MvLT idy ,p, Cousin 4 Compl, Rod Hy Py ‘ Mov R, 1 id, Boots tap § Ho 5 a Cross Conpilers ‘= ‘The process th constucbng Compiler ron already extrlung Compiler Lo Nuo aerial execuibing on & = epee 4 Ax ' NAO Program | spl. Bootthop - Same as C055 Compiler cd, Ape: ny 4 at tL Shuc ture + ae Lexical toy Nao process ) token ow dexital Ce 50 tnd, ——s p ue Pray Te to Wale” Dext toren( i : Nee Program . Z “Phau Pye inn | token, | Le vine Seon bel. tat Phy t | > ret 7 “ef de LP? aj, hexiCol analysis — pattern Caequente of before of poctero ts WP. 4p: taxioad anal; ate match’ wh lexime. that 3 oulput ‘yt eaIme = token (i) Aake “Ip Sdur@ (Pepe - (iy tdentifier tokens. (ia) ql Next token ¢) to get Nap toKeN fo devicol analysts . (") Suning Lenicoct analysis any enon ottured shose A Hot retogn' sed. ‘pput Butter — kwo schemas 'P lp eT ETRE Pt 008, * Before i it ibe} oe oe stores tn bw bacs “buffer Con have ‘two poiwtes 17 + {oly o* Cpty i - ~ . a both vee are ee at | t PPR PL PREG 1s Apt tog I “Lexione- i Cptr in A u wt oY ww sink 4s matehing and 4s consicleree ¥ token . a is net matchio os i . “ a y. sdenti fe a ts conpdered as Sd eakefiex Ss ¥ oe Cade} oe We load Instuc FS £pb An cremer _ = At ts nyt erasable - The toshuc ton roy i CWeny Ite 3s cending with cof Cond of KBs less POF also called as centinalls P-Bubbn schema Fn this 2-Budfer Séhema, Whey the Spb, eph read thee of previow, ‘inshucba| antl reae Ore stored 2A ‘onpthe bukber Sy the buffesing a nehen 107 Sch ie an cthe when the Fptr, cp reads the eof m . Second bu-ffer . the “ashuction are, Stored » the Ftrst buffer. Vitae . soit Ao iyplonertiln 94 Soput A eying - Anpul Sourle Program Qs See ot tcl PCJ Oulpuds tokens CJ elses i" pty ef in] Recovery piste Autor eww am O Vakous Po rammin trans! 5 S105 state @® ‘it the 1 Gpitalige °-f hoo cpt ? oes J P e =< » her Sone gaa fo sbuction into frst Bu ffex. + n . yi ston “45 lereme ‘then it S olad “eile 93 a transitton [ nq to ess 4 preg oApte kept suste AU a - e| Cphr ave readjusted . 2 aie : are Ror ao ; Aagram "tibem eft fp by his , detectec * until end of program C we we-'a b abi ger abiv sk ; ; So dont si ree 4 else if" toy ‘ JT Ape point to pent theo ou ut 8 load Tnshucktons’ Sot) Serood | “buffer .. b re q. tpt Fnceomented, by 9 : 2 of ip else Tf 4p print te Seof. then n y 1. pad Tostucton mnt finl bubbe i rp Fa crement ed by I on it tpt CF ptr ty cunt] pCIe— tof lé- peluro TL) 18 9 lex? - _RePlacing , interchoog peroutry Shaleg " fidile Automata lor ‘identfyin the Tokens 1 va8ous tokens comets Supported | b ~ she Progromming languages will be Represented al fanseot S105) ° diagvoms each will have sate @ it there “Ws .4 folure ‘in ove tansttins diaqia -™m » dhen dhe fpr 1S reposit Honed to where sp the Start state and. the next yA has s3 activated . Lransttfon claqnar Oa ay Te rans -Tailure Occur. %» all Aograms Aen a lexical error has been detecled and ‘Mvokes an evo? oe sbily Algoithm for. “orp. Recogntsin STnput + Source programy I~ output: Sequence of Tokens ' Gy taltze pos <—O 1 looxhead then not . Chay + get cba C prog vein) Avani tien Token Kons. f- SEG): ee et . ey a Alo thead LAalse file tue 3 Repeat Stqp y (top! & sorteh char Ci wrt ¢ we , rer gig a3) Fhe : repeat while id a Chay wipe Chav) elve tiger tp se lookahead 4 bue ; Loken a Divs Return. tokeo Case i Rn =getchor®, rye cha, is‘ token 2 Leg else lookohead <—True * ; token UT v . zeturn mag Cose “p" 2. lookahead = bue tonen ADD: ag ' (Case 2 Mtokabead + true By + tokey = mul : Case 'e! lookahead = fue; Foken. ee, Symboh - i Upe ‘ har = gete Kaa (Soule

regment solr bing hu chin ‘loben doy deuce! vonabyi tohen the piles ; CP: male "ng woth — clenime. 0 jurillony Prceclue = The methods that am need My the orfions. One dpetified in they fee tipo: > (ny { lab) a ram me ‘ Dot ti It cdeclorotion of vartobler and Constants T ,Q%, tea, Geo, em, ASS, THe, CSE, ip, 60, NlumBer / do, RELop + | aye 5 [# Regular Definations * } delim “Clo HJ id (Cdelimy” letle (a-2A-2J digit (0-9 id fetter (letter! digit] iy nuro (atgity” (\. (aye *)y2 ‘heh Sto floating priate the Spaces and delimeters 15 poqen +f i ee ws f 4ynore : L dvelwny i f tl-[a[, fr { retun op } 7 2

    [>= i. = dred un “relaleonal appercin / 1 yylral~ Ynslall ¢lC)* id a pkey [OS ee pd | IRE Nem, { yglvatie -Fntall— numlyy 7 ; Sop ¢ aie evra) MuMazc velura Crum) + / a then A doh shoud an “install Jar) entounticie® { procedure to ‘inital Wemnus whose abpde | > som : intd 40 yb fortand whose long Yuta en - } op he “gl i f » ond Sok a poate Pe 6 Savall ante on % Np below the iy panic ‘rin pod dono unter in Be | J “input — U ! 1a 3 ae _ a dy val — a tivd te Hove Ihe Yala = Aled Ay Te methods weol tn. dhe Progromme 1 tonslaluen ’ ; Ch) Del Achemas . ~_ ‘ Ii (onen a aint — do fi i PM du Ano. : 7 : oy _ tu pe eu difling ~ ad to rtou th Lonalu be | ugh ALYVUMb, . Fes feos “0 letcal, onalyiis aid In Lex? ral ondly sis Phase “aohinue “ils Oper avluss whe even Bh tncountuw 2MBL Sing Ya gd ic ihn du unable ® | 4 [rol because None th pallens ho | Torna machete ao ps of the Aamounin’ : <4 >, —_ Ss dng p fee Moy not Ase geting dhe eyyoy mumag es. a when thas Slaton occurs the lexPcoul (phos show!o dorm the. Ser aboul Ae errors encou nku PY 2 rap dhs enor reCove sralear Mol are being | ollowed by thin phase aw litedt below iy panic Mode vy Oelele Succontve choractes from she -vermainin “input until it Can find a well formed token. Ex ort : Should mMatrhwith pall for: . (i) Deleting a unnecessary characles ‘~ 4, lo charader of the Coming token when a Le. be unne cessor and, this 45. assumed 10 Q t Can be used (0 He CaM for ane ch) Inserting O renin chara cl a Ansenag O mre, - Keyoodsr & wher) — Cormpased “oth the att this "4 Hngle choracter ‘s rising fon he used. ; jolewk fie Bie vale on i (Hen ts bul Of povonthes ( . style — a _ rack b> Repl ting 90 nec Ghar ‘ _ @iut > thin i tharadlee When token vibe fico 0 Loe Wing oad ho han 4p Worth Conver f- | Hee Ave AL char fe ™ Irouspoithon f oe fus0 agin” e ty ofr C a 4x0 ( er * : gar Content free (ram mat § petliation b tree (md PMD: _> Amb uoll G rcmMar > ory fee niques “op down parsing < Bottom OP Recursive Detent Predict e Recunive prediche y thf Reduce hee UR havea L Str U clr UALR Cylon Beolists > pole of ee on >] sumbel fable yee Syntax ae Seroon ti 2 a Gal sis Analg | SN tenant a Y oe (i kvl i Cry Bua — locondict % hon lermash | his A thy oh. if tiny PP we, Be cau, g frrammau we (an gel sLifh evel ‘y Leen tine comp eaiy Pnvreaner Fare ay at thn Grollins white nr, b ° te eetiemua ll wept factory f As Ax] p —xett Poumon iy 4 ne es. Akt tun) thon Pht 3 vod - omg Spramrnax CA - non 4 Rip = Xlym Among LR ynbodug avo vovable om” A-sae|e AS pa ‘A Al sup! e ~, v equ? /y « eliminate dd recunion fro" fb?» rar —-E—serelesefe-clid E-Sve E53 eee Elimination of left Reta vi0n CAN i6~¢ Mot hating left Rumon Evid ( —>(e) S €ssd and es chy Adol Neu Non demi nal cy Ss. equivalent € —side! “hom hiprice, rem m > Ceye! frcy thon Add el Sn all othe, Prool ei +ee! { ! , €- 3 ¥ te : feet yl | ae : Totele | e 3e@ ‘ | f sid loo di) Es 47/7 LL T > Teele ) p> Celid - rot having Left rOcuvioy are peoteHid For Tor a add symbo | reyap'fe €—> Te pes afell ef eemove Fly Fo cid . brit prodir eae ' , a) que) Grammar 1S os 4Te le / T-> 4eTl¢ Fo ce lid Algor fo elsminaton 4 et Reyer ; #, SJ L and ull product, pPif cprammay er le tan gt Pel ms mole Le*! ‘thin in i y without & input a Ca free Grammy roductine ou 5) bog ol ene owkpeck ‘ equivalent N gremmo cormorrl etuuvon : bY. It dironge the Noo lenmnals of the 4 on Order ob ct ntey Pree eeitiia? n V | A a al producron varable Stat) ; OO fina yotabte to te tt n Oe nei oy Slorhn Sin bol . axieal for i 48 040% Br ft tp fone l? Ve bs lor J ni 1 £0 : 6 uf. Ini Hs Replacin each pductoo tn / ( dluc Hons A —> Aeok the pe i> Balan [pa | ighere A> Br [pr [pal fa Bh» Bots 1 ep end Bt end (of inner or (op ) _ & Eliminate ‘inmedial ¢ deft ner A, produclioas that We cn Wnt at fighe re Ap among U hy pik [rep ern a > «a! |e 4 Chd Cef oukee hes (oop ) . dt ractosn ie ip the pemmay “ny he, imme AS appa Bap! al (Buf ~~ 4B Whore Reo ~ Ay ave non Herinads ; € 8 lerminal than gremnar v Called as MPG Flitminahing UF A—>af! cohere As Ay Aga _ | Fre flimindle pl fas ho " | AE Baie pt polbeuse i) “prema Fob Elimination 1S cs feks s! la ¢ 28 eslers|etsesle Eb: % s Produchions gusietss la desedle gis slits ]4ses sstetss ss es'le ls #5 ol 1 < bowlee le sls es E>} am gy anbe laabe. ADE . s— Aalb 5 climinahe (R a> AckS sa 'E 4S [iets ligtsets/ tH setses es pat co ~ Ce 4 ~then Cele s—sitafe Men agai alimina Hon becouse @ 13 matching

You might also like