0% found this document useful (0 votes)
58 views31 pages

System Software 1

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)
58 views31 pages

System Software 1

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/ 31
Mooute ~4 Lexical Analyser Lex tool — tex Pr0q Far» tex Prograsn 8MorlOoM » 8 Seck 8 Section tex prog — defination Sechon Rules deckon User Subsouhne Sechon C341 contain mon progrows) (4x) a® : : SSeparotor A cucture of Lex Prog TOM 6M ‘with ex 8M. en “AL # include Cit mast 62 used 198) 4 asibyt Wearinel De ibady ue Types . ' oy 5 be Medbo" tC printy C*Hi, How ove you? ); 4 Oe | re Lpnnit (Who ore you 2959 re “19 pris einate who 07+ 104 Jor al porta | anes V1 due to Sing), 4 Void tain O t ; print} Cele ‘the vaput"); 81 foo er, Yylex Oy : * 7 4 D Waite Lex Prograrn to Tecognize vowels and Consonenis “LL #incdude <6tdiob> ay ‘ Ke Caciou] € prot} Ci vowel); f Co-z)} tprmt] ( consononts "95 4 “Hera ou 1g alveody ervesed a Vaur! G14 ignores 11 a i Saher thom a-2 Specl characters axe ignored Void rmain c) 1 t Preni] (tote TepatD; ¥ylexey; yy Y Write lex Program 49 coum Narabrr of vouxls and Comsonam MM 4 prog7am AL Hindude <6tdi0b> int caumtveoy cro; us “7. Taciou) LV+s 5 Ca-c) tcrasy i 5 UL Void Sain c printy CEenies Jeput 9; Yylexed; Printy Clotolvcount 74, v); poor} Coral C count 4d, c)5 5 @ Write o len progrorn 40 secogwize valid tdenblicr 7. Lt include Zt drmdude 4 pried pube | “oH DuM 5 45 7 Co-d)4 mum-= atei( yytext)s t privy Crd 16 valid num, S comrent to voteger yPem)3 4 et : = Void mam) Aroy. 7 v primiy (© Enier Topol yytex 0); on e O\nohey 3 6) Write a lex progsarn do cheek Cobether @ Purwbes even, ot odd : — Zt #rciude <6tdt0.b> ini Dum; 7s “4 Co-a]+ num-atoil yy tend; i (rum rd = 20) prety Co even number); $ else! print) ("odd number), 5 Lo Vowd ame) f Paral} C* Enter Toput!) yy lerOz Exeauhon o| lex proqr0Rm™ (how lex program works) EE open @ file — gedit flenorme. L Cormpile = Vex. }lemone : ce lex.qy.c -2L — -/o,004 tex TR P84 comnpiles |———+ lex. yy. c Seny4< Jc cormpiler |» . /a.out (ee -/ J -/a.out |— % igits bathe Tequlox expression Jov recognize dig [0-4] —rrceogrize Single Jight Aon ate sem 9 PIMberD orate 4 Co-d] 4 (xecogrize ormber) Write tequloy expression Jou recognize deciena] mommber oceuverve Lit Pet there ass 10-9 (\. [od] 4)p 20 on! occur Ses he cy number onsiarr 92 Write requlox expression pr Tecognize exponen ko| — ex: 6 e-02 [6x167) ae We (0-4 9elled b- I-99) a dermal no “Whole aArite lex program 40 recognize valid Dumber 5 A trix ite len Psoquamn fo welognize Number of cChordceterg Wuotds present tn Grew sentence eee reece er eeeeren paarCe-9 + Iosec0-a1s (\. fo-4) +) ? (tee) [+29 Tog] J *ECOGMI7E WOOL chovacky 4 No of words 4 fine coud 4S pace Coxry ‘ov =p 18 aldo vakd ce-49 7 LF imclude 3 Cheountibtyy long 24 O\w) Lime vis y ay ‘ : sty OveJ mn O\+\-J? (to-4) +) USdpace count +454 {Space coum +4 ay (Cis \-]p toa} (1. fo-949 7 — ( fee) [+-1? [o -4+) 2) : Void Trav) o t * primi} (*%d "te voli d umber ");4 prot} Cr Entes Tmpot Yylex lo; PRA! C 7d 16 Mot Void Nurnbes"); obec tmvolid So toke % fo prim! Single hry \ Pref C Torol weoent 74) weoun), oy all mpeiching I photret : “ed print 4 C the number of Woes 4d hee), erat} (The num bet o| Space =7%.d", Space count); Void main ( ) Cl corms 4 ‘ 5 wane — YACC—> C parser) C lex and porse comnenrnical on) (toigher Level “Enics impui" Total rouneemternce Pret C pier 19] aay Hytexco; 1 2 Toute iS Poxsex) seund texicay | toter Syntax SEE NSO Nec, 1 SU | Cex (ace oD Porser) Symbol! tabi | Cin v0 rOMNY Pea hina, mrastine con olse bs asked} founbre no ol wonde C* \e\q)-+ *ooords ex abe l2abe @ab, Tf Space comes W ignore a yoccp.y [ 4 nt seckoo zy Aefreoton ur Roles 6ecbor Qrommo Lacon 5 ny, main ¢) : User 6ubsabIe Secho ¥ yporse()- 4 lex pt nt 4 de{maton Sechon YL Pattern Lackony Rules seghorn WG mom) LSet Sobroukn, Selon yylexca; [yace uses ory, while ler uaey Requlor erpreas. Grommencs 404 valid denice o-+ AB s~—lolele tn lela poaces B= 08 bBlcB le loshe]as Eerunten 08 +] tot ° en 6 Gm SLA : f d A= talon le ; 7 /\ tes voeslelellelalel 14 a} 6 p=oltlal. .- 14 a \ -— 6 Yaccp.y Wt [f rmetcmmeal— \eesmveo! Shen #yndudecstdtoh> corte 1110 Lex peogron) vy Yy¥parse rolrenally call yyiee Z4oken LD —> lex prog-t ee 47 Beith = Yace-4 prog.y A:tsloal; Y-tob.c ¥tObh Lt —* Celery Petobe ty manly + defime F define 5 pent Cre mtes your ap’). eb p 44 posse O; ‘d.but 15 Pei] C vole Siving); > BYCTTOTC) _. t Prot] Co2e¥aha Shiny lexp.l exitfa). at Firoctude 'yAab.b" 2t eee eee eee eee F peinyy © cetcr your fp"); we yy porsecy Ca 2 A-d) Pacturmn 34 To-a) {rere 054 Prin} C vol 611179 . Cochown yy tent (e155 4 \n Vacturn 054 yyer03 (0 “a t prinaf (¢ rovelid Btxing!), : : i exit (0d; 5m ow Yore progronn qo xeCOqmize abe groremner few The String 5 Write @ lex program +0 coum! 0 o| eoo8d 5, MO ‘ol spaces ape Dawes g lines jrom agren ‘mput file oT shinelude "y-4ob.b" as ne £4 #include2didio. b> [Phot ov] “S \ Reet L Lachusn ASY , . ce WW Coun! +0, EhCount <0, wot 1% 70; argv b gaduso Bs yy ine fp z pacorm yriert (5)5 J 3 ae file pout wn daciutm OF ‘ Yrout = 6) p “et ‘ Pi \elw)+ Leseoumress } (ue ‘ : : pounied porite shard Cn) Lime sas y Yaccp.y Tw) USpacecoumd +444 ie om kSpace coum +44} frrclude 454di0.b > : “y i wae VAoren AB ; ea room Crot arvge , char ¥argvC1) wel 5: AAAAACB Vf Gorge < =) a cracls Pein} Ct 0 Tp fier; wv ; g ° amarn(> ge SR re ereererer ceri t ye yin +fopen Corgvt, v')s Yylext; pail Ctr of w count ‘fd |, wou); prong (m0 o| kine 7.0 + 7d" Woe); prni| C* no of Space * Pd", Space count) - % Wile 0 lex program 40 tacoqesige corssnand Wee Hater oi Cheowmmnands C Alpbobel Uber alphurummrcal Chovark) + comments ~Tgmote Conyihing slosts ost #) & cumbess Crecoqnuc 4-6) bs whitespace Tym (Spore beters "J —~ Lf LF Vora de <5idi0. b> defor NUMBER. 400 # dene, comments “Hol “h delyne COMMANDS HOD H define Text Hos Ly Vt ce-a+ { Co-d)+\. Co-dje] return NomBeRS5 | ] \. [o-D + \ push (a-%) [a-r0-q) 41) +e \E AV nya" Vb) ae 3 nt void wan C) Saturn commanos; 4 { teor COMMENTS ye v Usetorn: Texts ¥ | © nt vals vdl=yyles0o; Pamy CO xd",val); 5 tog rcs # ‘raclade dt delyne NON BER ‘ # define COMMANO i ' #ddree COMMENTS iia at defvre TEXT “rat THM CYnt age, Chav avgvl I) vt Torval, witite © Val =lexer ey) t priv o> ee 5 Wo bexrerc) ie Wai cs maint whi Co~qetchorO) =" W Coe et! Mredigit Gey) t frewsle Dir oe 8) (F-0] Qrossrerat ,. segee L armbigioue Qrovnniy * wahile (Coe gtichaves) 1 €or $4 rodight 6); a Se ' Cone Cee gerchar2) EOF 3h vedigit CO) ine ox e + T % Belurm NuMBER; \ if /\ _ 4 bial 7 »* 7 CcenHOe | | wus ' 7 py tek LF E cohile CCceqgeithar())|=t0r 38 Cr le) se, Ct tom ; trngetc Ce, od: Clov tbs E24 | why yact cammot parse P Spigot led : Fearn COMMENT Gouna ae all eels ob r os f pond b-e*10 © > E 4num q Cisalphate)) » oe poet a | E enum fisgq voar HeCUTIIVE GFOTOENEC ae while CC c~geichor cy) Le oF XQ Usaleusrn cy) Ungere CC, didi): saArae be 6 —xeb|y¥ce we : q ° : Xe ale to soos Belomm COMNAND; van rift yoals 5 i Job ¥ ay Cowen : 1) 3 pen tot asitces tel eabile CCc~ getchavcy) be or 3 § (pei Ungeic Ce, sta); BAVTD TEXT; eae eae Mopute-o. Replace dec a 7s Compiles phases (3m ov om) wwtes v 7 o aa ' oe a ae ca Eloi 0 detail Various phases o| cornpila Rog for the ae A Ny Apel Sis, x=0%b+Ceed)/e ed P q | oa J i —> Xeoth+Cerade ae Mx ; Lexical Awalys¢e a b ~~ a a ; tan WS a1dtp cur cide <¥> “48><4> Ly | ors ' <1d,9> <)> <'d,6> iat <7 oewmanhs Analyt sis we 0 ~ a | we : Yeah Syw bol jable-> a “ ‘tds 14,3 T ‘ tidy Te Syntax Analyser (highs priosly should Come last) Triletome diate cog i ReO#b+ Ccadd/e = 4 © Gene tokon 2 dy wid s = tie a i LO \ doeido aida . ns A= 4+t,/e o7d 7 x ty =4otla ty ~Aotig % toKb +cems)/e 1 _— . Sf ve tu * e€ N | i ‘ aX | eg : sapizalhon mole *Pdependent code op ber 424d dye idy eds ify 2 O%b do sidde dd + > 4p ah/e dar nfide Yq torts Nave tot ta’ Code qenciabom L+H, dub 145 © - Mov R1,1d4 to=idd nidae Mov 80, 15" tg=nlide® Mut R189 A> tots @ @® Mov ®@3,ido . Mov &4,1dk Mot 23, ey : . © Mov 8,86 Div 218s @® Abo #3,R4 Sik * IRB bt Appricaton | compiles Technology, * Teplermentabon af High level Progrownscimg + 4 Lomquoges : ‘ : ao bi ‘ + Ophenizabon 4or (OwmMputer Aschilecture * DEsIGDM of Mew computer Architectus, . Proqrom Teansiokon - la Produchyty tools Lexical Amalysis Comverts Source Code to tokens Lexeme — THis a Sequence 0| Choracters tm the Soutce Pooqiarn dbat 15 matched by the potterm Jor token gene raboo Toren tes seizso| oy THbolS Ww Ibe Gromer Patlerm— Ttisq descsipbon ol, dhe Jor dhat the lexe wes O} a token any take Rules hos the Lexical Aol yser + s Lexical arroly3¢s performs qive Tasks Helps to Tdewtty token wie the Symbol table — Removes while spaces ¢ commrnents from Abe Source prog tow = comidales evror THESSOgeS with the Source proqgrarn sz Ya {Ou — Heips po to expords the macros Ih sound tm tbe Source program — Read mput_ character from ing Source POA Tax, Lexical] Analyser 3 posses COMMU MICA Hat whet will be ibe cideok}ics + Requlor Delrrihons The ci dewbliers wls}ole) Tele lets — Als] aq ooh] ls that call be the C rdeobliens ? lentes salable |-- |} alo) ---[el_ dhairralilol- Ja 4d —> leles Cletter \sigin )* uneigned Duro digit 01) - eta what will be ¢ UNsiqned numbers » 0380, 0.0193, 6.34 ay, 19. 36-19 digit soli ol... la digits digit digit ophonal Frochor —»,diqite | é Ophonal exponent Ce C+l-/€) digits) lé umber > digits op honal Frackonah 9 phono! Fx poner! Extensions 4 Requlor Expreasions — Kleene Closer%e and Posilve ClOSuxe: One OF THOTe INdlanr opte tt lE andateastarty Xero OF OMe INStarKe: 7 15 CquIvalent tos le 7 Using the extension letter, —» LA-%0-7-] digit — Co-a] 4d letter — CleHes | digit) * di qe +L -4] Aigiid — digit + umber — digit 6 Gaigitd 9 Ce Ce “VP digus) ° Pe (Og7i Bow of Tokens Qrarres {ov Branching eta erernts Strat > if apt then Simot 14] tpt fhe stand else Sim) ye Spr + term slop term a gs _ esr id J romebes PPegalos expression Jor bronchi digit —- [0-4] digits -» dig * numbers + digo [A-z0-9 id lees C leHes Idigus)* a then then else else relop + <[>lex]> ale le» Patterns [or totem ol cratmple ave described by tequlos delima bors Exornplc ‘Lexical Analyses S17ips cul woh wo — Cblonw Liab] Dewlne) + 4 Tea nsihorn Woraa bor relop Stost = 7 — »(0)- 7 6 ) AB) Retosl velop, ce) { > ta ~4@) cers Ceelop, we) (eee A@) Retusn C Yelop 1) Return retp,@) -— = 6) iH (G)) Return ( aelop tp) 2 other — Wk -Space, by Fecog wn ay toten Transibon diag sore fos Seed words and iden! frvs leties/ digit _oibes * jets > ES {2 {@®) Reus get Toe (2-175 +0)” Cnonlates or digris) other Ye Sterin to b — o—~o- Fronsiten diogrom fos ondigned no rokrs digit aq an igi : dig 20 529", (SH YAN 0) Tronsiton diagram for unsigned, Dumber rghit digia “om St gues $6 © © aE Program for tc top> TOKEN gerRelop o TOKEN TetTOKED + men CLELOP); cobile CO ¢ /e tepeat character proce s5iing ub! a ¥eluren on failure occurs */ Switth Staie dt Case 0: Cx DEKE CHAOS i CO~ <<") State 'y state 63 L Comtext [see qromen i @ttbg grommn : ’ 4 Ambiquous qrosea * de¢ comtext [sce qvoremnet avd corile gramme [on] Coes ) Stolen3; cise foley p x break define Comte feec qrorernes. obtain CFe 10 genesate Case 9: sedvaci Cd ; 4d isin gs of ob and bg Foving Sub String ab. Cio’) seltoren atvibule = @1; seturn Ceeltoren): 4 cobeveves otberiose ababoa abalD Pop | Sally are ab | bo a abahaa a lau ab |oo abo |boa abobhabaa Ghabe baboa Seluwn lokem Same —— Def comiert free qrommn consist of terminals, Pon 8, Stack Syrmbol and prodathon, esmnol Generally e@tNT TOPS * ec isdbre Worle relxot 0) fon Terminals C) > lerrmnals ae basic Symbols {rrr cobich Srsvngs ave jovrncd The tere token nara’ 15 a Synonym for Jesmminal 19 86 6 olol rio |3 it - hon “tesmninal CNT)» Now teweminals axe Sywlacke Yasiables abobty obaba Ahat demote Set 4 Bieings it 9: au : ab \lobu ab lika " aba lbab ae eee an Non terminal Tempose a hiesarchical orsuclure OM a Abob) bobau | language. ¢ key to Syntax amalysid Gnd 1ranslabon mma Quem ODE NON-lesMinol 16 dis hr gui Shed asa tart Symbol and the Sel of Strimgs wdenolS 15 dhe language gencrated by the grasnrrecy ia» bs 4 agro geil A “The product : 4 monte raimals C which tesa nalS prodecor co" cd heed of produchow | [> ornbind, to form EIS\ 9} row ainings- toch ro son-lemmal coll won tt AA body oF aig Fgh Sid lea rsa 15, « conn of © 0% MHOW Acsassmals 04 MOP calb¥ ab Oley NFA? ‘ob ab 6.2 .©+-6 Regulor expression « Calby* ob Colb)* Grororme— | Ss AabA A~aal ba |o|ple Slasbrgay mmbel > 9 Nomiestminel - 6 & Tesmmina) - 6.6 Devivaton Cx. Abb “S@Ahabdh Eabas | lb mot reciudeden grosnmer Tee y » ¢bb 2B bA = Obb 900 Crmralid sting’) 6 Aaba& 4 : Con sides a qTamrnes quer below from which any avHbrnbe expression cam be oblanned. CPO» that 2atkabsA 2 aOObA Ss Cammot qererate a8 bid thew promm iS Awebigous [ox semtence Vd vid wid Lom) — A qronnreey tbat produced more than one pass tee | for Sewience oF Stang 18 Said to be arabigions AD orb gous Gravett ‘SB OMe Anat Produced Tow ON els most dewi vabon 03 *MoFE thro one, sight mNost desiwa town hor the Some Bemlence OF Shing Cproreinen > ESETE Je-€ VExE le/e lid Shing Ad aid wig Chefisrost > ESEsE EDEXE fea td ve Eww ,ETERE ies id + ERE Emm IA EXE — > tid AE ED idatd we lend lond ees Wd4idnid Tld tid aid Parse i100 7 ‘ E le]t 16 CUtG0m Qramsre AA _ /| \ Qrasoren we { i aoe E72 JN NG Righl TeCuIsion qrosrnes i (se JN “d xh, ‘1 | tee ! cAkcirnove Veld secursion i a ot | * yaa Amadlp dete B® and ; B® and werov, elt te Curso Aro b’ quity acrovel> : : ae ( tau e Aas Bia ‘ooze arekigueus qreroreer tol omombigious qroTenpr, sen ie Remove left Recursion) t: A A A precedence wo “\ LZ Leassociabvty Esen| o ee B 7 7 Tote i Yrorernt : Foid : ° ‘ s ban po~ . coe | beg Remove Vel} ve cursit * arbi gious unorabigious | [recension [ror (otowng os) t—eat|r (63) A ALB EEE p | ba eatlt ‘ . 1 €xE : —. is Tot arle i @ pr are'le 4 E Fotate lid ad Totter | F SR RR 3) R+RAR ; ag BTR Bis TEV 1 » Ss Sr|r youre lalole torxlalple > © Faig [ ecxaies Sarn] eer A-BAT Roane ; Se &eobiquuly tremors! . Teeoova, klirecarsion Yoosm the [ollourng qromenn s—o(ola _frermarns S00 beoz S16 Pol there, 5, A> Ahale po lel tecuTsion)) rr Fr Louk bore! stew Ai—Aat'|€ 1.4818 K REB j ia 6 — Na -oC Now vwarncdiote felt Tecurtion ) ZA, ee : \ A 6xlc® (fp ua, su |é Stepre \ ; Subatiule prodatton O (5- Aa) + Ab al hel e ™~ production #5 bet AG 2p - Bale i 6— Ne Ne Ve elUTsion — A=aa' A+ fox la— rmrncdiol: left tecursion —G) n—opa a'len'fe | . - Resmove Team: date tele Fecursion for @ zi | | osha Bx es'lé Asan : | A> axh le pond | ° | oeb 8) Remove left secussion Ama i An edl fe~ | 5~— Aa\ble | } Asal} (Suh 5319 ©) 5s~sdalfal ble A « B® Bs Pe jas! | be Joo: Sa das'lé>

You might also like