0% found this document useful (0 votes)
30 views

Chapt. 4 Syntax Analysis - Part1

Uploaded by

Bubblegum
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)
30 views

Chapt. 4 Syntax Analysis - Part1

Uploaded by

Bubblegum
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/ 33
Ce ppecizicdtion oa programming language can be ting contert-pree grammar (alo called ONF (@ackus-Nowr Form) ‘i A grammar gives o precise, yer eaty'te understand, dyntach Specigcation yor the programs a o park copar programming fanguage constructed from a So Anveppicienk parser cor be automabcally Property designed grammar, — A ogrammar imparts & dhucure ta program ‘that a eegel For i -anslatien nte, object cede and qov detection. 4 C7707 involves 4 qyeanth ai- A context free Grammar produckons | t derminals, nonterminals, & Atark Adymbol anol formed « Terminals are, basic symbols from whith abinga are Token is a -2ynonym Aor termined - Nonterreinals are special symbols that denote Ae of atings, syntacke variable and dyntattic cabegary are Aynonyms Jor nonterminals one non-teaminal ia aglected aa ¢tayt aymbo] ancl Language da in which We aw truly interested - athe other nonterminals depine other seh o% Stings and telp ik eenota the deyine the Language . The productions ( vecoriting rules) lepine the ways wn tonic h, the ayntacke categories “may be built up efrem one angie and trom the terminals. f Each production consiste amierminal, qollowed by an arrbuyy 4 do lowed by a stig % nonteaminals and teaminale. *) | A) Scanned with CamScanner a the yo grammer with he following eS) dhat de gine dimple arithmehe ©& ay expr op FY, eg> Considl produchon ruler expr expr —> Cexpr) : x expy —> — expr : \ expr > id ep—> + op > op ed op—>/ a { opt exps and ep- are nonteminal aymbole. dn thir grammar, expr a the stark 4ymbol id@4—-* 7 tO) are terminal Aymbols- + Notational ConvenBon! q eunturminals 4 @ thee symbeu are a phils ee. a lower Care deters eokly oD ( hid hee SbO — eperator Ayrnbels bue : : esis COMMA, ete + > punchuedion symbols uch Cs pure i ” > digi 0,1, --°9 : ~~ Boldjace AhINgS auch Ot id or if } © these symbol are nenterminals s- —> Upper-case tetters early. tn the alphabee “uth at A,B,C. ww eaually the > the letter &, whith, token vt, appre ¢ stork aymbel power case italic names sfuth Os EmprA OF Stat TH fy @ vppercase Lelers Late in the alphabeF such O4 X,Y, 2 represent gyammar aymboli (be. either NTs ax Ts) Scanned with CamScanner "ed rr Ah poieerease lettens Lake in the alphabeh, wv,---Z paper tings % ex minails ® Lowercase Greek Cee aymbel. Lebters , 0; By P- vepreenk ating 9 , O© HH Arey, AP (Aus ay are al produchions t with A on dhe Legh side, may be written as ARM ftp 1 1 XK - ly are alternahves jor A- ted, the lefr aide % ot, Xa, ivsk preducken 4 @ news otherwise teu cthe stark aynibels & Derivations Producten may dp expand, the. nonterminal ia sting. cp nontermin Nonterminat on ebb ® wight side a production: copsielen the yellowing presenting be applied, repeatedly au and terminal . replaced by phe. 4bring 9? the. \ grammar for, arithmelic expr “with nenterminal Bre an expression . ew Ere] exe] Ce) |-El i -E signifies expr’ Ary nstane % writen a “BE ES-E ‘ The production E> preceded &y minus sign wv alan an erpy”'s achen can be E can be replaced bye. hin Ce denjues -E) a4 hy ty Or > - - piel ay we day derives oy ir) "derives in one alep", qhe dymbol => means siderives in 0 or more tteps" } ‘The jy mbol By means . » B> means * derives wr Lov more steps”, Scanned with CamScanner Given & grammar G with stork Aymbel S, we, Can use, % ; 7 > relation depine LCG), language, qereated by Qin se “ we Aay o aking % aerminel w is, in LOG) iy and. oni: iy Sw. jhe abing : A language ‘ihat @r be geneatd by & gamma ta fy wp dy be content. freee g LANGUAGE: ate the same w ia called a ventence q ) | Language, they re Af 2 grammars gene i 5 mid iw be eqpivalent- Hy Sa, hae x may a pentenkol form % 4a. dentenkial {or with OR cove ad | a non teaninals |, then x contain A Aenkene eq. Abring (ig etd) nx aentenve\y grammer because, ahew in ce clerdivahion , - (8) & —CEtE) =» -Ud +e) .,-Wadtid) appeasing Ahn Grannis - tndi code —Uidtid) & can be, ES-ES —(id+id) shings Es -E, -(e)--- in derivaken Pare pentential yrs 4% we wake E *-(idid) & derived rom © The detvaias fh on only the teitmere nentermin al) in a penlenh cd form oo replaced at eath alep u codiehy Legimest (E+E) => — (1A FE) & Lids) Et 4 ; desrivakon- R " ey AD) oe 7 UY ED) 7A Add) i gi a. . Hol y the derivehion tn which aightmest nonterminal is rop laced in called vightmos clerivabions . @) -CEHE) => —Cetidd > — Cid idl) ‘Scanned with CamScanner ‘4 favee dye es : « gTA parse [rea ya graphical apr Pathak fillers ouk the choice vege ding interior node a % POT Aree the the, children a the, "0 vighh aide % A bath 2 A and right, by alymbel io eg A 2XIZ., parse tee The leaves oy parse dee OALe labolea and yead yom Leg called the yield or fromber. 4, trees ponlation for roplaremenk* cteaivation tp right, they cond bute derivadion order. fabeled by orne noolerminal de aww Gabeled from lept te ui A Ay YE by rnontesminals av terminals a dontenktol ¢arm, ¢ consicles the avithmehG expr? OMIM AA + che sentence id ald eid Aas & distinc Jopimost deatu chen: E> ere ! ESEXE tid+ BE) =p ere ee id+ E*E pld+ EXE ay id eid we Td + td eE => ide idx id => id id «td with the’ 2 corresp: pave trees, E aia e+ Ee 1 {Wg ou Scanned with CamScanner & Ambigusty 1p grammes tha produces more than one parse tres fee dome aentence 1» said @ be ambiguous. hot An ambiguous grammar one Ahat produces more than one). Legimost or more than one ‘vightmest dexcvation 407 the dame aenkence For cesbain types oH pruser, Yin desirable fhov- Gian ee be male unambiguous y thease, ewe cannok uni qeely determine which pane tree to eleck for & Aentence + thak throw way Certain grammar We Atsambiguating ruled eath sentence F jetvable pase tree, leaving only ene tree for Q methools deal usith ambiguikes:— — stat a vule tha spertics in eath) ambi guess case eohich parse tree “uu \covreck me: guch o rule uv called asambiguatingy rule. thu rule correct am biguihy usithewt changing the grammar: ping he ae — Change the ammo web & form thab . forced the conitruchon oy , arredk parse! trees , Thue removing the, ambiguity: e® Given graram ou G@ v an ambiguous grammar emp > exp oP exp | Cexp) [| num bes, op > +1-\* 4 Etprenion 15-5 %10 haa 2 parse trees, exp sy i ZINN, 7 ‘ ~ 4k i “it exp bp ep \ op exp % — Mububt | ™ qT oti too nub = number rey OP mame Me UTES Scanned with CamScanner ‘ ¢ torveip. syntax tree Ont ce / * - ql “ “io so > / \ - 2 ae S ic 1g SRE NOI = POY pproka 504 1F-BO= -35, ‘ bshes yelakue precedence + a athe disambiguah 4 yule | esta ee precedence 40 multi oe 1 . ., a er ee (a be plicak on shan dubtracker) Consider expr?” 19-5 -10 — iso is, 6 2 yo 1g -5 = 10 b-10 = -5& Co Is-CD) = 2Oy Subback on consid ered Lah aridapht Lepr cisocéicah ve , je. operations are Performed from left te vight =® The disambi quabng rule asocak vily 4 opeeakeons need to be established - no nead gor 4pecificer’ oy Parenthesized expression? hove a arsoualaty oy pretedence . => tar Chan ging the gromacow to remove ambiguity , exp —> &xP addop exp | term : ee addop > +|- vr exp erm tem multep term | Factey Ley is multop > re \wautop ie factor > Cexp) | number 4 sestr wr Mnbmbes abs \ Sin tho grammes, muthplicakion ts grouped ander tetrn Aute and additionfsubbaction in grouped under exp: aule- + and _. vill appear higher (atuse te root) in parse tree anol ths bower precedence, Scanned with CamScanner To lef wrdociake, we wake , exp —> exp adtelop Lem | team eum —> Lem mulop qacker | darker The grammes b exp —> exP addoj ‘tem | Adem caddep > + I~ Acum —> Lem milop autor | gates melop—> % acter —> (exp) | number Parse Aree for 15-5 10 ( prressdenee) aN exp - h aA i. s - exp addop

» FT To Tele bere pom (ED lid gn the care where we howe productions % the yorm A> Aol | Ady |---| Aam | fo | Ba) o> +] Bn whers. no Bi begins with an A, then we yeplace A procuch' ou by Acs piAilipea leo Tea! Alenw oy Al | wa Ale fetal | PAE Cpvicl the cthronrGgranrreer, : Sey mee\% VY NNEAMDNE. Scanned with CamScanner Algorithm: Eliminating (egt recursion Anpuk > Grom mor G with no cyules or €-produchong ivalenk grammar. with no dest recursion outpub! An. eq method: 1 App Arrange dhe nondesminals in dome oe ne A a. for tz} tn do begin for j=l w ivt do begin replace each prod” a the 407" Ay AjY by the productions Ar= &¥ | Sarle + loca. wher Aj —r~3i|bal--° {Sn ore aul curren Ay produ cons / ear rmmediore Lept recursion anr0ng the Ai- produ ch ons end egy Ebiminote dope recursion the grommar ss pale A—> he IGAE Soli» Order, NTS | as o3A immediate, lest recursion for ici , No fer ica, Substitute & produch om in & eael a VE oz) AS Ac | Aaa|bad le , Ad, APs, Bi @2 : climi nate tegt recursion among A product ons A= baa'|a play eh jada’ le & Find Grammar S—> Aalk A> bd A'|A' At—> catfadat lé Scanned with CamScanner fest reuarsion from the grammar A— Ba jAale G-> Bvlabld 2 > order the NTs as 4,8 potursion prem & A-prod’s. tay there ‘o immediate. Uf Eliminating its A= BaA'|ca Aweal\halc : @ ia Als aalée a Replace A in B— Bb| ALIA ge Bb| Bavtblca'b|4 Nove grammor vs pu 4 > Baal|cat Al waa'le p > Bbl earth |calbla ston of B, ' p> cAlb BAB Hp] cA'bl a Brerleaatl ans pi» bp! lanl BE wa Now eliminating Legt retary Final grammar , A— Baa ica! Ala eal le \ p> cAlbe'| dB! Bi —> be! | aA'pe' |e Scanned with CamScanner + hept fochoring af A> epi | eR are (wo A- produch on, and the input, begins with a noo emphg String dewved from a, we donot d.” egy know whether, to expand A oP oy bp: +p we may deper the le cision by expanding AtpaAl , cihen Apter deomng the inpuk derived 41om &, we expand Atdp Bio ove pa A—> aa! Al—> pi |Pe Algevil hm : Snput : Grammer G ie. legt factored, She ovginal produchions become Lege gattering. @ grammar Output: an equivalent left factored grammar Method : For eath nonterminal A pnd the ton gest pregix a common tw 2 or moreigii alternabkives | Lh ote, replace all A produch ens Aap] pal la Boly where p represent all alteznatves that do not begin with % by Aa> mar |p A'—> Bi |p2to> > [Ba A" id a New nonterminal. two alternahve for a w Si Ets| (Eases Eb => iy => Fy Nonlerminal Shad bongesk, progr *» S—»itts sN\a si-> esje Eomb “a lets Scanned with CamScanner Repeat edly apply dh transpormakon untl no ee non-beimincd have commen pPregin _ Basic Parsing Techniques prfecs. A : parser grom grammer G@ iw a program that takes as input as oubpub either o parse tree in error messog & a sting w and produces fence. a & OF ® sentence o &: w,ig we ow ven indicating thot ww nek a bo) odfable cing a sting % dokens from Lexi cad analyzer dnoe the tong OP be generated by the. “ap alo reports 4ynlax pource LAngurye yecve fom commonly oceuming A power oht and ert gies yam mor jor, the errors: At bhowd alec errors 20 that it con conhinue proce ng the yemainder a top ut | yee gramme on - | arsers Aor context - bottom parse trees from 2 2 base type % @ Bottorn 4p. parses ushich build Cleaves) athe ‘gop (4009 _>shigt- reduce poses _> eperater precedence parse: arses <— simp LR aan nical LR LALR. ah starts ie ceith aot and worle @ Top-down _pawiest down @ the Leaves —> Recursive descent > predichve parser parses Scanned with CamScanner # Top down Passing . € ' oy Gr can be viewed a an attempt 2 pind a teptmast ‘ derivation fey 07 in pur biiag . at con be adéo viewed as &/. attempk fp condtruc o& parse tree gor the. inpur Atarting from peoof and orecding dhe nodes % parse tree in preordes . general form 4 top-down parsing thar involves backtracking tee repeat{ie- making. repeated deat inpab) 2 thewn ¢ Consider. the grammar 5 S —chd A —> abla and input shing w= ead 40 cwonshuck a parse tree for thin Sentences 6: the inpub we rete a tree consishng gy avdingle node, Labeled pointes, points +o c, the first Aymbol 4 wo Then we wre. ist prot?” ors So expand the tree. Ss AI™ cA a hoptmest Leas jc matches Ish symbol | w, 40 We advance. inpak pointe, to a, 2rd aymbol gw and Conside, the next Leap Labeled A, Then & we expand A ining SF QL tosmate $ ead as ob : or “and inpuk symbol. Now consider d, 3rd input symbol and neat heagsb b dow not match d, we repork gorbune and go back tp A te Aee for another alternate eohich might match, we have a math To ge back ww A, inpwr pointer must be reset te positian2. 2 veg and altenare Ss a “Aa 4 Scanned with CamScanner ~ Mow there ia a match ancl 1 parting is complete- parser » we creak a procedure for &S40 * sap lement thi F each NT Procedure 5 pre cedure St); begia , 7 if tnpuk symbol 2c! then fee Oe ADVANCE OO; if ACD then iy inpuk dymbol = tq! then begin ADVANCEUS return true end. ends 4 return yalae end pre cedure ACs hegia 7 isave se inpub— pointer s if inpwaymee | ='a’ then Pegi? povancel &y inpuddymbol = 'b' then an : ADVANCE Os AetuAN true end end ‘inpuk pointer := ave, /x failune t tind ab */ ig inpwt-aymbol ='a' then | beg, ADVANCE (9; ebe end Aabaro usd Aetuan false end Scanned with CamScanner Difpivation:- A bepe vecursive grammar can cause a top down spouses infinite loop. when we by % ehpand A, wes fo go in on moy eventualiy ind owuelves agarn tying t expand & withs We.” proving consumed any I/p- -4 we make a sere seqene % error neous expanse! ons and subseqently, discover @ mismatch , we may have & unde semankc eggects - - when ot lute. wu reporled , the errr actually occumed: we Have a very aitle idea wht # Recursive Descent pawing, Gk eliminater the need) for ba dn order that no backtracking aymbol a and NT A —b be expan cetrodeing over the tnpub- be repired , we must know, gimen dhe curren clp ded whith ome @ the alternate 4 pred?” A 7 di] a2 | -- = Jan a unique abfernate thak clerives a Abang beginning with a@- A parser thak used a rer oH recuse ve proceduned te th op with no backtracking @ called yeruyine pecognixe descent porsr- 8 consider the grammar a: ——>TE! E' -pgre_'|¢ Ter Ti aHeT' le F—(e)/ id Scanned with CamScanner ae @ amyhon- bark tracking rrecursiwe detent parser Us- z " procedure, Boo; begin TOD EPRIMEC? 2 procedure EPRIME Os ' inpukaymbol = ‘+! then begio ADVANCE; TOs EPRIMED POs TPRIMEWD ends procedure, TPRIMECI, i4 inpur dymbel = '%*% then begin ‘a ADVANCE L); FOS TPRIME CD end; precedue FL; if inpuk aymbol = ‘id! then ADVANCE © ele i4 Sinpuk symbol ='(! then #8" govance Os £0; b ty inpuk ay mbol = ')? then ADVAN CEC > eve eERRoR ty end : ee ERROR» Scanned with CamScanner Por a grommasx to be duitable. dor Aecuuive descert pothiy, it phoutd be lat gadorized Ca procew o factéring othe, common -pregined att exnates.) Transition Aegrams tun ba wed A 2 gowchat or plan fer \ Tecursive ctercent parses. For each NT AS > Create an Wwitial and final Cveturn) State, 2> For each produchion A—>XiXz---Xn, Create a path -frem the inibal tm inal state, with edges Labeled Xi%o-- Xn for B: oT E29 tees toe au T: FT 30 4a T's ee € fore: 9g Epo 2 Stu possibly t simpligy tronsikien diagrams tg abst benny diagram in ont anothers _ Simpugied tronsition agrame jor et: Kets We \\ gor T? ame ie ad for Et: ¥+NeE 6 for F: jor & ebro Ered ze id for E Scanned with CamScanner A Predichve pase on eppicient way arup lemenbing recursive descent a8 ing by handling the shou. 4 ach'vakon records explicitly tha implicitly via recuratue calls. model o nonrecursive predichee, parser Stack outpur A table- driven _ pase hos an tn pur bupper 4 Atatk, « parsing dable and an eutpuk Afream, > The inpuk buyfer contains the bring & be parsed» qotlowed by ¥,a aayrnbel my CO GS right endmarker indicate the end % inpuk abirg. > The stack eontains a regent % grammar $ an the bottom 4 the stack» Gridi ally , the slack contain the on -lop % 4. —> The parsig doable wo g-cimensional arra MLA, a] , where a a termiaal oy symbol ¢. aymbola with short aymbol % the gem Ayo nontermingd , and a sche parses ia controlled by o program ‘hak behaves @ f follows 2 the program eonsidat X, Ihe aymbol 0” 4op % aback, and a, the current inpur Aymbol- Scanned with CamScanner These 2 aymbel cleteamine the athon %a pars There are 3 possibith ett @ 4 X=a=$, the Completion 4 pausing: parser pops X %p the stack. next inpub ay imbol parser halts and annountes duceem pd ‘ @ ap x=aFF, athe and advances ' inpak pointer 4D rn tetminal , the pregram consults entry MLx,a] | Kr produch on cthe @ xX 4 a no q% the parsing 4a q che grammer oy an ay M[X, A) = 2X uvw4i the pers ek by WyU ( with u on top). ble na, This enty io either a exror entry, en ~rep laces xon ohe pore sur dop q sta pin the production weed « TL Mixa ¢ ervey + dhe parser cals an error recovery Youbine. “g: Fe laa Grammay :- eae. Ei + TE'|G TFT! tla eet' le F— Ce) lid wohith tk a configuration in : aq & ontop, apilially, the Parse~ te in athe dtark Aymbol with S, hos $3 on the aback, gor (w la om Abing) and wh in the inpak but fo parse dhe inpuk tdeid wid ,the yollewing predichve porsing dable in useds- Scanned with CamScanner de Eive | ele Blanks Ae error en’ expand athe nonterminal woh vohith with the inpub sequence, % movedi- tries; non blanks id+ id wid , the predichva parse. mal i Dicom . rhe) reexet|] wie | Tie ae aro) | sadseate 0 proaucion on the atatk. keg the he inpub pointen poink -e the, Left most symbol g the bing sp inpur column, A parse. fyaces ouk & legtmest derivation $7 dhe inpus. ' che ilp aymboly that have already been tanned 1) followed by gvammar aymbot on the Atack »make OP the, Sett- gentential qormi in the derivation . orack sneuT ouspeT id tidaid $ | grid xia S ig tidxids E> + TE! Scanned with CamScanner — ee tt ere $ i pra geiTid id pool et! ¢ #8 $ tte Pe £ 4 Eli+é The Construch'on of prediche, pauer te aided Y 2 qunehions : EIRST and FOLLOW , which allow ua ZI/ tp the enbie % cw preclich've parting dable for 4. Fh © ww any bing of grammar aymbols, tek pneliee, be the det 4 toumina that begin she sbings derived fyem ob. 44 ot Ee, then € also wy FIRST (LD Jo compute FIRST(X) Aor all grammow symbols X, apply dhe oll- Autes Wohi! ne move derminals or € tan be addec/ t any FiRsT et @ 4 x4 desminal, then FIRST(XD & Ax}. @ 4 Xe “ya producion , thea add €'4p FIRsT(A) 1 od” @ if Xv rontermined od ee a in eipst OX) WE for dome i, O& ‘is ty FIRST (Yi), then pla ond € ‘uv w all 4 pmsT id. © EIRST (Ninn) ee on) oe de RreAPOHD Eu FIRST OY) Fer all Jab do-e k jlhen 4 add € +6 FIRST Cx) “Fig compute FIRST fer ‘any sbiag Xi Xo 7~ “Xn, Qdol %& FIRSTCX1, Xa ---Kq) all now symbols od erRsT OX) - Algo add PON symbol of Frese ¥2) tH E ia Wn PIRSTCRO, 2nd add do on: Brey add € ~ FIRST (xits--Xadig FIRSTOD “ . contams € Scanned with CamScanner aE: foniider the orl. rammae . ETE! f e+e |e Toe FT! whe ee T IE ' F-> (e)lid for riest(E) = FIRST(T) = FIRST(F) =¥ Lia} “s Oh 16 FigsTCE = 24, e4 ep eiastlH)= BY, coe First (T') = 4%, e4 - ernst (A) 22K, Tee FOLLOW(A) Fora nenterminal A ia detined t» be the det gy decmina a thak can, appear immediately the righty A : in dome AMlenkal, Form ,e- the cet q@ terminal: a such that there exis a Aétivedion a the $o7™ 82> wAap www lA) aor all nenterminals A, apply oll. Arles TW @mpake FOU can be. added + any Fottiow deb. uht | nothing. “4 land B84 fu Plaw $in Fotow(S), whee Sa stat fre $ dhe inpuk Aight end marke, . Au Sh thee ‘ a prod? A> uBR then avery thing in F1RST Cp) , except gor & ih placed in Fortowle ). ph) £4 “the 0 prod” AraB, or a pred” A>aBp, whee Fras B) contain @, then every thing Wn FoLlow (A) "a Ww FOLLOW B) Scanned with CamScanner qPonider a 1st pred?” ETE 4 A > &8 aps FoLLOw(A) HM forrowce) PMD ©) len Qa pho ah % Fouow(E) » FoLLowe') and prod? el-aeTe'le : pre cane! & inst (pd oo A FoLiwl 8) sy eipsrteldia th peutewtt) Muy ond. poghow (A) ve ‘wm FoLLow le) e rE este Ga foLiow LEN) a "BA vow (1) Rule: 34 pred” \ P Mies Fovtow (A) u Ws POLLY) fol gute: + poinw (1) oy Fottow(T') Ath prod 4 ay a if Tos yet pinstip) FoLLow (8) Avr w&B co opiRsT(T') | % \gorr)ew br) Ruler fe ee na PG fe year Foriew (A) ie wm Fottew( B) Ruled i oo porvow(T') 9 &O Lrow | &) ST th 6 pred? ra (a) pirst (p) vv wo FotLow(B) p= cep LL Forrow (ED Rulez ip wt wt Soe “ be 7 Re ww sca gy poe OO) Se 2 Fouow(e) = 3 a auaeaid edie! Foirow (e') — 3 couse D5 2t4.)3 Zrimrled, rouse oe) Fouow (T) = =34.4, 73 Fottow(T') = J Fortew (v3 zat bs Fou (FI = 7 Fottowtr') , FIRST (v3 = 44,8,0.%9 Scanned with CamScanner Cono a hruch’en |e pow ingle: BepO Foy eath prod A> ob 4 grammar, do akeps © ond 6 4 | OF sep@® pei y cleemaiinad A a IRSTC a), ae eed Aol ‘tb? ‘ma TAjad ‘ Oooh dkpO ty C ‘wm eiRsT (0), adel | A => o¢ 46) 4M) [Ane fev Cath Lerminad b tn FoLiow (A). 44 € ww riest to) ard 4 with, ForLow CA), add psd fe ™ [A,$) Atep@) Make, each unolskinea onby ‘4 ™M be enrey. Scanned with CamScanner UN Ae at OM ne! @ whoewry! D Kew e @) veri © roger! © vex @ rer) @ to-wid Posing Non deamins : = \ 1 . \ y f Pima (at) wade nb ind Cid yy ML este Me, id jae d he! WESTOITE I Gay oo ME +] = eleere! Se Fouuow (ED= Fy} AMCel = m[e¢] . boc rinse (rt): fiw)” OM, 2M Lt teehee =,T— ett riksr (Mets 3 ey Nevbare ars wir! Fim (ODstey ronowtt' a3 by I,44 0 aM Ertl $J = m7, )J=mOrb+) 2Tse Funsn ee: . . rmor (Ce = 905 & MDF, (] = pole) ernst! Ctelas tid gM De td] Ftd dable we” hp Ayre | vd ' x i gore! 1 beat vot t tlw & yw th Scanned with CamScanner predickive parsing. dable ger the following By construc grammar and parse dhe sheing ink di, ida ¥ potty : Boy ope» ‘int | float taiar\ Alea yo ia, Vid apie v—=viav' qeeiny vig NE 4) rind FUR => Lead FIRST UT) = ink, jloaty cunst(v) = nh YeMyar sey Li4h rinst(VI= 34,€4 , Yi) Find FOLLow 1st prod? DoTV Ame FOUL A 88h 2 Ratue4ate we Fest (Vd Foo) ard prod” Tor iat gloat eo “ee a ae ne _couiowt) i in Fowtow( a) wld) in “FoLLowly, ea) ; torrowet | : hy 3rd pred” dy via v' Foussnta? om Feuewl 8) A> vB Lowlv) 0 » Fownow(v!) ath rod” BORON Vay Forrow(A) vin Ene i. aLLew(Vi) vin > Fottewty) | A+ aed ' ) 4 oprewl 1D = 245 forrow(W = 244 i : poiswl v= aby eouset* yy Scanned with CamScanner ernst OV=2 im, jloak y M [pyint = > oty Cr guat= Dav +, pA Tint) = Tink © vs ior kph First (ink) = Aint 5 7 | @ Toqgeor Frnst (alent) = 3glot pq [Ty loet] = TH @® voiav' Futsr (id v= 314g OOMEW, id= voidy! ® i @© via ov te First (sV)= 394 LIV, Je voy @ vive Fiest (€9= 364 cowow v') = 284 i MpVvyg] = vise Le ie ~ int tan ide, Doty tak dt, vel T-2ink tdi, ida. pausing complete - Scanned with CamScanner 3) eliminate Lege qactering and Corstrutk predichwe spossing table der the qotteusing » S—> aAA A+vas|bs|o Parse the 2758 aabaaa => Bey Legt Jack : 2 A aA! | kde bS Als s|é common prefix ia o Ap pred 2, obtaining FIRST, first (S) = Zay First (A) = 2ab4 first(Al) = 1h, frey Obtaining FoLtow , : pt pod? = g->aAAe first (p) “9 fo uow (B) Aer jes [rien poco J erRsH (PI = HOH FE + No fault 3 FOLLOW(A) “win Fotroto(B Spout) #7 FOLLOW (A!) ] amt pred” Apa At arabe ad pred” — pa bs [Fevidue cay sw Folipwls) ‘1 cou - on conan wo atl pred Alves [Fettowtad @ uw Foe Ae = 2 rousga,eaunaa 1 Po AA pusouts) 23, 7bf aos ce eiRsr (a) ‘ forrowl A) = Faby, by oye ee wuts) 4% ai 3) 4 . prota Sb Foe AD = 3 ar b§ 44 a ro NB FORME) iy in FOtourA) | Scanned with CamScanner ‘ FIRSTLL) eurst(bs) = Zb4 oe rinst(aAA) = 4ay “ M[s,e@J] = ss aah eiest(aAl) =2a4 - M[A,@J- A>aAa' M[A,b] = A—»bS oc Fiest(S) = jay <. MPAGA] = Atos. \ Alive EiRSTUE) = Fey Forrow (al Jo ards, $4 iM [ASa ha Al>€ : MLA bl = Ale ee a Nontaminal aX J Bt Ss S-PaAnr A Aan) A->bsS \ 1 AY MSs Lee [Abe : aa Flp sheing aabaaa , } ‘ stack ay string ok ess $8 aabaaat $ Lia pang dabaaat Saha Ag | FS? cS pr * a gbeaad Aaa! “pops ee oo baa at i | vaaah | Abs " gaat | sana aak A>an | —— ——_——_-— _{—_—_—— | aA ak Noe ig Ales Aeten | = 7 a _ we need + } $A! of #4 Aah! oa j + Woe posing (pouting comple | Scanned with CamScanner LLC Grammars 7 ay” = ; for ome qramnmae , | pauing A mM ay chane some entries that corr rast ly defined « i recursina oF Ombiguous | then mM wilt have arteash dhe multiply « dagened entry. ) | A grommls ohese, pedting | table hao no. ptttiply- - oles neof enhies nad bebe LLL). The iF °L" Afandly if scanning the ilp strom lepr to right. ahe ard? ‘ M lyre oduting a Leptmest derived on, | A” atondds fib ene inplt symbol of leokanead of cath dep to coe parsing ack on qedsi ons. Crammen @ va iLbCD if! ‘and Lonlyh ig whenever A>] B are 2 olisinek'!\prod™s 94, & the ,goltowing. cand hold. ! ® Fer no terminal a do both w& an p dere, Abings \ beginning with a , be wool ° a eo o and daniidesive the en ie @ At mah one % Bp si pty ag. Oy Pee, dhen ol does dgt abetcye any. ashing beginning with o teeminal “in Fd LtowllAd , «, *N , ; 5 i . : [Pinay AK ‘N\ HINA | Scanned with CamScanner side the jollacing granmoe ' S—ricts | UctSes|o Carb tontrur the pouing table. vray , ' " SO Legt, gator Leb fort og icess |e ils es|e Cab Compathng PIRST © tCeat Ta} ee i i= First(s') = 1e,65 First (c) =4b4 ® Graputing FoLrow BF prod” € See “yp fou (0) pe BR vn FOULS) i Fiest ( \ a & 5 teks S [Ramey ue Reupulsy) ob - _ he ! ¢ —ictss' ‘st 2, FOLLOWS) 4 Fouts) Ao Par. ernst (p)=€ Not needed on pred” ‘ A : 8 oles roumatS7 = Fores?) 18 — piasrce) except © | So LESS’ peer [py wn Poumata) Fouow (s)= 14, e4 + eIRST(eSst) oo Foucw(s) Foutowl fouowls')=}gre} “Zag : Fo tLe roviow (c) = 3-4 emer tp) + € R Scanned with CamScanner S-victss! riesrictss)=4i4 2 Ms, =sei sigh ae Finst(ay=Jay M[ss¢j=soa *, en sia es Fiast (eS) =e} “MLsbe] = s'ves sive Fest (@)=7e3 2-Fouowts'= 74.64 \ VMLsigdeshe cb First (b) = 354 . M[s',e] = soe f { 1h) ceeM Ee gecee 1 | Ponsing table 4 Nt | a | & |e |. + 4 fad ie a ’ S saa id oo Sie = w | s! Sises ’ 3! Lee Ur ee c \Cob / | j the entry dr Mise] contains both S'>eS and s'se ey for (s'J= 30, $5 4 2 ohe grommas ‘wu ambiguous Thy grammar which contains multiply eegined entre ‘4 % nok LLL!) grammon . Scanned with CamScanner

You might also like