Download as pdf
Download as pdf
You are on page 1of 78
re —— eo Syntax Analyze a. | Syntax Analyzer is also called as payer» Role of paauer: at tokes ctaieam of tokens a6 inpol cab glhiuctute of tokens cont oblern we can cons helps to vecovet 3a 7 a checks qrernenali a7 Grammatical structure Ww specified by 3 of token clear is valid without any pt © parse bee; if there ts a problern tren pte the evior by providing additicnal information. ext free cprarorns 6 huct 3 > ital | 5] Sra ea, a j 2 |e ed T sen : a Li i 2 |fontend Fepweke- ° ie 1 1 RS Ld, Ban: 8 otha i o| ‘loplevst | » | » 4 Types of eros: sy Lexical eviots ® a;dyntox eriow Me ® sydernantic errors ® luy Logica! evto1s a) |y Lexical extors: a | 5 eros tohich ave encountered during token formation. | Fees eal are single character evtors ' bovt | | | These aie very easy to report and 1ecover- | eq: ' io rivopelng of identifies and Fequorde and operators | a are re ee | ! ay GMleqal characters — BA skiing caithoul double quates(" “ 2) Syntax errors: Syntax eviow ane encountered due lo invalid centences and ‘valid, chructure. of a Proyor: eved compit es doesn't execute the > \dhen gynlax evi0t Ws eNcouN’ program. ao Vi eq v ) Missing parentheses » Missing cernicolon. 3 Using a. variable caithout declaration ly incorrect Ghuclure of loops and selection stotemenko- 5) Gemantic ents Semantic evtots axe encountered due to violating the meaningness da progiam. Jo These ertoms ore syntacki cally comect but semantically incorrect Lo These eviors produce inaccurate, qevults = 9.0000 Cirmplicit conversion) af typecasting is pevforrned c= Clloal) 5/, 22.5 (explicit conversion) M isrnatched oper andy 2) Inco rnpleke operands eq int anls), bs Isa been bes . { i an(s\=5 ; NNNNPNPNPN OHO HPO EHOAMAAgGaas DON] 4 ~ a nannnanna”N © arin ep alse iw nalched coilh wotong if statement Wf (cond) { i Ceond) Hf tH is virple if statement elvo ctatemont; 3 \ 4 Amayfndex Bovnd uy Logical extoWs they aw occured Ave tg incomect, logic, difficult to report : oo rect, logically incovtec 4 aeoult > These are Ver I> They ane eqptackeally co These eviors produce wion 4 » Something is divided by 2e10° 2) indefinite vecutsion s infinite loope uy Noll aeference: ¥ Exton Handling “Techniques: 1y Panic roade tecovery 9.) Prose Jevel recovery 3) Er108 production 4 Globol covveclion:; ‘*>SOUVOADODOOYD @eaceaod GCUowoeodood GG6GOGSESE 4 Hf Panic made recovery : the pawser discards inpol uyrobals one al a lime unkil one of a designated cel ov synchronizing Jokens i found usually delimeters ,cuch 66 semicolon ~The synchronizing tokens ave arn tv clear and onambiquous ot },whase role in Gource prog? int abe, ory, com=0 5 fl discards and gives e107 a6 invalid variable ag it toasted eoith a number >) Phage Level Recovery / pot: symbol by correct inpot cyrobe | Gt wplaces the incomect in} and also eplaces the prefix of 0 remaining ques or b, aeplace ‘,’ with ss’ otiing, c=arb; ( 1 hare] 2) xUizoj ici rity) - 3 Gt places finst te00 chavackus of for = for lie; igioy ita) t | | 5) Exsor Production” Enon Prose > By anticpating common ertor s thal right be! encountered oe aromas for the evar constructs - can ougrnen! the L.A poxses constructed fiom regular grammar augmented by evt07 productions detects the anlicpated ertors when AN erto7 procluctisn is used dering parsing. these Spry an , om. 4 7D P NDP 99H OLMADRPDD DL LDf Pe HSHVHHOUHELUTCECECEECCCCCHCCHUHCOHOOHOOEOEES 5 ie Parser can Hae appsopricle evyar chagnasties about the rromneovs construct thak hav been secognized in the inpol 43 Gtlobal Conection Sue would like a compiler to moke as feu changes as possible in processing an incovect inpol olving = There are algorithms Sov choosing a minimal vequences oF changes to obtain a globe! least cost conection. + Context Free Garmmars Context fee Graromans have 4 tuples Gzlw TPS} ihovart Ve eet of non terminals a Tz cet of terminals P- production wale!) 9! bonous) 6 = karting eqrobol oy 5 non ferminale represent etaternents of a programming lang vage: L, nonlerrinals are syntactic variables that deriote vel of ahiings bthetokens:! | ly > Terminals tepresen z 1 ch chings ave foumect _,Taminals are basic symbols Fron ahi a stmt — if (exp ell else trot - gt ic the context free grammar of if else. if Hnen, else — teanni nals tml. evpt- nonterminals ' 4» devia Lae Gh 6 4 process > Every derivation stat ah of vhaing inpot ching thal verified by “ror 6 toith the clatsyrnbol of grammar & > Syntax of source lan vage Is specified by cet > 1 verily a token, derve acting af derminals using qraroratical rules af derivation exists then token is valid othensise invalid Haiwalion process Derivation clarks with stort symbol of production exrninal, vailh terminal. > until the complete derivation contains Slep-45 idep-2: Replace non |clep-8: continue clep- | terminals la “Types of derivation : - » Lett - most derivation i) Right _mnoct derivation. | « Left_mnost derivation ses the leftmost nonterninal to ape | Alooys thes tT production Falah e 5° i | Right=mact daivation: | Ahooys chooses the right most | rule nanker rina)’ 40 apply prod ction gly EEE E>Ere Eid ida td & id ct tefl gost Qevivakion Right ndost Oeanic0? Te € fe € eae id+€ ever id+Erl eiexid idtid #E Evid id V+ id#id id+id #id ae) : DD PAPATANRNAMDDBIPDL PPD wn ew on a Cal ( POO dddddddddddddddddddd dddggl + + Paroe tee >A graphical representa! ~leaf nodes representy the terminals [snerna ‘nodes nopresents non terminals Ls Each interior node of the parse tree sropresents of production. lion lof derivation is a, parse tree. the application 5 wot node of the pore +1ee ic ctavt-oyrobol of a qraromat eq E ETE 1 Eere Eid idsid ¥ id - LebbastDewation . E E E [ Py 5 JIN. 3 ES > SI E+ € Boe & \ Ve AS id id EF F i e-m Righ!iost Detivaloo - ' E iE E Pow 2 IX? Lhe? LYS ere &4 e+ & € \ ef bre A /N i © LN 1 ee © ew F E \ \ \ g + Arobit vily: 7 a >A qammon whieh produces move Than one parse diee is ambiquious grammar A gaammar thal cenves more than one lefl roost derivation a rightmost dewalion wan ambig vious qraramas + tefl Mast Oerivalion ie i 5 Ere JS id +€ e+ & BoE iy {I id4id¥€ | id+id sia Id vid ; _E ' E Veer | JIN | Exee b= i eile | idse+e Ny idtid + E [1 | ida id rid id id Right Most Deaivation 4 E E ; &+ E L ~ E+ErE E+ : a “ id [Ne Eaidei \ . id id+id+ id i: id A E Ere / ih Evid 4 4 ek 5 exe) Roty idateid a ‘ ' id aid # id a id ~—rrAnrnannmn MA HKONNNNNANANAA AR AAR AR AAD. mrCbecebiddddddddddddddtdlldidid ais - _ 4 olution for arobiquious grammar W Precedence | ps Associatwily \) Precedence:- ority as ahich operalo evaluates frag 219 Hel of Ee? ~ | 1 nS ng dN, iy er € /N\ id 1 4 i. il 3 ut | id i id id ee E22 3 4y a \\e iL a i, A af td be AN. id rh lg hd e id id 1 4 rand 3 ave convidered as they ave conect : bottom in + Operator with highest precedence ic placed at the parce tree. EEL E EERE tid To achieve operator precedence we can fam Eo ett To TKFIF Foid Lelirnos! Oevivetad /\\ — ea ( a eo TtF 1 a ‘ id Ambiguity of qraromar is pe Sic, r.r,”rtCOCUCSSsCi‘ ‘RCS EES" SRS AE NY SS RUSH a ceasaeiaeae tae eT jJ then too a move Game priority operators existe In expression coe use ossocialivi y = Milhmelic operators have left bo ‘ight avvociakivity. eq 10/2 *5 ~ Assignment operators have iq eq azb-5 hk to left associakivily ge ESEKE b> exe Evid id vid aid = Lelimost Derivation oN LE +E AN 4 7 +E iid Right ‘asst Deivation |, : d n T fpjppf n SIDMPPAPINTAIANNS ~wewewuwvwnv Ca a i a 7 FE e=ele Eid id = id=id Mo OF Rup: E /\\ AN. \ 4 aN a id id A € bi ds 4 €2T-ElT tid | E /\\ Te & AK ia fh Ee \ \ at id se Whiting qrornman- Regulas expiessians (Pirite Avtomata) to C&G oteps cote a nonterminal SAi’ 1) for each tate 7 of the NFA, C7 fiy G1 clote ‘i’ hos a Jnanwition fo elote *Y on input e” add the jecHen =" AY at: ; ' vy TE the tate 4 goes 10 cade sj? on input add the production MAY 1 i an aceepling glale'add Are" w FM oh f elate make Ai be the start cyrbel of the wat Vis the. chav gramnnas: HERE aEEaE Reiter ee ee rr renner cnr —— # (alb)* ab \ G0 + 6+) Ao 2aMiane| bho Map expressions and ctatements Ai bar A, bAs A, 7 € ; : & Elimination of anbiguily for selection ctalements: 4 Dandling else problem sedaleturt ie matched with 1009 if claternent called dandling alse problem ifCexpd then ilexpy) then és else Sz “ec chook > ih expr Phen oink os — ifexpr thenetmt ele tro) — other 24 1 pif Er then Si eloe it € then so eloe S3- trol. if expe I cimt else stm. A 4 \ e 6\ iP expr then &mb ye stmt, A A . & Sz Sy FI FH Hg Hms PaP' ope AQ) nod ao ¢ { ( B 2 4 : AY ac) 3 : JI J ~ pet @adbvibiddddddddddddddddddddddddébse [6 VIESEAa| 1 Tots ele F > te)lid E and 7 ove having ell recursion Griammon ‘without: left secutsion, elo a+tellé Tort TPoerrle Fa (eid 2)| a+ aABd| Aala B> Belb av ard dale A Re DEB e~Te! viosog qu mathod cit aoibneinnit IP PPT "4 i} fp eal WIN B—Belb A AUB “| Ba Beh . 15 eB ]e 7 en oftes alirninating left recursion iv S aca’ : = al-spd hilar le = ‘ Bob 8 givoblle a — 2 =| y ee CUCM ECECCCdCdd ddd dd dd EEC ddEOES --— {Lsayla 9 [Lau Ss Lo Lists ts having lef! secursion Ne BR Lost! Us,sule Grammar after elirvinaling lef} recursion is | Low|s | boasts | Lost! i | Us, 6ule S$ 6061601 So Gasislo! a= B [A s'5 osiss'|é . | SoA {As Ad| Ae| abl o& A ~ nal aelablas is having left vecursion. R RAKE A-abea' na atodn'[ea'le Grarrnon without left vee 6oaA ®@ pasabntlach' ptode'len'le widen 6 COM borg hy po Abele A> Ane RAS lp - Graroma: cithou! tet} aecursion 16 apa’ Na —7 nwa |e so ots! pe 1g LS} | | A Bal Aale B—OBbI Abd BV to having indirect recoision: A~ Ralale A At BE A Bal'IcaA! alsaa'le cobstitule A in B productions B- Bb|Gaalb| cabld fUAce op Fe A Bs ca'bs'|dp! BI, porfantbe'le Griarornaa afle elimina A= Baa'|ca! Alsaalle Bocr'bB' de! Bls pellaatbs' le ting Jett recuwion is xo xebléalb so 6blxala x xsb] sal b mop A X— Gax'|b* xioobe le wobstitute ‘x’ 10 second sosbléox'al bx'ala # gobx'fas'| as! 6b be'fax'as' le Gnarman afler elinnl X= Gax'| Dx! xl-sgbx' le ba pxias![as! s'obs'| ax'as'|e prod uction nating left recursion is apap a -) a f = ” OOP nnn pp pp RAADMNS. 2297 iff, - ‘ 3 S> Aalb A» Aclsdle A-Aclsdle Gl is having indiaec! vecursion 60 wubslatdle & in A production 6-Aalb A-AclAodlba le RAR ALE B avbda'ea' a’ ce'lada'le Grammar sithoul le $= Aalb As bdal[ at ANNA catlada'le «Left Foctowing: A-vcprlapsletfal --- ABol¥ A qearomas cath common prefixes More than one produchon an the Ris of the graromas starts some syrobal 1s called os qrarnmmax cath common prefixes Lofl factsting: G4 is a process 0 in {eos ot more productions psaplop.}ape-2- apoly- flaecuidion is with, { aemaving the common ‘eft factor thal appears of the came nan teansinal Aoually A'pi] P+] Ue aa 2° ee W so icts| ielses|a |s-ctslictsesla re Cn goitlss'a St eles »)|p-anB| oBelane [AS aABlaBel ate |y A ip ap A Be | psaetlé 1 pt nslpclac Again two praduclions sl - nts aplaclee } a eRe hS | a'aat|se | atsele | Gaammar aftes left Factering Ww | A aa'le | ats pat|ec | at, ele ) 3) gr bssaac| bose sb|beblo $> bSsaas] bssashl bsbla Roa 8 Be, «BY. sobss'lo- ‘ __ go Saas|Sasblb- ‘ productions atarting with Sa’ ins apply, lett fackoving Again +02 gissaas|sasbl b K LR thy sodas" |b cas} 6b taaling with A” 60 apply Jel Aéctoing an it Y oo R-R-P ph f-h hh p DDD 2 SATT STL I >” |; ARS %) Af os? Pree bbbbbddddddddddddddddd dddddaa 2) Grammer alles lef! factoring is S> bes! [a 4 6k Sas"|b "4 agleb. $+ alablabclabed 65 alablabclabed le tnapem < BY: smas'le S'5 elb| belbed | Aqoin LBS production 19 cl ane casting aith Cb! co apply lel Factoring. S> be|be| bed le A ERR CB Y sb bstle 6G elbelbcd » Gramma adler emoving left factoring is soas'fe glo bstle cs" eledle ‘Types of — Farsing + Porrsting + Parsing is th a. okting of Aetminals can be. generate rama she proces parsing: a There ave # Top down Parting gy Boke oP parsing 2. process. of determining hous Jd bya of constructing a. parse ‘ree fo called two types of parsing techniques - Top - down parsing . +A forse tree fn ths, Paring can constwaeab ina Lop. down approach + i The precess of construe Hing a parge tree Lorn oP | C stant aymbol) to bottom (Tern inal) fo Known 2% | fop- down pursing * LT uses leftmost dextvatfon - ah 1S claseffed Into kwo types: ay-Top down parateg wetth tmelebrac king (Brute Force Method) | {iY TP down parsing without backtracking | Recursive descent Parsing Non - Reewesfve descent Paysing ¢ Pars tng lord LLG pars fing) * pred relive. 2) Bottom-up parsing The Preces® oF constructing a bottom input” stving) to Upstart symbol) 1S a otto - UP Parsing: +e) ve.duce parsing - paree tree feo | lenown | «Tt uses hi te oe . Te fe, classi rrightrmost™ davyatton in veverse - fred tnto kyo types - *operator pre cadence Parsing + st) LR parsing LRCLO> parsing RCD parsing LALRCD parsing CLRLY Parsing Qo YA MY ® « a9 \ SA MONDMAMMMOOODDPDPDPPPPL LLL LYS Oooo dbdddddddddddddddddddddeds 22> Parr Sing WoR- down parsing proR- clown ryoPA own | i) . Passing wilh — Parting wrthout Peta : ak backtacktog — backireck-?ng ree pat 9 : : 3 LR) sLRu) Recursive Descent = Non-Re cursive ULRI) eesing Descent Parshng | , art) -S Top - Down Parsing, 4) Top - Down parsing with BackTracking - ( Beute Force Method) + In thts method we will have. many pooduction ules and while working with them $f there 1% a. problem with any oF the, production sul, we cin back track and goes to another productfon wle « / g>ckd Input sting w =cad * ELi haabla i tacks with start syrn bol S Cty start oe 0 7 hy, aed ti) checks productton ules vt-Ae, h has abla, but ppreh TE considers ‘ab: ; Te Se are et ? a, aN “Check the. Str Ing fom Jet to Right, A we are. ger tng Cabd + whitch 43 ve wrong string, So backtyack @ a a, » wg. esp ts Back bya cing Row Consider Mw sas ; 3 Now, we got’ the gfven sting which hod ( is cad La Po ) sock Bd | Bac “fh Bed[aab B acl dAl bd | a Sy xt beets mo te 3 $0 Backtrack « th doesn't. match input string Spat sbing : bdac- > gn Ft doesn't match the [input stro: C a FS Oy bacte track * Avacl because+ st doesnot % pict 8 tr’ng (A 7 ~ match the fo! Oy iss | =, | Aes ewe “yakae ; »/ > gt matches the input sting + Bo. pack ere L-2-9-9-0 9 | em § DAD DD DM DMN DP Popp fp ML ADTt

You might also like