You are on page 1of 42
7 * Compiler Design # wo Indtvoduetione Compiler ae paca) translalors. Destgeshg ao Compiler fox Some lanquage is a complex and tune consuming process while | Studig the subject compiler] iw te necessary to understand what & compiler $ hovo| the process of compilation can be ¢arsied oub- we will see how Ite source program is compiled wana the help # vartous phases Of compiler Lastly et intioduced with varfous compiler conskuckéon tools Wwe willl po am which takes one d translates tt (rasger pa orem Compiler” compiler & @ laniquaya (source pro panoyas inpuk an inte an equivalent another language ther vole 7 Dury this process of transl alzon C4 Some errors are encountered then compiler desplays thera es, Me baste model Cy) compiler can be as exvot | mes: a@resented as follonr Spur output” ne Z ompil feet So! target hanen ’ we fig ar A compiler > - 3 the compiler takes a Source propam as higher level languages such as ¢) pascal ,-Fostan. and. converte if inte Low Level language (a machine level lanquage such as assem li Jangunee - -fostan 1% feast compilers > 5} lhe tage fan & an executable then i tan be called by user to process Wp's and produce Op: * : : Input = Se Owlput” Target ft Togs aa Bunning, the rlargel hearae - inter pretagir $b & a common kind of language processors SE execute lhe operations specitced in We seupplied be the user. Source paegee on. pals Source prep Snterpreloxs - oulput- qa A Snterprelow - \- Compiler's target progeain ts faster than. an— interpreter a. Snter pretabess ae beHer exzxor diagnostia han a compiler, because it execubes Step 7 gtep owtee Statements > - Execution. of Program: To create an- executable form of ye Source- Peers only a compiler program t nok Sufpiuen You may vequite several other pregame te create) an executable rage preyren be déided into modules aA source program may Stored tn Seperate Ailes called ee. pre processor = “The pre processor ca also expand shorthands , tabement zalled macros into Source language sl the modegied source program és then ped ba compiler the compiler may produce an assembly lanquoge program as ilg output » because Assembl language 6 caster bb produce as output and i easier te beg Language is then poocessed | a Ly The “Assembly cabled an assembler that produce popan relocatable mache code as tls output > - = large programs are opter- compiled th pieces $0 | the relocatable machine Lode mal have to be linked together with other welocatable objec files and liboary ples ate the woe bat- ackaally yuns on the machine * address , where The linker yesolves external memo tbe code th one ile may yefey lo a lecakéon th another file - I the Loader tren puls bo ether all of the executa ble. obpeck: piles inte nmemony for execulion - Source ae Y modigied Source Program v [compiler target oy hae LAssemb | er| Y yelockable machine Code v inkey | loa L ae Machine code fig A language Processing a The shuctie of a compilers Compiler consisls Of tivo pole H-Analysis Pork wt) Saiest Kart rhea sis Parke t beaks up the source program a constituent pleces and impoes a grammakical- Stucke on them, this ckuclaxe t! used te creale an intermediale topresentattion of the Source ree [This pauls collect infomation about the Source pregran. and stores & th a dala shuckire called symbol ee # fe called “honk end”. a fort tr Gt conshiucls the desired target progam yom the intermediate representation and the thformabien in the Symbal table» St is also called * Back end“. - chavacke sheam Lese’cal Analyser 1 Token. seam eyptar Analys ta Tee , parse tee - Syptax cr Parse lee ta aE ¥ ee Snterme dicate representation EE Welter pes a verified : ec: aq ek Machine code lachite ~ Depend code optimixer target eshte coche Fige Phases of & compiler - oar Posthfon = initial +vate # 60 aise tanetatce [Lexical Analyses | (fd 4 = >(td,a) 24> (ad 92% 2 bo> Spas Foals dw aw (id,2) ® 7s (fad © *, (fd) int fe flea Tatermedlate : code | Generalor| . +, = tnt to 4lear (40) t= fd et) be ee id = 8 v tode 0 plimizes] v Lof ky) eda Molt far Ra 1 #600 top Py ho cappk Rn Ro STF fdr Ri qe Jranslation of an asstgn mbol Jable y jeinenk * Ls Yt stoves lhe woes name 5 ils Lape als Scope and procedure nares wth number of arguments methed of passing each aun and lke tape aetusned - Loy the synbl table i a dala strudive contatnin a wecord or cach variable name, with Aields sor the aktiibutes Ihe name - "hd. Grouping of phases ints passest from several Sn an im amenbation- adiutties phases may be grasped tagether inte a pass ment Statement aa yeads a inpuk fele and parry SpE pass | consis of \. Lexteal Analsts ae Sqokax Analysis 3. Sematic Analysts Ye Sptermedéate code Generator” Pass 2 consisls of |. code optimization ade Code Generator - I-54 veads the inpul character of the source progr) rt them inte lexemes and produce as output a sequence Of tokens fos each lexeme io We gouurce Phegrarr * When the lexical analyser discowrs a constituting an Edentéfier » SE wul enter the lexeme into the symbol table L» 4rterackion betroeen tA and sa will be done ny forser call using vaek uexk Token " vormand « | _, Woken | — . “Jo semailia Source ee _s\ lexical feces Peoqan Leper oe Analyst Ger Nex J Joke lexeme Tasks of Lexical AnaliserF |, Vdentificatéon. of lexemes a Slaippt cut comments and while spaces ~ 3. conelating exvor message enerated by ine compiler wilh the Source progaam « Process Of Lexical “Analyser - a Scanning 4t deletes Ihe Commands and compaction: of conseclive vohile space characters thie One ° p. Lexical Analisis vr i prodtsce tokens of the scanner Tokens, Patterns, lexems i Token i Token f& 2 pair consisting of token name % an- optimal abtiibute value Patterns 45 2 description the 4om lewemes Of % token way take". r 4c a sequence of charaders in Source thal matches the atitern yor token. - Anternal Description lexeres: characters & f fein pepe ae chayaclers rhs & Eke - spon the extpat- that the lexeme # p ane “the coer seerezobe [Zero b= letter followed fetter (OXdnUmber) ptr scove + number literal Alumerteal conslanls Bly =59:096 2591016) epibing but “sursounded al dumped “Atiribotes for Tokens 6x €= mt ee ztd, pointer te symbol — table enby for € > 2 exp -OP > Z number > integer value 2> Snpub bupjering To speed up the veading te couree pope € will be us Hs 4 5 lextcal analyser the input shing 430m lest te vighb ome ¢ ine die uses lo pornters begin ointer and _fosward pointer and “epte’ te Keep track of the postion of | input scanned « Initially both the pointers powot to the first charackl the tpl sting inte] i ; Le eve LP Bi- il} 3 =the ‘pli? remains ak the begining of the Shuey tp be ead g \fpte emoves a head to search 4 Ine end of lexeme «fs Soon as the blank space fe enwuntered thdicates end of Lexeme Vor Saar ae fs HOD fehl VT fp - 4 LS Jhe ‘fph’ will be at vohite Space « when ape entountes vohile spa head .jhen both [he next teken “i'> ce it toner and moves ‘ppt! and “fple fs seb a yore (ea hE rey, ui foun hp asthe input character & thus veal fo"? secondary storage but th ts costly Hence bepgering technology is used. © Boot shopping: Lhating a compiler Lox amy fir level Language eee complicated process. Ib dokes a lot of dime do wtte a compiler Fron serodch, ~ Hence Brople lonquoge oe used do generofe ougel code in Aome sleges. *. The proces 4 coriting a complex fn the, dougel programing longuode wchicl “hdb de be fe i compiled uw known “Book Shopping” x: BASIC, ALGOL, ¢, Paral, ovo, Python eto, Lex Lexical “Analyzer Generator: Lexicol Aroligex Generator Fnbroduce a: doo| falled Lex hich allows one to spedly a lexical Aroliyzen by apectffing ezulort exprenion to devthe — pettorn for dokens Rcation - ata Lex tomepiley Jens ‘ Ble wt Clerical ana fo lex-yye C Complex ronal pega) glo hk rie ena a: oud tas rae Bovsce [OO Recognising words with Lex: mex pean comists HY thee pos ( Declared on Seckion 2 Rule Section 3 Prroteduine Sechion Syntax: ne Asclonatos Scbion “3 eh Rule Seckon a juocedune Section

You might also like