Download as pdf
Download as pdf
You are on page 1of 39
Fanctamentalss < Alphabet + Analp habek wa fraile won-emply St 4 Symbols. We Ue the Supmbel (=) te “Veprrenass ar alphabet Ex: == fot Sao aes We Ze Ja, b,.---F% Shing: A ching th a Hulle Sequene of Symbol. | Chosen ftom Some eilphabet - | Ex, Ol10l ftom the bray alphabet s=90,1% The Shing UL & mother ching choosen (rom this alphabet. s-labek 422, bbb, ab achbacca oe shings. Length of a Sieg -- (ne. opsymbels f& a ching) Th & often useful to Clamhy Shtage by tet length be, the “0-Of positions for Symbols fo the Shing for frtance ollol har leugth S. Lerath enotiet by mod[Iul] operator Tt common be Say thak the length of the sting te the number OF Symbol tn the shikq Empl Shing The empty ching i the shang wth ero occusence of Symbole. This ig Kn Aewd by “E' eptolon. This shiwq a Shing that-may be chown prom aey alphabet zs! Sone. : i a w se FET emply chive cetof, . { t ‘cehog eres Stohegs. Puoed Of an alphabet .- (x of cringe Whore lemeihy & kK) Tp Eke an epbabel, We Can EXPT dhe. Sel of AU Shingt Of a cerkain length fron thal alphabet by Wsivg ex poreukial wolstion, we debe SS te be the Cebep shinge OF length Bice cath of used Cyrvools CARs ex sé no males what the abprabel Sw Te clea words “S'in the Only sheg of length ‘ged © Ee jabeot s+ fab 2% s% Fax ab, ba, bb, cach, ce& St Foca, aah, aac, aba, axbb, abe, aca ach, acc, baa, bab, bac, bba, bbb, bbe, bea, bel, bec, caa,cal> cac, cba, cbb, cba, Coa, ech, ceed Peele Note: Thee ik a hight confusion blo Sand =! >The homed (Z) ba plphabek voith members ab& © a Sumbol. >The lak (=) wa cet of shings with mew bees, an the shings a fant c of lewgth | Se sus'ost:: 00 Ex. se Fa, b,c S*o seb of au ching ovr Ao Spey bret ce Sevkee alphabet | | ~> The seb of all shinee Over ain alplaloel Su conventionally clindial toy sk Tor ixslarce Fo,'19S 3 E,0,1, 00, ot, 10,1. % SS Us S7 0 sete). —> Somctimen we wish lo exclude the exnpty cha, fom the sek of Strgs. “The Set of non—crpli, Shh4e ftom alphabet 5! i Kenoled oe cs ste s*_jet s*- stud et eee clause Concakinabion of Shbaget— let KEY be two Shige then 2%-Y cheno the Concakivation of KEY Le, The sbiteg & Ps makg a copy qx and flliaoma ft ly A cepy of y Ext x=llol B Y=ooll Z Y= LOlOOW = YxX= COUN! Lanemage: (L) A Set of chiings all of OHER ce ekpocen Same = idnere Tan particular alphabet a called a language , ih 2 & an obplibebare L iw Subset of S¥ then Lia ee Si xl lanquag' Ls @ Tre uquade of oll Ching’s coniching of nN voof oc {ello d by 1. woof Abeer bee nNzZo Valid ee Ls FE, O01, 0011, CONN, COCOII(1--. 2 @ The Set of shings of Be aud 116 with on cayeal no.of cach Vali ching! L=3 F,0U,10, 001, 100, 01010, --- - @ he set of brrasy no, colioce Valucr i a prime Valid shivg aca Le Flo OL, lol, & @ BS” & abso a language for any alphabet & © BF wan empty baquage, Ua lerquage over on} alphabet 4% © set The language contsting Of only emp by Shing & also a language over VY alplabe . Notice that P= 3 EL. The former har no shing aud the later har 4 Shing. Prefix: “The prolix F ching, ‘u a ching forest by taking any "0 ot Symbols ftom the stort Of the Shing We Olll Prix. & ° ot Ol Ol Exteel or ia Ce Po defi A cling the qywen Slvkey we Ol pe te aprefix = €,0,01,011 | —_peeper Suffi i excluclng ‘the given Shing | €,0,10, 10 Patoduclion fo Regular Exprorsions E=Jad an == 3 Ea,00, aaa. aS a= 8,a,4a,c00. Usion(+> z= fab} O+b= 3a, by (a0) } 8,0) bac, ab; barbbranal-t > ConSi = FIL OU, Wh, OoU, OWL The whole RE will Paes aks ties: shings end with > I= 71 10,100, lo00..- % AU sbivys rust beqin voila 4 > atbatbat = Ybb,.--.4 “this RE qereraler excctty two Ke fr emery hig > (brabby =} &abb, b, babb. bbabb....% every ae frineckicety follouecd by alecrat duo be => Ree tho 2 own mut be folloused Any wo-of ae pollowect by any hoof be footy by aanyne. CS A > abe, ac, ab, bbe. +++» ABRACE “fh > RE- a & followed by b followed by c fy epsilon wot there —> Wilk o RE to Aenokd Love = usheae Sa fabt Such that 24 chovadlir heen the might ead OP the Shing & alianys yy’ Re= Carb’ a (arb) (arb) > Coreliuct A RE forth language b votdicl ee ae age aah akeet Bo Bs ov the S=fabt RE= (at Bb (any berb* > WHE RE fer the lavquage Lom which the shvgs uhh are Stating ul 4 and evdig ust 'o! over the Set s= 30,18 Re= (Co+l)‘o > RERT CYS Fyne una... % odd vo, of fie Def inition of a Reguterr exprexsion aa Avy Any sHearttval Seyrnl a [element of = RE ee DEA HE = Union & two RE, expwosvion & fe Rr Ro) Ra, Raab R= RR = (ath) —Concolinakion of bso RE, R, &Re writen oy RR wahoa RE te R (Re R-R2) ~~ Thetalion (dlosuse) of RE, RB unttien ar ef ik also a ee ow Leb al be a tecqlon expeewion A= &, QjOOQ,--- - Finite Set_Autometa A lawquage Wa Subcet Of cet of shigs Ov an alphabet: A lanquage Can be vecagnige! by a mission, Such a detee UW Codd a ite dorce. Here a language. cam bave a Mreprescuktts fo teers, Pagenesating device AL Arama x4 Vell as fo beams of secoyrtion devices tsheh U called an “Acceptos’ ee ae ee elagttion hewiee the fini Stati outomalon | ceaulas R, ard Ro wa” NE TY OFF Sesitch on = exanp of FSA O% cvs ove eS “ & ae Sues adden. Deketaniniste hit Stale Automata (OFA) le can look ab the FEA, tsith an hput teRe, be tape head aud a brite Conlecl csbich tenotes the Stake Fitak a Vecoqwizen | The fomnal definition & a folars i A drsa & a S- tap Ms (@, % 9/40, © wahere So & a iale cet of stealer > Ee a ffeil Sek OF Papa Symbols (5a ia @ ob the Steak Stak or frill state FSO ib cok OF bal Stats > Sate banution fanckon A a mapping from QX ESQ © cramper Leb a RSA have o shai cet 3Yo,4%a,ih Ayo f the Pital cet ait the only bined Shale, The state diagram of the DSA U to 1g, etidoen bba a ae No aabba ” yy Peal cla Aalbba nN, aabba a An QAabbha Ao aaabl, * oes ae Babba iq Acceplee| 6 bb Frral steuit a om DOAN : c Le sane” (nneid ak Nhe E aaabb § Qx2z3@Q Fenton i \ CH, 2 §GoD24, Ege , S (4-b)>d a0abb § (4, D>, S$ (a. by 4 Nee Big. chows the transition cMiagsam for DFA that accep& all aud only the shige of Os aud gig that hae the saqpence. O 1 Somewhere dhe Shing. 1 D Oy Be SS Cromation Magsam.) ion table: 9 Transition “A (40,0)= 4% S (40, =4 SQ) =4 $4) =e S$(Ar,0) =e SG = Ve @ Lt w design a OFA to accept the auquage (L) L=J wl oh eres length and begins usith noth Sp es S(4o, oj=M Rantition table + $(4o)= 0 S (a> > S(a,= ! S( ft - @ Detign a finite automata, heh accep even ne-< | ER Os and even vo of 1s a poseiblities (a states © even wo. of Os & evn twa. OF Al @ odd us of O's 2 even vo of Als @ ervey roof Os & O44 wo. of Bc &) odd uo, of os & eAL wo. of ac: $(4o,0)= a, anne SG@eN= + ies Vw S(%,0)= 4 Ra ye S(%,.0= 4 Teas a, (>) Dokign a pike automala bo accept Sb\gs tab : aloays ends with OO Gee” a oS m= (@, =, $/AVe, F) > B= 3%,U,140$ > s2 G01 { j > F = 840k > Aoz in @ iu the Steut Stak ox Wwihal cla > § tomilion funclion $(40,0)=% SCD =e §(a,,0= WW S(4,/)= 40 S(42,9)= Aa, S (%,'\ = V0 © Design DRA ushich can accept dregs haxing Al Wak Subshing S(4e,9)=%e S(42°)= Veo SG@o.9=% Saaz % $ (4,10) =%e S44 = $4, = An Slay!) =A © h pe BON | mnzod, Desdq PPA feces “Oe Les 2 a) (Bead Clate m= (& 2, = $4),22,424 Z= fo, % Vee UV UWQ ta tied det. F= 34,42 S= Lamaition functions S(Ve,D= S@ = 4 = 4% S@o = An S42D)= ay ; S(4ni) = 45 ; Be : Stained eee He cicehe ct fn boincany - gk He Mivictble Bis BANA hen: ee 4 1 | | \ ' A A Ne Consliuck the — tancition avaph jor EA hich So ocepk a language L over =20,1% tn wohich go, 14 i anes) shings Steal, worth geo(Jaud end coith't 2 Laith vnplyr @ Deviqn finite automate be accept b whee ost the shimas fe Lave Such Hak total wo-oh AS wo them ae Anicible by a Aweble by c! Non- Dekeaministic Exnte Stoke Automela Th the previous where > O- ka fee Sef cheater 7 Eo tha ire Set-cp Inpak Sinbad } > 4p, A member HA, in the dark Stub § > F, & Subset op@, & the Sc of tival ctaby | So the bankition function @ Tk ctete Aegram & NEA talich accept bia! chs hich have otleask ome pakk of Zes0 310 0 © of Last te mk tora i. @® The Shake agin x an NFA tslich except bina Stings which agen ‘oo or 1a" G22 B) Ge) ' @ peur NPA which accept. shies having I hat ape i. | ee ae ee ea De | Evy DEA ik a NEA, but NEA & ota. Bey So, we cannot comet REA to BEA | CRA —> NFA (NEA—S DEA | me Comuk ‘the following NRA to eatilvalout DEA “Rantiten Kagem of NFA Os = Q=3 Stoln 2 Ras S= Qxz= > $4103 Sah 3423 V* S18 ore} @ Papalene of NPA avd DFA oO o5A —=@) ee ) ? Subset Commmution is ° { S [2 g $0% [awd | tnd Y3a,% | ind PU S40) [Rory | WV DRA “© ; Se ef So \ Ao (Bork Ivd 4, [ia NEA A= ,=,S%0F) Q= 40k S=1o/l% Qp = Tnitad Stale F=ja0h if ut ; @Comerk “the followhy NFA te DFA ty { Qn” ° l > &)—&) —>@) NEA A-@,0,5,6,%6) T= loi B= 140,4,A2Y Fae Vo= Tnilial shale $= Qxte2= Be Subshing contbuction = S = > 2 2 PHS | otk | snag yak é is 39.3 g 2 Bord | Bens eval AVY, Hout a eaah e et M7293] Jawad ant come dhe fellowng NEA fo BFA, 2 ies nn an NRA Ac = (8,2, $,F 40) R= 340,41, 42, 42% Ge Trial stoi s=-%0,8 F= vo. 4 Ss Qxera= alle, sub shiing Conshructiod aan ae x a | Sas | a| 2 842 4a | funds | 2 Ss ° ! p w zx 13403 Sa,a& o {ak furr | # fant Jared £453 Bante & * 340%V14 wt | F €Syo4gh Sirah | Bd oat | BAVed a 43,403 Hi %ed oe S442 $04 g faatd | Jaiark twat “Wtontet | RUGd — | AnAak 34 49433 $4,403 | tA,%ab Et eh | 8,43 | 2hash Titadoui IHW} | we IWAN 34,0 2S ak he | 1° posk te AudomolA Regular expression to fini A | Owe. Crd*u ea ceo” SB >@@ Pe Re Ga) | @ge: (oD* We “One © RE: @xe: (oxi) tot (o¥y* 4 p Re $B SO) | G28 | o*t*o (0 ou Fo)" (o-+t)* Eas GP Theorem 1 bet R be a veqular expresion then there exicti. oo NAA Usit, E. bauriteiony hak occeptt L(®) v= 7) ~@) | ah & to brad Stat) @2>@) ._. | Tuduction _—_—_— Casett Uslon. Lek vem t¥. tohete Traud % be “the ~weqular, expression there evict 2NEFA's for MAG. BAVA Concativalion Cate 2'- Let ve*(Fq where %%,%a ate 2 rreqular expreor the MoM, Aenoltt the tes machines Such het (m= EQS ane L (Ma) = E(m) . the conshuckion of macdhire M vill be. td 36 » }-[6 » © Cotesi- . Lb we) © whee % be a vequilor exprersion the machine -M, & Sucbthak L(m,) = Ln) coma & ¢ &. 'S Ex. Conthuck NFA usith & breaunsicsion’ for 4. yeqular expreion bt ba® y= b+ ba* Y= Ut Va | meb Mygeb t= bak rye —Bge Vy \ For vj=b (Fox wa=b For Weutbo a eo € &) b € G4 Consbuct NFA with ¢ moves for the vequla expression (o)* y= (o#'* v= (m+%>)* =0 i=l For ‘= ° —_> For Yo=1 @@) DEAT ij STN a rg gee 2 Rg Cheeta 9 | \. Combuck DEA fox the aiven vegulat evprertion | CarbYrabb Mts pS + 94" @) | | ‘ b> Subset Conshuction:~ § a b 4% 34ut 3404 | York Iaork torah | Yoel Hent —eos} ! os vk — oh “Famdlion dlagram:.~ 2. Conbuct DFA for the apien We previo “1 alos Cony ot (or vr a “\,0; 4 Qo, ' i yV 2B" @ OL cabest conbcton $ 3 \ Wo Vo Jao Jaoth = Pwo LO Jase — Fak we} WAS Fase 320 nts ore OWA Jae} Yarns lwnnt. DPA ——— * Distinguish bebacen keeprelia aud Compiler, aM peak | Tnkeduction te te Compile. | be Saset peti (alles | et Page ce pero, [or] Boe PT L A compila isa tanslatn thab Converts the Nahlwed lanquage ihe mackinclevel language . Compiler Uw wed to Shod® esron to ~the The Ce ipa: op yigtltFe tioned ota ak Witten fo One lanquage usithout Changfing the meaning Of the program i Lexernts — Sequena of character. Jokes — (durbliak, kona Comleuts 4 Operators — Synkorr fee fubemalluocder Phases of the compiler . Scume Progam we a ag Tegel preqrann one: EE Code : vey Sum = olelsum + Reale 3 50 go Hextca) Analyzer | oat + leepres a dye ida hy tokens 4 [ayaa vale J v rN (ao ¢ ete, Bo aN Phases ef ‘the compiler code ee Sur = olelsuun + Ralle 50 lexice! en om a, iF lexere® og. thas idem Ay forens iy Syntax Analgget Vaya re Y ae 4 ee 1 a oad + ase A gs 0 4 ae : Riles 0 > z | 4 $ ae int toveal U Y t f 4 tempi = tabtoveal(S0) | temp = ida temp J | temp3 = iAattemp2 idy = temps | L ‘ kemp| = id2 %£0.0 TAi= idat terp) Y code generates mF ide RR opener MULF ttooo, Re Move fhe R, APD RAR Move R, eh, The pass avd the Phaser Of “the Compiler Dw ts 3 complete travettol of the Soure pemem: Compiles has too pamer be tavern. the cance pepe. (D Mutkipace Compiler @ One- paw compiler. Matti-paxs Compiler Mulki -pas Compiler, Ic Ube be proud the courte Code Of a progam Several Hines. Tn the pack pam Compil Can eae the ae programs exhack the pre tokens LOA Sheree the nesutt fy an oukpus pile. . wy the.’ Secor pars Compiler can cand the Giukpat podued by posh pee ull he -Sypptactic bee cand. peryonr, the Syxtoetea! 5 the oudpet of thin Phase wa fle thak contains the Syntactic tree. this pous ob faye On uvbl the touget Oukpuk & produced. Ore-Poss compiler: m Uthech to thrawelte the One- pat Compiler, %S p only one } i A compiles can brasdhy be Aivided to teso phases bared on the way they Compile, © Araliyeic OY @ Sypntheaas Way, ft Avaly As Naat i a the peonkend OF the compl, the analysis phase Of the Compiler seals the | Coutce program, divides it tuko Goy pout due checks for lexical, aprarrimen oud Sanda ely, The aralysic phase generates an wkend), Ne pretentertion of the Source Reda Frontend | \ Eis Me ‘eprakeukabion Keun Qn the baleen situs hiss ath en ta fase: apneic ice : usit help of inteamedliate ; eg Fass— A pats ths tothe thuough the ew reveal Of. Coreplle Phase A pare of the compile 4 ae phase which takes frput Lens ees ae Chage POO oud Yield oy fev ie ee eae ees de han ei hand rnore than one Pare Book steapping += ™ pesign a Compiles 1. Scutce Lanquacye 2, Taugh language 8 Trylementabion language T-Aiegram . a Sauce oy Target Sa TS eae tes bw Pees c FT Owl ef Compiler (lL lake~a Ihe hase tr be iver Mhe gy Chasacte og a fp aw a beam of as tokens Tokent cam be Clarcibied tbe Auubibion, Keqpoovels- operator, cones and Specick Chrawekers Cc nak LEX foCompilr clevign 9 LEX & atool/ acompulin program that qerciele lexical analyars (coruts the stiagnof chonractinr Gute tokens) Lb LEX bol tselL a complla, the (EX Compiler Laker the Vp & tearspoms the Jp ME % pakke . Te Fuvttion gf LEX Lex Source ae Lexicak lex YY’ rere > Comp} weve 5] € conpita SES exicad arerlyger. Setten [ar Po lex & anaieble W Lux Help lex Progen wre obich G& fo so the fit Slap. the Source ce le name files quege having the fi Ex Compiler commonly jy. oukpuk Os len W.c! cl alll be Uded of the lex law Fives ae Vp to the iW kno ab LEX b act > Ale thak the Jp “lacyy- Snpub to the C compiles hich qer tee Sp fh He fom of ‘a-ouk! Mle. ard finally, the ofp ple aad’ will take the Stream of Chounchean and Geveale the totems as oukput - LE hile_ fpr A Lex program comic ot 2 past, aud & Separated by ‘76 %' delimiters. keewt: Declaration ur Translation wher ht —Declaration Ie ean ya ees He & Headerhiler , —Trantlation ovules These rules Conristi of patter & action — Aruviliasy pyocedssre the aurilasy Section hols auxile , ured fo the actions aay punctions Xe pakkap pee Waite @ LEX proqvem to Yeognige a fecy Wow ls ven Aw Und fo - cyatement % 3 qe include ws Ch ib | cle| paintt Lpantt (* Ts iw a keyword , Vitek) 5 % [edt Eptrif. (7s ba rumba", Yyted) 5% [a-zA-Z]+ Ipatt CZs & a Words Ybor) 2 *[\» LecHos< LG [4 yriliosu procedure Trt mail) L Prfatt (Wo enter the Shing”)s yleOs gj Y Unde hunctten Pi Whitt a LEX Prapram te theklby the captel Verde been the qven faput Shing. at peels At frelde < Sto- h> “& tte (Trorslsic oo a+ evi Ape ( ZS! Yrtext)s 2 5 nan mataC ) Ss prt (“ertix some Stung, Cott capihh urls to bebieen\n") YlexO) 5 ; s me Pe Whit a LEX proqenm be Ge the) count the wo. of Vowels §- Consonant voz : dtirclide ft \Wows0, Con=0%3 Wy rote My A Tews 5 sg tedecion WOK ‘eee [aciou AE lou Jrowets % [retovAbIou] — Reonets 3) Sohieats weoat nh fat matn( ) P ¢ Pret® (* Enter Some String 4 \n)s YY lex()s. "pot Sing \n print (* Number Of Vowselas Yad \n", Vow) s prict® (* Nuraber F Contorawl = %ah\n", Con 5 4 pie Waite a LEX progam fo Count Ube nuunke, of U ieen, tools Spves amd Chetactr ty oa iver halreetas Stal eens 22 Y brelucte < Stio, h> wnt Se-0, we=0, kez, CC=05 “% Lt TW] Edcrts ca== Yrleng 3f [xe] 3serts S64 == V9 legs & [A\ENe] + Buoctts Cotas Vy leng 5% L% @ ft mand) ee ‘ Print (« Enter “the . fnput = \n")s YylexC D5 (pos injp to the leh) print CThe number of Uner= %A\n", Lc); pote" The number of Spaces = %el\n* Se)s punt® (The number of Word = % alin’ usd); prot} (tthe number op chatadeer = ZA CC); g

You might also like