Compilers. Top-down analysis. Third course Spring term. Top-down analysis. Top-down analysis Overview. Introduction
|
|
- Beatrice Tate
- 5 years ago
- Views:
Transcription
1 Complers Thrd course prng term Alfonso Orteg: nrque Alfonsec: Overvew Blnd serch, depth-frst serch nd wdth-frst serch. low cktrckng wth LL(1) grmmrs Procedures for modfyng grmmrs lmnton of left-recurson lmnton of lmd-rules Grech Norml Form Defnton Procedure for otnng the GNF of grmmr xmples LL(1) grmmrs Intl exmples Defnton of LL(1) grmmrs yntctc nlysers sed on LL(1) grmmrs Introducton We need to fnd dervton from the xom to the progrm nlysed. However, dependng on the grmmr, the numer of possle dervtons s extremely lrge. There re generl strteges to solve ny prolem wth lnd serch: Bredth-frst serch nd depth-frst serch. In redth-frst serch, t s gurnteed tht we shll fnd soluton. In depth-frst serch, there mght e rnches wth nfnte lengths. If tht s not the cse, sometmes t s possle to fnd soluton wth less effort thn n redth-frst serch. 3 4
2 Top-down wth cktrckng: concepts We cn consder top-down nlyss wth cktrckng prser s prtculr cse of depth-frst lnd serch. The crteron to decde whether rule s pplcle n gven poston s the concdence wth the non-termnl tht s n the left-hnd sde of the rule. We shll not contnue long n nlyss pth when we hve termnls tht do not concde wth the progrm. We cn fnsh the process n two stutons: If we hve een le to generte ll the termnls n the progrm sequence. In ths cse, we hve een le to construct syntctc tree for the progrm, whch s correct. If t ws not possle to fnsh wth the dervton tree, ut we hve tred ll the rules n ech poston nd there s no other opton vlle to try. In ths cse, the progrm wll e syntctclly ncorrect. Ths technque wll e llustrted wth the followng exmples: yntctc nlyss of the word
3
4
5 L next pl ACCPTD yntctc nlyss of the word 19 20
6
7 25 26 RJCTD 27 28
8 Anlyss of the word { - +}, > { - +}, > { - +}, > - - { - +}, >
9 { - +}, > - { - +}, > { - +}, > { - +}, >
10 { - +}, > { - +}, > { - +}, > { - +}, >
11 { - +}, > { - +}, > { - +}, > { - +}, >
12 Consder the nlyss of { - +}, > { - +}, > - - ACCPTD Conclusons If there re left-recursve rules, the nlyss of the word my provoke tht the lgorthm enters n nfnte loop. In the followng sldes, we shll study the possltes for vodng tht fct, nd we shll see other propertes of grmmrs whch re nterestng for uldng effcent top-down syntctc nlysers. Overvew Blnd serch, depth-frst serch nd wdth-frst serch. low cktrckng wth LL(1) grmmrs Procedures for modfyng grmmrs lmnton of left-recurson lmnton of lmd-rules Grech Norml Form Defnton Procedure for otnng the GNF of grmmr xmples LL(1) grmmrs Intl exmples Defnton of LL(1) grmmrs yntctc nlysers sed on LL(1) grmmrs 47 48
13 Propertes of grmmrs for top-down nlyss Propertes It s esy to uld LL(1) nlysers, n whch the nput s red from left to rght, nd the dervtons n the tree re lso mde from left to rght. The numer 1 mens tht t needs one look-hed symol from the nput strng. In order to uld n LL(1) nlyser, the grmmr hs to e expressed n LL(1) form. Possle steps to trnsform grmmr nto LL(1) form re: Removng ll the left-recursve rules. Removng nccessle symols. Removng rules tht generte the empty word: A λ xpressng the grmmr n Grech Norml Form. Left fctorston (whch s necessry condton for LL(1) grmmrs) { - +}, > + - Grech Norml Form Removng left-recursve rules Let us nlyse the followng exmple: { - + λ}, > λ λ - λ λ Grech Norml Form Removng left-recursve rules Grech Norml. Form Removng left-recursve rules: frst exmple It s dffcult to thnk of generl procedure from the prevous exmple. However, the technque cn e generlsed. G=<{,T,F}, {-,*,} { +T T T T*F F F }, > A Aα 1... Aα n β 1... β m A β 1 X... β m X X α 1 X... α n X λ G =<{,,T,T,F}, {-,*,} { T +T λ T FT F }, > 51 52
14 Grech Norml Form Lemm: removng left-recursve rules Grech Norml Form Removng lmd-rules very context-ndependent grmmr cn e trnsformed nto n equvlent grmmr wthout left-recursve rules. A left-recursve rule s rule of the followng form: A Ax,,A Σ N x (Σ T Σ N ) * The lemm s shown n constructve wy dong, for ech recursve rule, the followng tretment: Let < Σ T, Σ N,, P > e grmmr wth left-recursve rules: A Aα 1... Aα n β 1... β m Where {β } n =1 represent ll the non-left-recursve rules We cn susttute the prevous rules y the followng set of rules A β 1 X... β m X X α 1 X... α n X λ We cn modfy rule y susttutng non-termnl n ts rght-hnd sde y ll the rght-hnd sdes of the rules for tht non-termnl. The grmmr otned n ths wy genertes the sme lnguge s the orgnl one Grech Norml Form Grech Norml Form Removng lmd-rules Removng lmd-rules G =<{,,T,T,F}, {-,*,} { T +T λ T FT F }, > F ( cn e put n plce of F n) T FT G =<{,,T,T,F}, {-,*,} { T +T λ T T F }, > G =<{,,T,T,F}, {-,*,} { T +T λ T T F }, > T T (T s set n the plce of T ) T G =<{,,T,T,F}, {-,*,} { T +T λ T T F }, > 55 56
15 Grech Norml Form Removng lmd-rules Grech Norml Form Removng lmd-rules We cn delete rule for non-termnl symol, provded tht we lso dd new rules y susttutng ll ppernces of the non-termnl y ll the rght-hnd sdes of the rules elmnted. A cse wth specl nterest s the rules tht generte the empty word, λ A lmd-rule s rule of the followng form: A λ,,a Σ N It s used to remove non-termnl symol from word. G =<{,,T,T,F}, {-,*,} { T +T λ T T F }, > G =<{,,T,T,F}, {-,*,} { T T +T +T T T F }, > Grech Norml Form Removng lmd-rules Grech Norml Form Removng lmd-rules Let us test some dervtons: G =<{,,T,T,F}, {-,*,} { T T +T +T T T F }, > G =<{,,T,T,F}, {-,*,} { T T +T +T T T T *FT *F F }, > G=<{,T,F}, {-,*,} { +T T T T*F F F }, > T + + T F T F ++ + T G =<{,,T,T,F}, {-,*,} { T T +T +T T T T *FT *F F }, > F + T 59 60
16 Grech Norml Form Removng lmd-rules Grech Norml Form Removng lmd-rules Let us test some dervtons: Let us test some dervtons: G=<{,T,F}, {-,*,} { +T T T T*F F F }, > T T * F ** * F T T * F * F T G =<{,,T,T,F}, {-,*,} { T T +T +T T T T *FT *F F }, > G=<{,T,F}, {-,*,} { +T T T T*F F F }, > T * + F T F F *+ T * F + T G =<{,,T,T,F}, {-,*,} { T T +T +T T T T *FT *F F }, > F Overvew Blnd serch, depth-frst serch nd wdth-frst serch. low cktrckng wth LL(1) grmmrs Procedures for modfyng grmmrs lmnton of left-recurson lmnton of lmd-rules Grech Norml Form Defnton Procedure for otnng the GNF of grmmr xmples LL(1) grmmrs Intl exmples Defnton of LL(1) grmmrs yntctc nlysers sed on LL(1) grmmrs Informlly, Formlly, Grech Norml Form Defnton A context-ndependent grmmr s n Grech Norml Form f nd only f the rghthnd-sde of ll the rules strts wth termnl symol, followed, optonlly, y nontermnls. < Σ T, Σ N,, P >, context-ndependent, s n Grech Norml Form s (def) r P r=a x,, Σ T x Σ * N 63 64
17 Grech Norml Form Theorem very context-ndependent grmmr whch does not generte the empty word cn e expressed n Grech Norml form. Grech Norml Form Proof of the theorem It wll e constructve proof, showng how the grmmr cn e trnsformed. The trnsformton s performed n the followng wy: 1. If the lnguge contns the empty word, dd the followng rule ( s the xom) λ 2. Remove ll the left-recursve rules pplyng the lemm seen efore. 3. The followng prtl orderng wll e estlshed etween the non-termnl symols, deduced from the producton rules: A <A j ( α Σ T* A A j α P) ( β Σ T * A j A β P) If ths orderng produces loop,.e., f α,β Σ T* A A j α P A j A β P we cn choose ny of the two followng optons: A <A j A j <A Grech Norml. Form xmple of step 3 G=<{,T,F}, {-,*,} { +T T, T T*F F, F }, > The followng prtl orderng cn e deduced from the rules n the grmmr: +T does not provde ny orderng. From T we cn deduce <T From T T*F we do not get ny orderng. From T F we cn deduce T<F From F we cnnot deduce nythng. In concluson, <T<F Grech Norml Form Proof of the theorem 4. We cn clssfy the rules n the followng three groups: Type 1: Rules of the form A x,, Σ T, x Σ * Type 2: Rules of the form A Bx,, A,B Σ N, x Σ * A<B Type 3: Rules of the form A Bx,, A,B Σ N, x Σ * B<A 67 68
18 Grech Norml. Form xmple of step 4 G =<{,,T,T,F}, {-,*,} { T, +T λ, T FT,, F }, > Type 1 rules: +T T *FT F Type 2 rules: T T FT There re no type 3 rules. The lmd-rules wll e seen lter. Grech Norml Form Proof of the theorem 5. All the rules of type 3 wll e deleted. Type 3: Rules of the form A Bx,, A,B Σ N, x Σ * B<A To do ths, 1. We replce B wth ll the rght-hnd sdes for B. 2. Ths process s repeted for ll the type-3 rules. 3. If, durng ths process, there pper new left-recursve rules, we trnsform them usng the procedure seen efore. 4. If there pper nccessle symols, we elmnte them Grech Norml. Form xmple of step 5 Grech Norml. Form xmple of step 5 G =<{A,B,C}, {,} {A BC, B CA, C AB }, Type 3 rules: C AB We susttute A wth ts rght-hnd sdes (BC): C BCB Now, there s new type-3 rule: C BCB We susttute B wth ts left-hnd sdes (CA ): C CACB CB G =<{A,B,C}, {,} {A BC, B CA, C CACB CB }, G =<{A,B,C}, {,} {A BC, B CA, C BCB }, 71 72
19 Grech Norml Form Proof of the theorem 6. At ths pont, there should not e more type-3 rules. The next step wll e the removl of 2-type rules, strtng wth the non-termnls whch re t the end of the prtl orderng. Type 2: Rules of the followng form: A Bx,, A,B Σ N, x Σ * A<B To do ths, 1. B wll e replced y ll the rght-hnd sdes of the rules for B. 2. Ths s repeted untl we do not hve ny more type-2 or type-3 rules. 3. If there pper new left-recursve rules, they wll lso e removed. 4. Inccessle symols wll lso e removed. Grech Norml Form xmple of step 6 G =<{,,T,T,F}, {-,*,} { T, +T λ, T FT,, F }, > There re two type-2 rules, wth the orderng <T<F T T FT Frstly, we susttute F n T FT wth ts rght-hnd sdes (), nd otn: T T G =<{,,T,T,F}, {-,*,} { T, +T λ, T T,, F }, > Grech Norml. Form xmple of step 6 G =<{,,T,T,F}, {-,*,} { T, +T λ, T T,, F }, > Next, we susttute T n T wth ts rght-hnd sdes, (T ). We otn the rule T Grech Norml Form Proof of the theorem 7. Now, ll the rules elong to type 1: they ll hve the followng form: A x,, Σ T, x Σ * The only dfferent wth respect to Grech Norml Form my e due to rules hvng more thn one termnl symol n the rght-hnd sde. Ths cn e solved wth trvl susttuton, ddng new non-termnl symol, s n the followng exmple. A C We cn replce tht rule wth: A BC, B Where B s new non-termnl symol G =<{,,T,T,F}, {-,*,} { T, +T λ, T T,, F }, > 75 76
20 G =<{A,X}, {,} {A X X, X X λ}, Grech Norml. Form xmple of step 7 There re two rules n whch the termnl symol hs to e replced y the new non-termnl symol A : We dd the new rule A We susttute A X y A A X We susttute X X y X A X G =<{A,X,A }, {,} {A A X X, X A X λ, A }, 77 Grech Norml Form Proof of the theorem 8.The lst thng to do s the tretment of lmd-rules. In Grech Norml Form, these rules re fordden. The only excepton s when the lnguge contns the empty word, n whch there hs to e, necessrly, lmd rule for the xom of the grmmr. They should e removed usng the procedure prevously studed. NOT: For the purpose of uldng LL(1) complers, the grmmr needs not e exctly n Grech Norml form: ome of the lmd rules wll not e wrong for n LL(1) grmmr. Otherwse, they wll e removed usng the procedure lredy seen. When these rules re removed, sometmes t s dffcult to comply wth ll the condtons for LL(1) grmmrs. In ths cse, t my e necessry to lter the grmmr mnully to otn n equvlent one whch cn e restted s n LL(1) grmmr. 78 Grech Norml. Form xmple 1 1. As the lnguge does not contn the empty word, there s nothng to do. 2. Remove ll the left-recursve rules: G=<{,T,F}, {-,*,} { +T T T T*F F F }, > A Aα 1... Aα n β 1... β m A β 1 X... β m X X α 1 X... α n X λ G =<{,,T,T,F}, {-,*,} { T +T λ T FT F }, > Grech Norml. Form xmple 1 3. We estlsh the prtl orderng for the non-termnl symols. In generl, we cn estlsh the orderng usng the non-termnl symols n the orgnl grmmr, nd the ones dded n step 2 my e dded to the orderng f necessry. G=<{,T,F}, {-,*,} { +T T, T T*F F, F }, > The followng orderng wll e deduced from the prevous rules: From +T we do not deduce nythng From T we deduce <T From T T*F we deduce nothng From T F we deduce T<F From F we cn t deduce nythng. In concluson, <T<F 79 80
21 Grech Norml. Form xmple 1 4. The rules wll e clssfed n three groups. 5. The grmmr does not contn type-3 rules, so there s nothng to e done 6. Type-2 rules removl: Grech Norml. Form xmple 1 G =<{,,T,T,F}, {-,*,} { T, +T λ, T FT,, F }, > Type-1 rules +T T *FT F Type-2 rules T T FT No type-3 rules. Lmd rules wll e treted t the end. G =<{,,T,T,F}, {-,*,} { T, +T λ, T FT,, F }, > There re two type-2 rules, wth the orderng <T<F T T FT We frst solve F n T FT nd replce t y ts rght-hnd sdes (), nd otn T T G =<{,,T,T,F}, {-,*,} { T, +T λ, T T,, F }, > Grech Norml. Form xmple 1 G =<{,,T,T,F}, {-,*,} { T, +T λ, T T,, F }, > Grech Norml Form xmple 1 7. As there re no termnl symols ncorrectly set n the rght-hnd sdes of the rules, there s nothng to do t ths step. Next, we delete T n T nd replce t wth ts rght-hnd sdes (T ), to otn T G =<{,,T,T,F}, {-,*,} { T, +T λ, T T,, F }, > 83 84
22 Grech Norml Form xmple 1 Grech Norml Form xmple 1 8. In the cse tht we wnt to otn the grmmr n Grech Norml form, the lst step would e to remove ll the lmd-rules. RMMBR: ths step s not strctly necessry for LL(1) prsers G =<{,,T,T,F}, {-,*,} { T +T λ T T F }, > G =<{,,T,T,F}, {-,*,} { T T +T +T T T F }, > G =<{,,T,T,F}, {-,*,} { T T +T +T T T F }, > G =<{,,T,T,F}, {-,*,} { T T +T +T T T T *FT *F F }, > When there re no more lmd-rules, we hve the grmmr, fnlly, n GNF Overvew Blnd serch, depth-frst serch nd wdth-frst serch. low cktrckng wth LL(1) grmmrs Procedures for modfyng grmmrs lmnton of left-recurson lmnton of lmd-rules Grech Norml Form Defnton Procedure for otnng the GNF of grmmr xmples LL(1) grmmrs Intl exmples Defnton of LL(1) grmmrs yntctc nlysers sed on LL(1) grmmrs Adjustng grmmr n Grech Norml Form to LL(1) Chnges n step 8 ome lmd rules re not ncorrect n LL(1) grmmrs. Therefore, we re only gong to remove those tht re not rght. The followng procedure wll e followed: When non-termnl hs lmd rule, e.g. X λ The followng stuton my rse: tht the sme non-termnl hs other rules wth dfferent rght-hnd sde. Becuse we re n step 8, we know tht ll rules re now type-1 rules, strtng wth termnl symol. X α,, Σ T α Σ * 87 88
23 Adjustng grmmr n Grech Norml Form to LL(1) Chnges n step 8 Imgne syntctc dervton tree for word (the termnl symols re represented n red colour) Adjustng grmmr n Grech Norml Form to LL(1) Chnges n step 8 Imgne tht we re dong the top-down prsng of tht word, nd we re just efore the symol X XY 1...Y m t t j t l t k t t t s t n If X s the only non-termnl tht remns, there would e the followng two possltes: X λ X α X α t...t n Intutvely, the effcency of LL(1), whch s etter thn smple top-down prsng wth slow cktrckng, s due to the ndexton of the rght-hnd sdes, for ech non-termnl, usng the next termnl to e nlysed. Ths wll e possle only f ech non-termnl hs just one rght-hnd sde strtng wth ech termnl. If we do not hve lmd rules (X λ), the top-down nlyss cn e done completely wthout ny rnchng n the nlyss. t t j t l t k t t t s t n t t j t l t k t t t s t n Adjustng grmmr n Grech Norml Form to LL(1) Chnges n step 8 If we hd the followng rules for non-termnl X, X β 1 Adjustng grmmr n Grech Norml Form to LL(1) Chnges n step 8 X t -1 β -1 X α X t +1 β +1 X t k β k,,{,...,t -1,,t +1,...,t k } Σ T t p t q p,q {1,...,-1,+1,...k} {β 1,...,β -1,,β +1,...,β k } Σ N * There would e just one posslty to choose f the next symol n the nput strng were. Y 1...Y m α t...t n Lmd-rules wll e prolemtc whenever they produce severl possltes of choosng the next rule to pply
24 Adjustng grmmr n Grech Norml Form to LL(1) Chnges n step 8 Let us mgne tht we hve the followng three rules: X α, X λ y Y 1 γ 1 A termnl cn e derved drectly from X (X α), nd from Y 1, whch follows X (Y 1 γ 1 ) Borrdo de X Y 1 γ 1 Adjustng grmmr n Grech Norml Form to LL(1) Chnges n step 8 In order to dentfy these stutons, we need to know: Whch re the frst termnls derved y X (n our exmple, ) Whch s the frst termnl tht cn e derved y wht s fter X,.e. next(x) The followng fgures descre the two possle cses: XY 1...Y m λ Y 1...Y m Y 2...Y m γ 1 B σxy 1 B V τiwω W Y 1...Y m I ξx τ IW V ω t...t n t...t n t...t n σ X Y 1...Y m ξ X Y 1...Y m X λ X α λ λ XY 1...Y m Y 1...Y m t...t n t...t n t...t n α t...t n Adjustng grmmr n Grech Norml Form to LL(1) tep 8 for exmple 1 8. If we wnt to generte top-down syntctc nlyser wth the LL(1) technque, we hve to study, n step 8, whch lmd-rules produce mgutes. 8. (cont.) Adjustng grmmr n Grech Norml Form to LL(1) tep 8 for exmple 1 G =<{,,T,T,F}, {-,*,} { T +T λ T T F }, > Who cn follow? next( ) We study ll the rght-hnd sdes tht contn G =<{,,T,T,F}, {-,*,} { T +T λ T T F }, > Who cn follow? next( ) We study ll the rght-hnd sdes tht contn In the two rules, ppers s the lst symol n the rght-hnd sde. cn e followed y nythng tht follows the lefthnd sde of those rules: Let s strt wth the lmd-rule λ
25 8. (cont.) Adjustng grmmr n Grech Norml Form to LL(1) tep 8 for exmple 1 8. (cont.) Adjustng grmmr n Grech Norml Form to LL(1) tep 8 for exmple 1 G =<{,,T,T,F}, {-,*,} { T +T λ T T F }, > Therefore: next( ) s ncluded n next( ) ovous next() s ncluded n next( ). As s the xom, nd t does not pper n ny other rght-hnd sde. next() s the end-of-progrm symol, $. o next( ) s {$}. On the other hnd, frst( ) = {+} G =<{,,T,T,F}, {-,*,} { T +T λ T T F }, > Who cn follow T? next(t ) We study ll the rght-hnd sdes tht contn T We cn conclude tht the frst lmd rule s correct for LL(1), nd cn e left lke tht. Let us contnue wth the second lmd rule (cont.) Adjustng grmmr n Grech Norml Form to LL(1) tep 8 for exmple 1 8. (cont.) Adjustng grmmr n Grech Norml Form to LL(1) tep 8 for exmple 1 G =<{,,T,T,F}, {-,*,} { T +T λ T T F }, > Who cn follow T? next(t ) We study ll the rght-hnd sdes tht contn T There s one rule n whch T s followed y. In two other rules, t ppers s the lst symol of the rght-hnd sde. Therefore, next(t ) wll e: frst( ) next(t) next(t ) -- ovous G =<{,,T,T,F}, {-,*,} { T +T λ T T F }, > We cn focus now on next(t) Let us see ll the rules n whch T ppers n the rght-hnd sde
26 8. (cont.) Adjustng grmmr n Grech Norml Form to LL(1) tep 8 for exmple 1 8. (cont.) Adjustng grmmr n Grech Norml Form to LL(1) tep 8 for exmple 1 G =<{,,T,T,F}, {-,*,} { T +T λ T T F }, > We cn focus now on next(t) Let us see ll the rules n whch T ppers n the rght-hnd sde. It only ppers followed y. Therefore, next(t) = frst( ) In concluson, next(t ) wll e: frst( ) next(t) = frst( ) next(t ) -- ovous G =<{,,T,T,F}, {-,*,} { T +T λ T T F }, > Fnlly, we need to check whether the lmd rule produces ny mguty durng the nlyss. For nstnce, The frst termnl derved y T s *. The termnls n next(t ) re just +. Therefore, next(t ) = {+} Becuse the termnls re dfferent (* y +) we cn conclude tht the lmd rule s pproprte for n LL(1) grmmr Adjustng grmmr n Grech. Norml Form to LL(1) xmple 2 Otn, f possle, the LL(1) equvlent grmmr from the followng one: =<{A,B}, {,} {A B B A }, Adjustng grmmr n Grech. Norml Form to LL(1) xmple 2 1. The lnguge does not contn the empty word, so there s nothng to do. 2. There re no left-recursve rules, so there s gn nothng to do here. 3. We shll estlsh the prtl orderng etween the non-termnl symols. =<{A,B}, {,} {A B B A }, From the prevous rules, we cn deduce two dfferent prtl orderngs: From A B we cn deduce A<B From B A we cn deduce B<A In summry, there re two optons: Opton 1: B<A Opton 2: A<B We shll study the two possltes seprtely, to see how the choce tken ffects the result
27 Adjustng grmmr n Grech. Norml Form to LL(1) xmple 2, opton 1 B<A 4. The rules wll e clssfed n three groups Adjustng grmmr n Grech. Norml Form to LL(1) xmple 2, opton 1 B<A 5. The type-3 rule wll e elmnted y susttutng B Type 1 rules A B Type 2 rules B A Type 3 rules A B =<{A,B}, {,} {A B B A }, Type-3 rules: A B The B wll e replced y ts rght-hnd sdes (A nd ), nd we otn: A A =<{A,B}, {,} {A B B A }, =<{A,B}, {,} {A A B A }, Adjustng grmmr n Grech. Norml Form to LL(1) Adjustng grmmr n Grech. Norml Form to LL(1) xmple 2, opton 1 B<A In ll the steps, we need to check whether there s ny nccessle symol. xmple 2, opton 1 B<A We lso need to elmnte ll the left-recursve rules tht hve turned up: =<{A,B}, {,} {A A B A }, =<{A}, {,} {A A }, It cn e esly seen tht, n ths grmmr, B cnnot e generted from the xom. It s nccessle, so we cn elmnte t nd ll the rules where t s t the left-hnd sde: B A =<{A}, {,} {A A }, 107 The rule A A s left-recursve, so we pply the lemm whch sd: If we hve grmmr < Σ T, Σ N,, P >, the left-recursve rules A Aα 1... Aα n β 1... β m wll e susttuted y A β 1 X... β m X X α 1 X... α n X λ In our exmple, A X X X X λ =<{A,X}, {,} {A X X X X λ}, 108
28 Adjustng grmmr n Grech. Norml Form to LL(1) xmple 2, opton 1 B<A 6. There no type-2 rules to elmnte 7. We elmnte ll the termnl symols tht re not n the frst poston of the rules: =<{A,X}, {,} {A X X X X λ}, We defne new non-termnl Z to derve the (Z ) And we susttute the n ll the rght-hnd sdes y Z : (A ZX y X ZX) =<{A,X},{,} {A ZX X X ZX λ Z }, Adjustng grmmr n Grech Norml Form to LL(1) xmple 2, opton 1 B<A 8. tudy of the λ-rules =<{A,X},{,} {A ZX X X ZX λ Z }, There s just one lmd-rule, for X. Let us study the set next(x), to see whether t s dfferent from frst(x) (cont.) Adjustng grmmr n Grech Norml Form to LL(1) xmple 2, opton 1 B<A Adjustng grmmr n Grech. Norml Form to LL(1) 4. Let us see now xmple 2, opton 2 A<B =<{A,X},{,} {A ZX X X ZX λ Z }, Concernng next(x), t ppers n three rules. From tht, we cn conclude tht next(x) contns: next(a) next(x) - ovous Becuse A s the xom, nd t does not pper n ny rght-hnd sde, we cn conclude tht next(a) wll e the end-of-progrm symol {$}, nd hence next(x) wll lso e {$}. On the other hnd, frst(x) = {} Type-1 rules: A B Type-2 rules: A B Type-2 rules: B A =<{A,B}, {,} {A B B A }, Ths lmd-rule s not wrong for n LL(1) grmmr
29 Adjustng grmmr n Grech. Norml Form to LL(1) xmple 2, opton 2 A<B 5. We strt y elmntng the type-3 rules from the grmmr: =<{A,B}, {,} {A B B A }, Type-3 rules: B A We replce A wth ts rght-hnd sdes (B nd ) to get: B B =<{A,B}, {,} {A B B B }, Adjustng grmmr n Grech. Norml Form to LL(1) xmple 2, opton 2 A<B Now, we need to elmnte left-recursve rules. The rule B B s left-recursve, so we pply the lemm. In the exmple, we get: B X X X X λ =<{A,B}, {,} {A B B B }, =<{A,B,X}, {,} {A B B X X X X λ}, Adjustng grmmr n Grech. Norml Form to LL(1) 6. Remove type-2 rules: There s one type-2 rule: A B xmple 2, opton 2 A<B =<{A,B,X}, {,} {A B B X X X X λ}, We susttute B wth ll ts rght-hnd sdres (X y X) to get: =<{A,B,X}, {,} {A X X B X X X X λ}, Adjustng grmmr n Grech. Norml Form to LL(1) xmple 2, opton 2 A<B As efore, we need to check whether there s ny nccessle symol: =<{A,B,X}, {,} {A X X B X X X X λ}, Now, t s not possle to rrve to B from the xom, so we cn delete t nd ll the rules tht hve t n the left-hnd sde: B X X =<{A,X}, {,} {A X X X X λ},
30 Adjustng grmmr n Grech. Norml Form to LL(1) xmple 2, opton 2 A<B 7. Removl of ll the termnls tht re not n the frst poston. =<{A,X}, {,} {A X X X X λ}, Frst, we cn elmnte the symol : we defne new non-termnl B to derve t (B ), nd we put the non-termnl n the fght-hnd sdes (A BX y X BX) =<{A,B,X}, {,} {A BX X X BX λ B }, 7. (cont.) Adjustng grmmr n Grech. Norml Form to LL(1) xmple 2, opton 2 A<B =<{A,B,X}, {,} {A BX X X BX λ B }, We lso hve msplced termnl : we defne new non-termnl Z to derve t, (Z ), nd we susttute t n the prolemtc rght-hnd sdes (A BXZ XZ) =<{A,B,X,Z}, {,} {A BXZ XZ X BX λ B Z }, Adjustng grmmr n Grech Norml Form to LL(1) xmple 2, opton 2 A<B 8. tudy of the λ-rules. 8. (cont.) Adjustng grmmr n Grech Norml Form to LL(1) xmple 2, opton 2 A<B =<{A,B,X,Z}, {,} {A BXZ XZ X BX λ B Z }, We need to check whether next(x) nd frst(x) hve ny termnl symol n common. =<{A,B,X,Z}, {,} {A BXZ XZ X BX λ B Z }, Let us clculte next(x): X ppers followed y Z. X lso ppers t the end of rule. Therefore, next(x) wll contn: frst(z) = next(x) - ovous There s just one lmd-rule
31 8. (cont.) Adjustng grmmr n Grech Norml Form to LL(1) xmple 2, opton 2 A<B LL(1) lnguges re LL(1) Concept =<{A,B,X,Z}, {,} {A BXZ XZ X BX λ B Z }, But t s the cse tht: frst(x)s the symol next(x)=frst(z)= Let us clculte next(x): X ppers followed y Z. X lso ppers t the end of rule. Therefore, next(x) wll contn: frst(z) = next(x) ovous Those whose grmmrs pper n Grech Norml Form, nd there re not two rules for the sme non-termnl, strtng wth the sme termnl symol n ther rght-hnd sde. o we cn conclude tht ths lmd-rule produces mgutes durng the prsng LL(1) Convertng from GNF to LL(1) A grmmr n Grech Norml Form my not e LL(1) For nstnce, =<{U,V,W,X,Y,Z,T}, {,,c,d,e} { U V W V X cy W dz et }, U> Two of the rght-hnd sdes for U strt wth the sme termnl symol,. LL(1) Convertng from GNF to LL(1) ometmes, ths cm e solved wth common fctor. teps Otn the longest common prefx of the two rght-hnd sdes (n the exmple the symol ). Leve sngle rght-hnd sde whch strts wth tht common prefx, nd whch ends wth new non-termnl, e.g. K =<{U,V,W,X,Y,Z,T}, {,,c,d,e} { U K V X cy W dz et }, U>
32 LL(1) Convertng from GNF to LL(1) The new non-termnl wll generte the remnng of the rght-hnd sdes, K V W. LL(1) Convertng from GNF to LL(1) We hve to tke cre to leve the rules gn n GNF... We cn derve the ntl non-termnls n the rules for K, so they strt wth on-termnl. In ths cse, we cn pply the rules for V nd W: =<{U,V,W,X,Y,Z,T}, {,,c,d,e} { U K K V W V X cy W dz et }, U> =<{U,V,W,X,Y,Z,T}, {,,c,d,e} { U K K X cy dz et V X cy W dz et }, U> LL(1) Convertng from GNF to LL(1)...nd we hve to remove the nccessle symols (V y W) Formlston of LL(1) grmmrs Concept In the remnng prt of ths lesson, we re gong to descre formlly LL(1) nlysers, whch we hve lredy ntroduced nformlly wth exmples. =<{U,V,W,X,Y,Z,T}, {,,c,d,e} { U K K X cy dz et }, U>
33 Formlston of LL(1) grmmrs xmple Consder the followng grmmr, nd the frst nd next sets for ech non-termnl: G=< {,,T,T,F}, {+,*,(,),d} { T +T λ T FT T *FT λ F () d }, > frst()=frst(t)=frst(f)={(,d} frst( )={+,λ} frst(t )={*,λ} next()=next( )={),$} next(t)=next(t )={+,),$} next(f)={+,*,),$} Constructng LL(1) nlysers Algorthm The followng lgorthm clcultes the nlyss tle T M ΣN ΣT +1 In ths mtrx, there wll e row for ech non-termnl, nd column for ech termnl, ncludng the end-of-progrm symol $. : 1. A α P repet: 1. frst(α) Σ T A α T[A,]. 2. If λ frst(α) then, next(a) A α T[A,] (note tht cn lso e $) Constructng LL(1) nlysers xmples In the grmmr for the prevous exmple Gven the followng grmmr, Constructng LL(1) nlysers xmples Σ N T T F d T FT F d + +T T λ Σ T {$} * ( T FT T *FT F () ) λ T λ $ λ T λ G=< {P,P,}, {,t,,e,} { P tpp P ep λ P>
34 We cn otn the next tle: Constructng LL(1) nlysers xmples LL(1), frst nd next sets Defnton We cn defne LL(1) grmmrs s those tht comply wth the followng condton: Σ N e Σ T {$} t $ The nlyss tle constructed wth the prevous procedure s determnstc,.e., ll the rows contn t most one rule. P P P tpp P P λ P ep P λ xmples The grmmr n the frst exmple s LL(1) The grmmr n the second exmple s not LL(1) electve top-down nlysers Concept LL(1) nlysers re lso clled wth no cktrckng, ecuse they re determnstc nd t wll never e necessry to cktrck durng the nlyss of progrm. They re lso clled recursve-descent prsers, ecuse of the knd of nlyss progrms tht re produced from LL(1) grmmrs. The reson of the effcency of these prsers s ecuse the rght-hnd sdes of the rules for ech non-termnl symol cn e consdered to e ndexed y the next termnl. electve top-down nlysers Automtclly uldng prser for n LL(1) grmmr Accordng to the procedure descred, n n LL(1) grmmr we re gong to hve two knds of rules: Rules for non-termnls tht hve λ-rule: U xx 1 X 2...X n yy 1 Y 2...Y m... zz 1...Z p λ Rules for non-termnls tht do not hve λ-rule: U xx 1 X 2...X n yy 1 Y 2...Y m... zz 1...Z p
35 electve top-down nlysers Automtclly uldng prser for n LL(1) grmmr: λ rules The next C functon wll e generted: electve top-down nlysers Automtclly uldng prser for n LL(1) grmmr: rules wthout λ The next C functon wll e generted: nt U(chr * strng, nt ) { f ( < 0) return ; /* ths propgtes errors */ swtch (strng[]) { cse x; ++; =X1(strng, ); =X2(strng, ); =Xn(strng, ); rek; cse y: ++; =Y1(strng, ); =Y2(strng, ); =Ym(strng, ); rek; cse z: ++; =Z1(strng, ); =Z2(strng, ); =Zp(strng, ); rek; } return ; } nt U(chr * strng, nt ) { f ( < 0) return ; /* Ths propgtes errors */ swtch (strng[]) { cse x; ++; =X1(strng, ); =X2(strng, ); =Xn(strng, ); rek; cse y: ++; =Y1(strng, ); =Y2(strng, ); =Ym(strng, ); rek; cse z: ++; =Z1(strng, ); =Z2(strng, ); =Zp(strng, ); rek; /* nd-of-strng goes to the defult cse */ defult: return n; /* The error wll e dfferent for ech rule */ } return ; } electve top-down nlysers Complete exmple Let us strt wth the followng context-ndependent grmmr electve top-down nlysers Complete exmple The followng s the grmmr n Grech Norml Form G 3 =<{,T,F},{,+,-,*,/,(,)} { T+ T- T T F*T F/T F F () }, > G 3 =<{,T,M,,P,D,C}, {,+,-,*,/,(,)} { PTM (CPTM DTM (CDTM M (CM PT (CPT DT (CDT (C PT (CPT DT (CDT (C T PT (CPT DT (CDT (C M + - P * D / C )}, >
36 electve top-down nlysers Complete exmple The followng s possle LL(1) grmmr, otned from the GNF grmmr y tkng common fctor n the rght-hnd sdes of the rules. G 3 =<{,T,M,,P,D,C}, {,+,-,*,/,(,)} { V (CV V *TX /TX + - λ X + - λ T U (CU U *T /T λ C )}, > electve top-down nlysers Complete exmple The followng would e the LL(1) nlyser (contnued) nt (chr * strng, nt ) { f ( < 0) return ; /* Ths propgtes prevous errors */ swtch (strng[]) { cse : ++; =V(strng, ); rek; cse ( : ++; =(strng, ); =C(strng, ); =V(strng, ); rek; defult: return 1;/*no λ*/ } return ; } nt V(chr * strng, nt ) { f ( < 0) return ; /* Ths propgtes prevous errors */ swtch (strng[]) { cse * : cse / : ++; =T(strng, ); =X(strng, ); rek; cse + : cse - : ++; =(strng, ); rek; /* λ */ } return ; } electve top-down nlysers Complete exmple The followng would e the LL(1) nlyser (contnued) electve top-down nlysers Complete exmple The followng would e the LL(1) nlyser (contnued) nt X(chr * strng, nt ) { f ( < 0) return ; /* Ths propgtes prevous errors */ swtch (strng[]) { cse + : cse - : ++; =(strng, ); rek; /* λ */ } return ; } nt T(chr * strng, nt ) { f ( < 0) return ; /* Ths propgtes prevous errors */ swtch (strng[]) { cse : ++; =U(strng, ); rek; cse ( : ++; =(strng, ); =C(strng, ); =U(strng, ); rek; defult: return 2;/*no λ*/ } return ; } nt U(chr * strng, nt ) { f ( < 0) return ; /* Ths propgtes prevous errors */ swtch (strng[]) { cse * : cse / : ++; =T(strng, ); rek; /* λ */ } return ; } nt C(chr * strng, nt ) { f ( < 0) return ; /* Propgte prevous errors */ swtch (strng[]) { cse ) : ++; rek; defult: return 4;/*no λ*/ } return ; }
37 electve top-down nlysers electve top-down nlysers Complete exmple Complete exmple A strng x would e nlysed wth the followng cll: The followng strng wll not e recognsed xom( x, 0); If the vlue returned equls the length of the strng, t ws correct. If t s negtve numer, t ws ncorrect. The followng executon exmple llustrtes the LL(1) nlyss: ( + *, 0) 0[1]: ( I + I * I, 0) 1[1]: V( I + I * I, 1) 2[1]: ( I + I * I, 2) 3[1]: V( I + I * I, 3) 4[1]: T( I + I * I, 4) 5[1]: U( I + I * I, 5) 5[1]: returned 5 4[1]: returned 5 4[1]: X( I + I * I, 5) 4[1]: returned 5 3[1]: returned 5 2[1]: returned 5 1[1]: returned 5 0[1]: returned ( + *, 0) 0[1]: ( I + I *, 0) 1[1]: V( I + I *, 1) 2[1]: ( I + I *, 2) 3[1]: V( I + I *, 3) 4[1]: T( I + I *, 4) 4[1]: returned -2 4[1]: X( I + I *, -2) 4[1]: returned -2 3[1]: returned -2 2[1]: returned -2 1[1]: returned -2 0[1]: returned yntctc nlyss Blogrphy [Alf] Teorí de Autómts y lengujes formles M. Alfonsec y otros [Hop] Introduccón l teorí de utómts, lengujes y computcón Hopcroft, J.; Motwn, R.; Ullmn, J. [Aho] Compldores. Prncpos, técncs y herrments A. V. Aho; R. efth; J. D. Ullmn 147
Rank One Update And the Google Matrix by Al Bernstein Signal Science, LLC
Introducton Rnk One Updte And the Google Mtrx y Al Bernsten Sgnl Scence, LLC www.sgnlscence.net here re two dfferent wys to perform mtrx multplctons. he frst uses dot product formulton nd the second uses
More informationPreviously on GLT. Basic technologies. Lexical analysis. Basic technologies ASF+SDF. Concepts of programming languages
Prevously on GLT Generc Lnguge Technology: Bsc technologes Pro.dr. Mrk vn den Brnd ASF+SDF syntx descrptons semntc descrptons: type checkng nlyss trnsormtons t so to s Concepts o progrmmng lnguges syntctc
More informationFirst Midterm Examination
24-25 Fll Semester First Midterm Exmintion ) Give the stte digrm of DFA tht recognizes the lnguge A over lphet Σ = {, } where A = {w w contins or } 2) The following DFA recognizes the lnguge B over lphet
More informationChapter Newton-Raphson Method of Solving a Nonlinear Equation
Chpter.4 Newton-Rphson Method of Solvng Nonlner Equton After redng ths chpter, you should be ble to:. derve the Newton-Rphson method formul,. develop the lgorthm of the Newton-Rphson method,. use the Newton-Rphson
More informationMinimal DFA. minimal DFA for L starting from any other
Miniml DFA Among the mny DFAs ccepting the sme regulr lnguge L, there is exctly one (up to renming of sttes) which hs the smllest possile numer of sttes. Moreover, it is possile to otin tht miniml DFA
More informationConvert the NFA into DFA
Convert the NF into F For ech NF we cn find F ccepting the sme lnguge. The numer of sttes of the F could e exponentil in the numer of sttes of the NF, ut in prctice this worst cse occurs rrely. lgorithm:
More informationParse trees, ambiguity, and Chomsky normal form
Prse trees, miguity, nd Chomsky norml form In this lecture we will discuss few importnt notions connected with contextfree grmmrs, including prse trees, miguity, nd specil form for context-free grmmrs
More informationUNIVERSITY OF IOANNINA DEPARTMENT OF ECONOMICS. M.Sc. in Economics MICROECONOMIC THEORY I. Problem Set II
Mcroeconomc Theory I UNIVERSITY OF IOANNINA DEPARTMENT OF ECONOMICS MSc n Economcs MICROECONOMIC THEORY I Techng: A Lptns (Note: The number of ndctes exercse s dffculty level) ()True or flse? If V( y )
More informationZbus 1.0 Introduction The Zbus is the inverse of the Ybus, i.e., (1) Since we know that
us. Introducton he us s the nverse of the us,.e., () Snce we now tht nd therefore then I V () V I () V I (4) So us reltes the nodl current njectons to the nodl voltges, s seen n (4). In developng the power
More information1.4 Nonregular Languages
74 1.4 Nonregulr Lnguges The number of forml lnguges over ny lphbet (= decision/recognition problems) is uncountble On the other hnd, the number of regulr expressions (= strings) is countble Hence, ll
More information5. (±±) Λ = fw j w is string of even lengthg [ 00 = f11,00g 7. (11 [ 00)± Λ = fw j w egins with either 11 or 00g 8. (0 [ ffl)1 Λ = 01 Λ [ 1 Λ 9.
Regulr Expressions, Pumping Lemm, Right Liner Grmmrs Ling 106 Mrch 25, 2002 1 Regulr Expressions A regulr expression descries or genertes lnguge: it is kind of shorthnd for listing the memers of lnguge.
More informationApplied Statistics Qualifier Examination
Appled Sttstcs Qulfer Exmnton Qul_june_8 Fll 8 Instructons: () The exmnton contns 4 Questons. You re to nswer 3 out of 4 of them. () You my use ny books nd clss notes tht you mght fnd helpful n solvng
More informationCS 275 Automata and Formal Language Theory
CS 275 utomt nd Forml Lnguge Theory Course Notes Prt II: The Recognition Prolem (II) Chpter II.5.: Properties of Context Free Grmmrs (14) nton Setzer (Bsed on ook drft y J. V. Tucker nd K. Stephenson)
More informationINTRODUCTION TO COMPLEX NUMBERS
INTRODUCTION TO COMPLEX NUMBERS The numers -4, -3, -, -1, 0, 1,, 3, 4 represent the negtve nd postve rel numers termed ntegers. As one frst lerns n mddle school they cn e thought of s unt dstnce spced
More informationThe Number of Rows which Equal Certain Row
Interntonl Journl of Algebr, Vol 5, 011, no 30, 1481-1488 he Number of Rows whch Equl Certn Row Ahmd Hbl Deprtment of mthemtcs Fcult of Scences Dmscus unverst Dmscus, Sr hblhmd1@gmlcom Abstrct Let be X
More informationClosure Properties of Regular Languages
Closure Properties of Regulr Lnguges Regulr lnguges re closed under mny set opertions. Let L 1 nd L 2 e regulr lnguges. (1) L 1 L 2 (the union) is regulr. (2) L 1 L 2 (the conctention) is regulr. (3) L
More informationCompilers. Spring term. Alfonso Ortega: Enrique Alfonseca: Chapter 4: Syntactic analysis
Complers Sprng term Alfonso Ortega: alfonso.ortega@uam.es nrque Alfonseca: enrque.alfonseca@uam.es Chapter : Syntactc analyss. Introducton. Bottom-up Analyss Syntax Analyser Concepts It analyses the context-ndependent
More informationPartially Observable Systems. 1 Partially Observable Markov Decision Process (POMDP) Formalism
CS294-40 Lernng for Rootcs nd Control Lecture 10-9/30/2008 Lecturer: Peter Aeel Prtlly Oservle Systems Scre: Dvd Nchum Lecture outlne POMDP formlsm Pont-sed vlue terton Glol methods: polytree, enumerton,
More informationIntroduction to Numerical Integration Part II
Introducton to umercl Integrton Prt II CS 75/Mth 75 Brn T. Smth, UM, CS Dept. Sprng, 998 4/9/998 qud_ Intro to Gussn Qudrture s eore, the generl tretment chnges the ntegrton prolem to ndng the ntegrl w
More informationRegular expressions, Finite Automata, transition graphs are all the same!!
CSI 3104 /Winter 2011: Introduction to Forml Lnguges Chpter 7: Kleene s Theorem Chpter 7: Kleene s Theorem Regulr expressions, Finite Automt, trnsition grphs re ll the sme!! Dr. Neji Zgui CSI3104-W11 1
More informationRegular Language. Nonregular Languages The Pumping Lemma. The pumping lemma. Regular Language. The pumping lemma. Infinitely long words 3/17/15
Regulr Lnguge Nonregulr Lnguges The Pumping Lemm Models of Comput=on Chpter 10 Recll, tht ny lnguge tht cn e descried y regulr expression is clled regulr lnguge In this lecture we will prove tht not ll
More informationCS 330 Formal Methods and Models Dana Richards, George Mason University, Spring 2016 Quiz Solutions
CS 330 Forml Methods nd Models Dn Richrds, George Mson University, Spring 2016 Quiz Solutions Quiz 1, Propositionl Logic Dte: Ferury 9 1. (4pts) ((p q) (q r)) (p r), prove tutology using truth tles. p
More informationGAUSS ELIMINATION. Consider the following system of algebraic linear equations
Numercl Anlyss for Engneers Germn Jordnn Unversty GAUSS ELIMINATION Consder the followng system of lgebrc lner equtons To solve the bove system usng clsscl methods, equton () s subtrcted from equton ()
More informationGrammar. Languages. Content 5/10/16. Automata and Languages. Regular Languages. Regular Languages
5//6 Grmmr Automt nd Lnguges Regulr Grmmr Context-free Grmmr Context-sensitive Grmmr Prof. Mohmed Hmd Softwre Engineering L. The University of Aizu Jpn Regulr Lnguges Context Free Lnguges Context Sensitive
More informationCS 311 Homework 3 due 16:30, Thursday, 14 th October 2010
CS 311 Homework 3 due 16:30, Thursdy, 14 th Octoer 2010 Homework must e sumitted on pper, in clss. Question 1. [15 pts.; 5 pts. ech] Drw stte digrms for NFAs recognizing the following lnguges:. L = {w
More information4. Eccentric axial loading, cross-section core
. Eccentrc xl lodng, cross-secton core Introducton We re strtng to consder more generl cse when the xl force nd bxl bendng ct smultneousl n the cross-secton of the br. B vrtue of Snt-Vennt s prncple we
More informationHomework Solution - Set 5 Due: Friday 10/03/08
CE 96 Introduction to the Theory of Computtion ll 2008 Homework olution - et 5 Due: ridy 10/0/08 1. Textook, Pge 86, Exercise 1.21. () 1 2 Add new strt stte nd finl stte. Mke originl finl stte non-finl.
More informationChapter Five: Nondeterministic Finite Automata. Formal Language, chapter 5, slide 1
Chpter Five: Nondeterministic Finite Automt Forml Lnguge, chpter 5, slide 1 1 A DFA hs exctly one trnsition from every stte on every symol in the lphet. By relxing this requirement we get relted ut more
More informationTwo Coefficients of the Dyson Product
Two Coeffcents of the Dyson Product rxv:07.460v mth.co 7 Nov 007 Lun Lv, Guoce Xn, nd Yue Zhou 3,,3 Center for Combntorcs, LPMC TJKLC Nnk Unversty, Tnjn 30007, P.R. Chn lvlun@cfc.nnk.edu.cn gn@nnk.edu.cn
More informationCHAPTER 1 Regular Languages. Contents
Finite Automt (FA or DFA) CHAPTE 1 egulr Lnguges Contents definitions, exmples, designing, regulr opertions Non-deterministic Finite Automt (NFA) definitions, euivlence of NFAs nd DFAs, closure under regulr
More informationPrinciple Component Analysis
Prncple Component Anlyss Jng Go SUNY Bufflo Why Dmensonlty Reducton? We hve too mny dmensons o reson bout or obtn nsghts from o vsulze oo much nose n the dt Need to reduce them to smller set of fctors
More informationProof that if Voting is Perfect in One Dimension, then the First. Eigenvector Extracted from the Double-Centered Transformed
Proof tht f Votng s Perfect n One Dmenson, then the Frst Egenvector Extrcted from the Doule-Centered Trnsformed Agreement Score Mtrx hs the Sme Rn Orderng s the True Dt Keth T Poole Unversty of Houston
More information1 Nondeterministic Finite Automata
1 Nondeterministic Finite Automt Suppose in life, whenever you hd choice, you could try oth possiilities nd live your life. At the end, you would go ck nd choose the one tht worked out the est. Then you
More informationChapter Newton-Raphson Method of Solving a Nonlinear Equation
Chpter 0.04 Newton-Rphson Method o Solvng Nonlner Equton Ater redng ths chpter, you should be ble to:. derve the Newton-Rphson method ormul,. develop the lgorthm o the Newton-Rphson method,. use the Newton-Rphson
More informationLecture 2e Orthogonal Complement (pages )
Lecture 2e Orthogonl Complement (pges -) We hve now seen tht n orthonorml sis is nice wy to descrie suspce, ut knowing tht we wnt n orthonorml sis doesn t mke one fll into our lp. In theory, the process
More informationLecture 08: Feb. 08, 2019
4CS4-6:Theory of Computtion(Closure on Reg. Lngs., regex to NDFA, DFA to regex) Prof. K.R. Chowdhry Lecture 08: Fe. 08, 2019 : Professor of CS Disclimer: These notes hve not een sujected to the usul scrutiny
More informationFirst Midterm Examination
Çnky University Deprtment of Computer Engineering 203-204 Fll Semester First Midterm Exmintion ) Design DFA for ll strings over the lphet Σ = {,, c} in which there is no, no nd no cc. 2) Wht lnguge does
More informationDCDM BUSINESS SCHOOL NUMERICAL METHODS (COS 233-8) Solutions to Assignment 3. x f(x)
DCDM BUSINESS SCHOOL NUMEICAL METHODS (COS -8) Solutons to Assgnment Queston Consder the followng dt: 5 f() 8 7 5 () Set up dfference tble through fourth dfferences. (b) Wht s the mnmum degree tht n nterpoltng
More informationRemember: Project Proposals are due April 11.
Bonformtcs ecture Notes Announcements Remember: Project Proposls re due Aprl. Clss 22 Aprl 4, 2002 A. Hdden Mrov Models. Defntons Emple - Consder the emple we tled bout n clss lst tme wth the cons. However,
More informationDesigning finite automata II
Designing finite utomt II Prolem: Design DFA A such tht L(A) consists of ll strings of nd which re of length 3n, for n = 0, 1, 2, (1) Determine wht to rememer out the input string Assign stte to ech of
More informationOverview HC9. Parsing: Top-Down & LL(1) Context-Free Grammars (1) Introduction. CFGs (3) Context-Free Grammars (2) Vertalerbouw HC 9: Ch.
Overview H9 Vertlerouw H 9: Prsing: op-down & LL(1) do 3 mei 2001 56 heo Ruys h. 8 - Prsing 8.1 ontext-free Grmmrs 8.2 op-down Prsing 8.3 LL(1) Grmmrs See lso [ho, Sethi & Ullmn 1986] for more thorough
More information1B40 Practical Skills
B40 Prcticl Skills Comining uncertinties from severl quntities error propgtion We usully encounter situtions where the result of n experiment is given in terms of two (or more) quntities. We then need
More information2.4 Linear Inequalities and Interval Notation
.4 Liner Inequlities nd Intervl Nottion We wnt to solve equtions tht hve n inequlity symol insted of n equl sign. There re four inequlity symols tht we will look t: Less thn , Less thn or
More informationI. Theory of Automata II. Theory of Formal Languages III. Theory of Turing Machines
CI 3104 /Winter 2011: Introduction to Forml Lnguges Chpter 16: Non-Context-Free Lnguges Chpter 16: Non-Context-Free Lnguges I. Theory of utomt II. Theory of Forml Lnguges III. Theory of Turing Mchines
More informationp-adic Egyptian Fractions
p-adic Egyptin Frctions Contents 1 Introduction 1 2 Trditionl Egyptin Frctions nd Greedy Algorithm 2 3 Set-up 3 4 p-greedy Algorithm 5 5 p-egyptin Trditionl 10 6 Conclusion 1 Introduction An Egyptin frction
More information1 From NFA to regular expression
Note 1: How to convert DFA/NFA to regulr expression Version: 1.0 S/EE 374, Fll 2017 Septemer 11, 2017 In this note, we show tht ny DFA cn e converted into regulr expression. Our construction would work
More informationHarvard University Computer Science 121 Midterm October 23, 2012
Hrvrd University Computer Science 121 Midterm Octoer 23, 2012 This is closed-ook exmintion. You my use ny result from lecture, Sipser, prolem sets, or section, s long s you quote it clerly. The lphet is
More informationI1 = I2 I1 = I2 + I3 I1 + I2 = I3 + I4 I 3
2 The Prllel Circuit Electric Circuits: Figure 2- elow show ttery nd multiple resistors rrnged in prllel. Ech resistor receives portion of the current from the ttery sed on its resistnce. The split is
More informationCSCI 340: Computational Models. Kleene s Theorem. Department of Computer Science
CSCI 340: Computtionl Models Kleene s Theorem Chpter 7 Deprtment of Computer Science Unifiction In 1954, Kleene presented (nd proved) theorem which (in our version) sttes tht if lnguge cn e defined y ny
More informationAssignment 1 Automata, Languages, and Computability. 1 Finite State Automata and Regular Languages
Deprtment of Computer Science, Austrlin Ntionl University COMP2600 Forml Methods for Softwre Engineering Semester 2, 206 Assignment Automt, Lnguges, nd Computility Smple Solutions Finite Stte Automt nd
More informationLecture 4: Piecewise Cubic Interpolation
Lecture notes on Vrtonl nd Approxmte Methods n Appled Mthemtcs - A Perce UBC Lecture 4: Pecewse Cubc Interpolton Compled 6 August 7 In ths lecture we consder pecewse cubc nterpolton n whch cubc polynoml
More informationLecture 3: Equivalence Relations
Mthcmp Crsh Course Instructor: Pdric Brtlett Lecture 3: Equivlence Reltions Week 1 Mthcmp 2014 In our lst three tlks of this clss, we shift the focus of our tlks from proof techniques to proof concepts
More informationInternational Journal of Pure and Applied Sciences and Technology
Int. J. Pure Appl. Sc. Technol., () (), pp. 44-49 Interntonl Journl of Pure nd Appled Scences nd Technolog ISSN 9-67 Avlle onlne t www.jopst.n Reserch Pper Numercl Soluton for Non-Lner Fredholm Integrl
More informationCS 330 Formal Methods and Models
CS 330 Forml Methods nd Models Dn Richrds, George Mson University, Spring 2017 Quiz Solutions Quiz 1, Propositionl Logic Dte: Ferury 2 1. Prove ((( p q) q) p) is tutology () (3pts) y truth tle. p q p q
More informationFarey Fractions. Rickard Fernström. U.U.D.M. Project Report 2017:24. Department of Mathematics Uppsala University
U.U.D.M. Project Report 07:4 Frey Frctions Rickrd Fernström Exmensrete i mtemtik, 5 hp Hledre: Andres Strömergsson Exmintor: Jörgen Östensson Juni 07 Deprtment of Mthemtics Uppsl University Frey Frctions
More informationTHE EXISTENCE-UNIQUENESS THEOREM FOR FIRST-ORDER DIFFERENTIAL EQUATIONS.
THE EXISTENCE-UNIQUENESS THEOREM FOR FIRST-ORDER DIFFERENTIAL EQUATIONS RADON ROSBOROUGH https://intuitiveexplntionscom/picrd-lindelof-theorem/ This document is proof of the existence-uniqueness theorem
More informationCS 314 Principles of Programming Languages
C 314 Principles of Progrmming Lnguges Lecture 6: LL(1) Prsing Zheng (Eddy) Zhng Rutgers University Ferury 5, 2018 Clss Informtion Homework 2 due tomorrow. Homework 3 will e posted erly next week. 2 Top
More informationHW3, Math 307. CSUF. Spring 2007.
HW, Mth 7. CSUF. Spring 7. Nsser M. Abbsi Spring 7 Compiled on November 5, 8 t 8:8m public Contents Section.6, problem Section.6, problem Section.6, problem 5 Section.6, problem 7 6 5 Section.6, problem
More information1.3 Regular Expressions
56 1.3 Regulr xpressions These hve n importnt role in describing ptterns in serching for strings in mny pplictions (e.g. wk, grep, Perl,...) All regulr expressions of lphbet re 1.Ønd re regulr expressions,
More informationAutomata and Languages
Automt nd Lnguges Prof. Mohmed Hmd Softwre Engineering Lb. The University of Aizu Jpn Grmmr Regulr Grmmr Context-free Grmmr Context-sensitive Grmmr Regulr Lnguges Context Free Lnguges Context Sensitive
More informationDennis Bricker, 2001 Dept of Industrial Engineering The University of Iowa. MDP: Taxi page 1
Denns Brcker, 2001 Dept of Industrl Engneerng The Unversty of Iow MDP: Tx pge 1 A tx serves three djcent towns: A, B, nd C. Ech tme the tx dschrges pssenger, the drver must choose from three possble ctons:
More informationSUMMER KNOWHOW STUDY AND LEARNING CENTRE
SUMMER KNOWHOW STUDY AND LEARNING CENTRE Indices & Logrithms 2 Contents Indices.2 Frctionl Indices.4 Logrithms 6 Exponentil equtions. Simplifying Surds 13 Opertions on Surds..16 Scientific Nottion..18
More informationFor convenience, we rewrite m2 s m2 = m m m ; where m is repeted m times. Since xyz = m m m nd jxyj»m, we hve tht the string y is substring of the fir
CSCI 2400 Models of Computtion, Section 3 Solutions to Homework 4 Problem 1. ll the solutions below refer to the Pumping Lemm of Theorem 4.8, pge 119. () L = f n b l k : k n + lg Let's ssume for contrdiction
More informationCMSC 330: Organization of Programming Languages
CMSC 330: Orgniztion of Progrmming Lnguges Finite Automt 2 CMSC 330 1 Types of Finite Automt Deterministic Finite Automt (DFA) Exctly one sequence of steps for ech string All exmples so fr Nondeterministic
More informationIntermediate Math Circles Wednesday, November 14, 2018 Finite Automata II. Nickolas Rollick a b b. a b 4
Intermedite Mth Circles Wednesdy, Novemer 14, 2018 Finite Automt II Nickols Rollick nrollick@uwterloo.c Regulr Lnguges Lst time, we were introduced to the ide of DFA (deterministic finite utomton), one
More informationChapter 5 Supplemental Text Material R S T. ij i j ij ijk
Chpter 5 Supplementl Text Mterl 5-. Expected Men Squres n the Two-fctor Fctorl Consder the two-fctor fxed effects model y = µ + τ + β + ( τβ) + ε k R S T =,,, =,,, k =,,, n gven s Equton (5-) n the textook.
More informationName Ima Sample ASU ID
Nme Im Smple ASU ID 2468024680 CSE 355 Test 1, Fll 2016 30 Septemer 2016, 8:35-9:25.m., LSA 191 Regrding of Midterms If you elieve tht your grde hs not een dded up correctly, return the entire pper to
More informationLecture 1. Functional series. Pointwise and uniform convergence.
1 Introduction. Lecture 1. Functionl series. Pointwise nd uniform convergence. In this course we study mongst other things Fourier series. The Fourier series for periodic function f(x) with period 2π is
More informationImproper Integrals. The First Fundamental Theorem of Calculus, as we ve discussed in class, goes as follows:
Improper Integrls The First Fundmentl Theorem of Clculus, s we ve discussed in clss, goes s follows: If f is continuous on the intervl [, ] nd F is function for which F t = ft, then ftdt = F F. An integrl
More information7.2 Volume. A cross section is the shape we get when cutting straight through an object.
7. Volume Let s revew the volume of smple sold, cylnder frst. Cylnder s volume=se re heght. As llustrted n Fgure (). Fgure ( nd (c) re specl cylnders. Fgure () s rght crculr cylnder. Fgure (c) s ox. A
More informationTypes of Finite Automata. CMSC 330: Organization of Programming Languages. Comparing DFAs and NFAs. NFA for (a b)*abb.
CMSC 330: Orgniztion of Progrmming Lnguges Finite Automt 2 Types of Finite Automt Deterministic Finite Automt () Exctly one sequence of steps for ech string All exmples so fr Nondeterministic Finite Automt
More informationTypes of Finite Automata. CMSC 330: Organization of Programming Languages. Comparing DFAs and NFAs. Comparing DFAs and NFAs (cont.) Finite Automata 2
CMSC 330: Orgniztion of Progrmming Lnguges Finite Automt 2 Types of Finite Automt Deterministic Finite Automt () Exctly one sequence of steps for ech string All exmples so fr Nondeterministic Finite Automt
More information8. INVERSE Z-TRANSFORM
8. INVERSE Z-TRANSFORM The proce by whch Z-trnform of tme ere, nmely X(), returned to the tme domn clled the nvere Z-trnform. The nvere Z-trnform defned by: Computer tudy Z X M-fle trn.m ued to fnd nvere
More informationFormal Languages Simplifications of CFGs
Forml Lnguges implifictions of CFGs ubstitution Rule Equivlent grmmr b bc ubstitute b bc bbc b 2 ubstitution Rule b bc bbc ubstitute b bc bbc bc Equivlent grmmr 3 In generl: xz y 1 ubstitute y 1 xz xy1z
More informationBases for Vector Spaces
Bses for Vector Spces 2-26-25 A set is independent if, roughly speking, there is no redundncy in the set: You cn t uild ny vector in the set s liner comintion of the others A set spns if you cn uild everything
More informationNon-Deterministic Finite Automata. Fall 2018 Costas Busch - RPI 1
Non-Deterministic Finite Automt Fll 2018 Costs Busch - RPI 1 Nondeterministic Finite Automton (NFA) Alphbet ={} q q2 1 q 0 q 3 Fll 2018 Costs Busch - RPI 2 Nondeterministic Finite Automton (NFA) Alphbet
More informationCS103B Handout 18 Winter 2007 February 28, 2007 Finite Automata
CS103B ndout 18 Winter 2007 Ferury 28, 2007 Finite Automt Initil text y Mggie Johnson. Introduction Severl childrens gmes fit the following description: Pieces re set up on plying ord; dice re thrown or
More informationCS 275 Automata and Formal Language Theory
CS 275 Automt nd Forml Lnguge Theory Course Notes Prt II: The Recognition Problem (II) Chpter II.5.: Properties of Context Free Grmmrs (14) Anton Setzer (Bsed on book drft by J. V. Tucker nd K. Stephenson)
More informationSection 6: Area, Volume, and Average Value
Chpter The Integrl Applied Clculus Section 6: Are, Volume, nd Averge Vlue Are We hve lredy used integrls to find the re etween the grph of function nd the horizontl xis. Integrls cn lso e used to find
More information5.2 Exponent Properties Involving Quotients
5. Eponent Properties Involving Quotients Lerning Objectives Use the quotient of powers property. Use the power of quotient property. Simplify epressions involving quotient properties of eponents. Use
More informationCMPSCI 250: Introduction to Computation. Lecture #31: What DFA s Can and Can t Do David Mix Barrington 9 April 2014
CMPSCI 250: Introduction to Computtion Lecture #31: Wht DFA s Cn nd Cn t Do Dvid Mix Brrington 9 April 2014 Wht DFA s Cn nd Cn t Do Deterministic Finite Automt Forml Definition of DFA s Exmples of DFA
More information4.4 Areas, Integrals and Antiderivatives
. res, integrls nd ntiderivtives 333. Ares, Integrls nd Antiderivtives This section explores properties of functions defined s res nd exmines some connections mong res, integrls nd ntiderivtives. In order
More informationCS 310 (sec 20) - Winter Final Exam (solutions) SOLUTIONS
CS 310 (sec 20) - Winter 2003 - Finl Exm (solutions) SOLUTIONS 1. (Logic) Use truth tles to prove the following logicl equivlences: () p q (p p) (q q) () p q (p q) (p q) () p q p q p p q q (q q) (p p)
More information12.1 Nondeterminism Nondeterministic Finite Automata. a a b ε. CS125 Lecture 12 Fall 2016
CS125 Lecture 12 Fll 2016 12.1 Nondeterminism The ide of nondeterministic computtions is to llow our lgorithms to mke guesses, nd only require tht they ccept when the guesses re correct. For exmple, simple
More informationCOMPLEX NUMBERS INDEX
COMPLEX NUMBERS INDEX. The hstory of the complex numers;. The mgnry unt I ;. The Algerc form;. The Guss plne; 5. The trgonometrc form;. The exponentl form; 7. The pplctons of the complex numers. School
More informationMore on automata. Michael George. March 24 April 7, 2014
More on utomt Michel George Mrch 24 April 7, 2014 1 Automt constructions Now tht we hve forml model of mchine, it is useful to mke some generl constructions. 1.1 DFA Union / Product construction Suppose
More informationDIRECT CURRENT CIRCUITS
DRECT CURRENT CUTS ELECTRC POWER Consider the circuit shown in the Figure where bttery is connected to resistor R. A positive chrge dq will gin potentil energy s it moves from point to point b through
More informationFinite Automata. Informatics 2A: Lecture 3. John Longley. 22 September School of Informatics University of Edinburgh
Lnguges nd Automt Finite Automt Informtics 2A: Lecture 3 John Longley School of Informtics University of Edinburgh jrl@inf.ed.c.uk 22 September 2017 1 / 30 Lnguges nd Automt 1 Lnguges nd Automt Wht is
More informationLecture 3. In this lecture, we will discuss algorithms for solving systems of linear equations.
Lecture 3 3 Solving liner equtions In this lecture we will discuss lgorithms for solving systems of liner equtions Multiplictive identity Let us restrict ourselves to considering squre mtrices since one
More informationNondeterminism and Nodeterministic Automata
Nondeterminism nd Nodeterministic Automt 61 Nondeterminism nd Nondeterministic Automt The computtionl mchine models tht we lerned in the clss re deterministic in the sense tht the next move is uniquely
More informationReview of linear algebra. Nuno Vasconcelos UCSD
Revew of lner lgebr Nuno Vsconcelos UCSD Vector spces Defnton: vector spce s set H where ddton nd sclr multplcton re defned nd stsf: ) +( + ) (+ )+ 5) λ H 2) + + H 6) 3) H, + 7) λ(λ ) (λλ ) 4) H, - + 8)
More informationSection 4: Integration ECO4112F 2011
Reding: Ching Chpter Section : Integrtion ECOF Note: These notes do not fully cover the mteril in Ching, ut re ment to supplement your reding in Ching. Thus fr the optimistion you hve covered hs een sttic
More informationThe Schur-Cohn Algorithm
Modelng, Estmton nd Otml Flterng n Sgnl Processng Mohmed Njm Coyrght 8, ISTE Ltd. Aendx F The Schur-Cohn Algorthm In ths endx, our m s to resent the Schur-Cohn lgorthm [] whch s often used s crteron for
More informationCoalgebra, Lecture 15: Equations for Deterministic Automata
Colger, Lecture 15: Equtions for Deterministic Automt Julin Slmnc (nd Jurrin Rot) Decemer 19, 2016 In this lecture, we will study the concept of equtions for deterministic utomt. The notes re self contined
More informationICS 252 Introduction to Computer Design
ICS 252 Introducton to Computer Desgn Prttonng El Bozorgzdeh Computer Scence Deprtment-UCI Prttonng Decomposton of complex system nto smller susystems Done herrchclly Prttonng done untl ech susystem hs
More informationCS 330 Formal Methods and Models
CS 330 Forml Methods nd Models Dn Richrds, section 003, George Mson University, Fll 2017 Quiz Solutions Quiz 1, Propositionl Logic Dte: Septemer 7 1. Prove (p q) (p q), () (5pts) using truth tles. p q
More informationMath 426: Probability Final Exam Practice
Mth 46: Probbility Finl Exm Prctice. Computtionl problems 4. Let T k (n) denote the number of prtitions of the set {,..., n} into k nonempty subsets, where k n. Argue tht T k (n) kt k (n ) + T k (n ) by
More informationThe Regulated and Riemann Integrals
Chpter 1 The Regulted nd Riemnn Integrls 1.1 Introduction We will consider severl different pproches to defining the definite integrl f(x) dx of function f(x). These definitions will ll ssign the sme vlue
More informationThe graphs of Rational Functions
Lecture 4 5A: The its of Rtionl Functions s x nd s x + The grphs of Rtionl Functions The grphs of rtionl functions hve severl differences compred to power functions. One of the differences is the behvior
More information