You are on page 1of 17
COMPILER DESIGN SUNEET SHUKLA IFTM UNIVERSITY MORADABAD ECS-603: Compiler Design Unit -1 Introduction to Compiler, Phases and passes, Bootstrapping, Finite state machines and regular expressions and their applications to lexical analysis, Optimization of DFA-Based Pattern Matchers implementation of lexical analyzers, lexical-analyzer generator, LEX-compiler, Formal grammars and their application to syntax analysis, BNF notation, ambiguity, YACC. ‘The syntactic specification of programming languages: Context free grammars, derivation and parse trees, capabilities of CFG. Unit - IT Basic Parsing Techniques: Parsers, Shift reduce parsing, operator precedence parsing, top down parsing, predictive parsers Automatic Construction of efficient Parsers: LR parsers, the canonical Collection of LR(0) items, constructing SLR parsing tables, constructing Canonical LR parsing tables, Constructing LALR parsing tables, using ambiguous grammars, an automatic parser generator, implementation of LR parsing tables. Unit- 01 Syntax-directed Translation: Syntax-directed Translation schemes, Implementation of Syntax- directed Translators, Intermediate code, postfix notation, Parse trees & syntax trees, three address code, quadruple & triples, translation of assignment statements, Boolean expressions, statements that alter the flow of control, postfix translation, translation with a top down parser More about translation: Array references in arithmetic expressions, procedures call, declarations and case statements, Unit -1V Symbol Tables: Data structure for symbols tables, representing scope information. Run-Time Administration: Implementation of simple stack allocation scheme, storage allocation in block structured language. Error Detection & Recovery: Lexical Phase errors, syntactic phase errors semantic errors Unit-V Code Generation: Design Issues, the Target Language. Addresses in the Target Code, Basic Blocks and Flow Graphs, Optimization of Basic Blocks, Code Generator Code optimization: Machine-Independent Optimizations, Loop optimization, DAG representation of basic blocks, value numbers and algebraic laws, Global Data-Flow analysis References: 1. Aho, Sethi & Ullman, "Compilers: Principles, Techniques and Tools", Pearson Education 'V Raghvan, “ Principles of Compiler Design”, TMH Kenneth Louden,” Compiler Construction”, Cengage Learning, Charles Fischer and Ricard LeBlanc,” Crafting a Compiler with C”, Pearson Education CHAPTER 1 _\AITRODUCTION To_coMPiLERS 4A_COMPILERS AnD TRANSLATORS. A 12 @ proyam Tor Toke aa ee a co Ge occa NOD opremnmnung Language Cha. aouner Lampuoge) and py amd produces ao ¢ suk op pyosxam. Am omsther Long Che obj ject or : Sy he nouns da toet cee hens a FORTRAN , coBot,c amd ate Le wate § Louel Lams Auch 42am OGe ON ymachut ea Them auch a Tranaboter a> caticd __& Compiler © __ OTHER TRANSLATORS __ Gillam eter Domalaler bomwfevn a gee Te ae a propio ‘caltad vl sh el abiate oaks Seonndls z a cemdeoperding compiled sbject progam . 2 There ang Amwenal on ie hs adie Sb ae booaideo campulr> i on ae er yt or acgumblor.. 4.2 WHY Do WE NEED TRA! ETORS 2 Sean etn with a can, 2 | apes | bine ecient opehations . Gm Ses _ page x el mor Thon a OB ands , pro) yn a0 Bc agers | Cri Fis coal a agree ie ree atrodw veconaag ed coding vv theta poe en Ae a) wn a. muymviLe Not en 19 scl) ga eager. but it also ban. diva post bla say. AM oO Comvenrent manna , S/MB0Ue ASSEMBLy LA Borouan 4 Ds dikes 2 ms machine Language Moak vmmmooiialt Alip owtoy- agit Aymbob-e acavmbly tango mhomenic vediea fo eth cperdlion cacleo and dala addow Sn anoomlly ADD tee recht Law’ otto onto O10101 m ehx oy Feoprann avullén im aoormbly > aogumbelor —> cenverti To macht omguage ok \ 1 & EB ‘ a y TPP POP RR APp2 LOAD ADD STORE _ENDMACRO HNGhiaL Pet LANGUAGES mek, rao ron Darptale complox open’ (tive 2 a cin als A eee | a grees ans weer cmUixcacken faa oe a ; a aa sa a ADD X oa High Roel Langan CHL) S “CoROL, pois PLT, ALGoL:, SNoBoL., APL» PASCAL, 1 pigp f ae japon ______, but we Toa) a an Kamadegous ts onze.) | Compilan "mens cope een campus vretl UEKS 145 “THE STRucTURE OF A compPiLER, Vener —> Compila—> oe, as dn Complex comaidorad mehemaoe orabpprace nnd |_phaaco Seen sa tl a Swe Program vnamagement Se ae 7 Ea J is eee | wy: |. gentiate ”n | Mi Taagel f Propawm Fig 12 Phaneo 4 a Covnp len i Lnpicat Avelys er Deamner ee i : chorachees f Du source Amik | cep acess qaaup? : UoualLokenk ons: Koyuiondo auch ao “DO eri 400 Soaeersai econ haa XL NUM es Luu 9 <= Ort plonclialian aS Ez os bition > sia “Cutout 4 Isxscal analy eas cma Sf Akews a ies ee panei te Ua VaRE pha praia) ‘i 4 a bre ott et cae asl an additional ruvmlsr (ahith Wontip — +B- aie Cae ee re : a | ter dros? no fies (: The prumony cuisferoncs bahoeen dulinoos Sy ANGIE CE EEE Passe 4 cee J Bupha AAR Cocle Optimization 6 fas opbieal phaas oleoignel be umprove. snkirwradielt Coe = Ao thot Te ulfimali object progtarn aura frolin a amndl/er Later £e0o “pace Sutput D atk nti ee ae axed Dr ouve a Thet paveo sven tele aml sigs re qemnalon Ural produces : progsams —> moat . pant Belen) et a nes The. com pl Track of de. names ES eel endemliat ofp Me eat each, Aucha@o oa pe ( amligenr,acak , Se Tia dale. dluclune uaed ps asemel Tue unkeurolien Ly caled a symbel Table, Eder howd er Guutked & ET, who a loro on Uw AOUNL Pr progam to i lolacled . mmuat warn Vu Lak aes by % a a erie ae avd ee” a ap = erorbindliny = fob Ds eae ok a D> jeu phe combined hide enc et 17 Pe A20D —> ax MNO % Bes eal 8 spa AOU pr ns euniully out} — alah “age fi nol pheor pauped Ahan Tas. ee Le po Lt ee Ia a atinnaling 2 peaaeanel pheooo ae Miao pans can len com be wads th uso. ia ce Lam a ile} pass Eqmnp ler » dimer Ee pace “ated by The aaet pro ferenc pass cam tat — “aiaaat tla ae vols pars Comp. sa eat eae cee neta 1-4 LEXICAL ANALYSIS 1ECS.£Q. MAX) Go TO 100 = Bgnt Tsien: les GS. EQ. MAX; D5 GOTO ; 400 iT ow wD a Tee tava of olor Se ey ‘< only src ete 8 ere ae Tokon Type zon a Token —> a i nen ee Qoks fry next Lokoo—> Seater: xk kop vig paren anAldb The value aes abt oe anal pavoco crde & primliz tn Ube apymnb: Hable | Saas | Example 1.4 IF (5.6. Max) GOTO 100 ne upto ( scanned | paras, ales for vexk tokon | Noade S,.,EandQ , becauoe S.E-10 Rea dy upon dae, o y nafunned a token dmpul ont “oo poortiones at det. dloten Lype : conalant 5 mumoucad valludsS” IP C Eeonae , 241] ug Lid, 7292) goto obese | Od hocond Component 4 de pour -ndox uns aymbat lable | es al | exp ZT 344 [oor een valu | +— + aa Fiy 13 pease 554 = 100 ale tres addhtsn code me Ae T2:=Ty*c A ali hu ancl uncenclibenal and An valamediali famgsage.—> Y nent oo, mento , ee At meatent /elalimn crtosted Li i = aularninn whalthar. te branch . tshule-clo ov 4 Uwn olor an tranokalid ule Uecaddy Abwits Example 1.3 while APB &A<=2*B-S do Ai= A+B; Lit af A>B gobble got L2 “ 12: i= 2B B= TS Y ASTe 4 Gis 4 At= A+B gee 4 i Fg l-% Dultrmediok eode for whule Jalunent {O i ih oa ZATIONS Chyact prosame Chat ant foquontly oxcculid ohauld fe hil atid daa Corton com howe willum them a phose Tak Guip, Lo apply eunddians Tn Tne oudput % ‘te Dalvemediols -cods' gentraie am alkoompt Ay preduce_am wnltimeciolr-lumgunge vOrinn a eaunce progiain fam ulhidh & faalit ot amalln. object a Seapets —cam-ublirnd Lely ‘oe produced the pe Seapets organ cabled Le oplimization pracr. eplumizalim > vaionermd how = net Du boot df eplinkelng computer > dail Tx apied mop) ASB goals x Chay Sapiens 13 Aaplaced toy maint Uoabuetians Soquonce {.4 on the ofhar hand i Covapane A amd Bt Dur fix condiltin codta ard S. Jump 13 4h hy cole-fr sana % att. we QoauNet APB in Lut halp Da time, Thm | C7 mee) alt the me et SOF i ae GB) bals The fume, 4 an auenage. 2S smnébuchind. Fer (1.4) we always onttult tive ietianasiniial ei Uotuetion, a 20h Aasungs . Aloo, (1.4 provides | Bi a 33% pace aowuny if we crudely endures Mok | ' all Analuchoyp acy he pune “pate. Avstian cimpetlant Lowi imizalion Ee Zi A:= B+erP 1 : Ex Btetr oo be cvelualed ad T= Bic T%+D , Pas Etat, ceramen Aulaoxpredctond One ralaLurely Aan, het tea ea 1on_Avbexprossion x es 14 A ec +CCtd AL deur bytes pr werd Thm 4#0 0 cn Fach Thee : splumizuna compiler com modify The oe = eS thor 443 1 at ouly. enck . 6 Net posaibls for the propane by apace, : address cobenlolion ana niet oxplicut : x Legp Oplimaizalion |, Ape 2 = la j je cpt brat produce Ua parm feaubt | = Loch Lamy ‘dhe. Oop by fuat afore Te - ee x Such a campulilion 2 calihd fey smn a A meu 32 4.8 cope @ENERATION S aa congas fia anlmediots cede aba machine inatuuc ao ASS. G. acum coda LOAD B ADD © ——SREA ae ding fp Axpanacn say ao -peduaa a rate pac & Beaute sg ODOM oe Oi; conju 4 sae = pce Uo ther ag pee wily ewer Pe as — alin allacalion 4D P i ee nin: “tr ie Pid rade jf Brrwee eis fl 95 Teco a mt TA compllin vaado fo catlut onformaben abook all Th =a hoe The unis. progr fe" or 2 conn nal brad an a van ele das, ee ee = 20 toh taut ef ps ee fi Ii ee Sl 4 gene Ce oe Tha. Imfromolion cotaclaal adlessk Th. dole. oboyecls A ibe axpuasiien tah FL ox oy De HOU 5 4 he exprosais sin fre a coal i4 a hoe eee: a cod wwuwat be & emt A a eee es a = Ly Atal Ou addihim can place. Tar! : yu don oink, and Ms oad ee pee be 4m ae The In Sun am \ 40 appliid ke Un dolumipalim f of te Ly pe ‘Aiaitlb | the. chack That | oe Aypeo Thet Aagal pr am application E eistad IF eauld clonal fac aating add, —|— 22 petag ope amd p pourbly olan ieee aswell) _| 4a. Nn fie, i Pt ete “wat “code genenalien phase . as Sees = oe 1.10 ERROR HANDLING Ow Te meat dimnporlamt funcliom oa compuler is A 1. amd Acpyilin: eve im The AMUSE. plogsaa : Tha Ore. wean An ally De propamm, dot mnint exactly where Te Drow have cecusntd _ Ener cam bo encounlend by virtually ak of Mu phases a a compilin, Far 2xampte, y 4. The Bextical analyzer. may be unable b precon} + because Un voxl Teten 1m Mu acurce Ppropam - ” yalsapalled | =e acting Sart bare as a Shucling 4o1 eam brcouae d Ayrtheie : Drv veh ao a ko parmbhoera Aan ecurnrred— B. The unltmediale cede genunater may datect an Bae Speier whee epeunds "hae Yaconpalibta Aype 4. The code opbeuizer, downy conltet Lois emabyato mary es cloteet Thal cortavrs platiment com over bos weed, 19 is oe S. The cake 4 fund a Coompiler-crsalid constant Li ae That the fange tn tn «weed Oh Cla anger machin, Ts. Nou 6. While enlow alum amie Aix aypmbol Talbots , ae ese mi ina rneay LinCCveLGn sdeilifean (77 Was a laadic encarta a lay pre i th e mon EAS Cea Drer. feast add; a a ie ae ot re no as well),__,_1aa.1ie9 aaa Mi woe has bum 5 Steet apes aa peer ee ae eon let Ie rf ahs Heb Sette re cousatng "i | ampul , _ Anoksing fer aubasq int m a flZ 10 pein SEES EEEEeeeneeeeeeee as a reentry Ms pa" capi. 0 cans Ly Bask Lamasgens TRE e +t act tugiog so = cord I : epee 2b 4 Suspller am Thaw Lamguages vray abl le pa oar ret areas comp ryan an wa es tai ie | ae isoprene mp. iy 22 ee omd Prat ree Fev Tet tn 2. mochint .

You might also like