Bottom-Up Parsing. Canonical Collection of LR(0) items. Part II

Size: px
Start display at page:

Download "Bottom-Up Parsing. Canonical Collection of LR(0) items. Part II"

Transcription

1 2 ottom-up Prsing Prt II 1 Cnonil Colletion of LR(0) items CC_LR(0)_I items(g :ugmented_grmmr){ C = {CLOURE({ })} ; repet{ foreh(i C) foreh(grmmr symol X) if(goto(i,x) && GOTO(I,X) C) C = C {GOTO(I,X)}; }until(no new sets of items re dded to C) return C; }

2 4 LR(0) utomton G : ugmented grmmr LR(0) utomton for G Q, q0, GOTO: Q (T G N G ) Q, F where: Q = F = items(g ), q0 = CLOURE({ }) 3 Constrution of the LR(0) utomton for the expression grmmr: E E E E + T T T T* F F F (E) id

3 E E E E + T T T T* F F F (E) id 5 E E E E + T T T T* F F F (E) id id I 0 E >.E E >. E+T E >.T T >.T*F T >.F F >.(E) F >.id ( F E I + I 6 T 1 E > E+. T E > E. T >. T*F E > E. + T T >.F F F >.(E) F >.id ( T I 2 E > T. T > T.*F * I 7 T > T*.F F >.(E) F >. id id I 5 I 4 F ( I 9 E > E+T. T > T.*F I 3 I 10 T > T*F. * I 7 I 3 T > F. id I 5 I 4 I 5 F > id. id I 4 F > (. E ) E >. E + T E >.T T >. T * F T >. F F >. ( E ) F >. id E F T I 8 F > ( E. ) E > E. + T I 2 ) + I 6 I 11 F > ( E ). ( I 3 6

4 8 E E E E + T T T T* F F F (E) id F E + T I 0 I 1 I 6 T id F $ ( id ept ( I 9 * I 2 * id I 7 ( F I 10 I 5 + I 8 ) I 11 T I 4 id E ( F I 3 7 hift-redue prsing using LR(0) utomton Push(I0); repet{ //egin to sn the input from left to right Ii = top() nd next input symol ; if (Ij = GOTO(Ii,)) then shift nd Ij; // Push() // push(ij). else if ( β Ii) then{ perform redue y β ; go to the stte Ij = GOTO(I,) nd push nd Ij into the stk //where I is the stte on the top_of stk //fter removing β nd the orresponding sttes; } _exit(rejet if none of the ove n e done); _exit(report onflits if more thn one n e done); } until EOF is seen

5 MODEL OF N LR PRER input 1... i... n $ s m s m-1 : : $ LR Prsing Progrm output stk CTION GOTO 9 I0,...,In enumertion of items(g') I0= CLOURE({ʼ }) Q = {0,...,n} s Is GOTO(s,X)=s' GOTO(Is,X)= Is' Proposition: if GOTO(s',X)=s nd GOTO(s",Y)=s then X=Y s Q we ssoite unique symol X s T G N G to s 0 if GOTO(s',X)=s then X s = X. Moreover, X 0 represents the symol $ (ottom of the stk) Q, 0, GOTO: Q (TGʼ NGʼ) Q, F Fix for G' finite ijetive enumertion p: {1,...,n} G'-produtions, s.t. p(1)= ' 10

6 12 Construt the LR(0) utomton for the grmmr C Ce C df 11 C Ce C df ept

7 C Ce C df!"#$%&'()*+,--,./01!"#$%&'&()*+&,-..-/012 3%4%#*&5)*("&)+*6()7&$6#)7%89 (:&;& &α<β&*6%)&#==&,>31?0β2@ε&*+&,-..-/0<2 (:&;& &α<&*6%)&#==&,-..-/0;2&*+&,-..-/0<2 (:&;& &α<β&#)=&ε&(8&()&,>31?0β2&*6%)&#==&,-..-/0;2& *+&,-..-/0<2 Follow 1 ()={$} Follow 1 ()={f,$} Follow 1 ()={f,$} Follow 1 (C)={e,f,$} 13 C Ce C df!"#$%&'()*+,--,./01!"#$%&'&()*+&,-..-/012 3%4%#*&5)*("&)+*6()7&$6#)7%89 (:&;& &α<β&*6%)&#==&,>31?0β2@ε&*+&,-..-/0<2 (:&;& &α<&*6%)&#==&,-..-/0;2&*+&,-..-/0<2 (:&;& &α<β&#)=&ε&(8&()&,>31?0β2&*6%)&#==&,-..-/0;2& *+&,-..-/0<2 Follow 1 ()={$} Follow 1 ()={f,$} Follow 1 ()={f,$} Follow 1 (C)={e,f,$} 14

8 15 terminls nd $ PRING TLE non terminls tte CTION GOTO i = CTION[i,] G = GOTO[j,] j G CTION[i,]= s j (shift symol j (nmely Xj)) CTION[i,]= r k (redue prodution p(k)) CTION[i,]= ept CTION[i,]= error 16

9 LR-PRER CONFIGURTION onfigurtion stk remining input ( 0 s 1... s m, i i+1... n $ ) top right-sententil form X0 Xs 1... Xs m i i+1... n 17 EHVIOR OF THE LR PRER ( s 0 s 1... s m, i i+1... n $ ) CTION[sm,i] = shift s symol Xs ( s 0 s 1... s m s, i+1... n $ ) ( s 0 s 1... s m, i i+1... n $ ) CTION[sm,i] = redue k ( s 0 s 1... s m-r s, i i+1... n $ ) p(k)= β β = r s=goto[s m-r, ] symol Xs 18

10 20 EHVIOR OF THE LR PRER ( s 0 s 1... s m, i i+1... n $ ) CTION[sm,i] = ept end of prsing ( s 0 s 1... s m, i i+1... n $ ) CTION[sm,i] = error error reovery routine 19 LR-prsing lgorithm

11 F E + T T id F $ ( id ept ( * 2 7 F id ( + ) 5 8 id T E 4 ( F 3 9 * X 1 = E X 2 = T X 3 = F X 4 = ( X 5 = id X 6 = + X 7 = * X 8 = E X 9 = T X 10 = F X 11 = ) 21 X 1 = E X 2 = T X 3 = F X 4 = ( X 5 = id X 6 = + X 7 = * X 8 = E X 9 = T X 10 = F X 11 = ) id id + id 22

12 24 X 1 = E X 2 = T X 3 = F X 4 = ( X 5 = id X 6 = + X 7 = * X 8 = E X 9 = T X 10 = F X 11 = ) 23 1.G : ugmented grmmr, with enumertion p of produtions; 2.onstrut the LR(0) utomton (nonil item set C={I0,...,In}, I0=CLOURE[ ] GOTO funtion); 3.foreh stte i: () if ( α β Ii && GOTO[Ii,]=Ij) dd shift j to CTION[i,]; () if ( α Ii && ) foreh ( FOLLOW()) dd redue p -1 ( α) to CTION[i,]; () if ( Ii) dd ept to CTION[i,$] 4. foreh (stte i,k && symol ) if (GOTO[Ij,]=Ik) dd k to GOTO[s,] 5. if (CTION[i,] is undefined) dd error to CTION[i,] 6. if (GOTO[i,] is undefined) dd error to GOTO[i,]

13 26 25 LR-prsing lgorithm

14 ' C C Ce df Exerise: Construt the PRING TLE 27 ' C q2 '!" q8 C!d"f!"!" C Ce df Prse tle omplete. Press "prse" to use it. q2 '!" q0 '!"!"!"!" q8 C!d"f!"!" q0 '!"!"!"!" q4 d!"ce!"!"c q10 FIRT C!d"f q1!" q4 d!"ce!"!"c q10 C!d"f q1!" f q5!" f q5!" q11 C!df" q11 C!df" q3!" FOLLOW {, } { f, $ } { } { f, $ } C { d } { f, e, $ } {, } { $ } q3!" C q6!"ce C!"df!"C q7!c"!c"e C q6 e q7!c"!c"e!"ce C!"df!"C q9!ce" e q9!ce" 28

15 30 ' C C Ce df q2 '!" q8 C!d"f!"!" q0 '!"!"!"!" d q1!" q4!"ce!"!"c q5!" f q11 q10 C!df" C!d"f q3!" C q6 q7!c"!c"e!"ce C!"df!"C e q9!ce" Prse tle omplete. Press "prse" to use it. FIRT FOLLOW {, } { f, $ } { } { f, $ } C { d } { f, e, $ } {, } { $ } q1 29 q2 q0!" q3!" '!" q8 C!d"f!"!" '!"!"!"!" q4 d!"ce!"!"c q5!" Construting n LR-prsing Tle I0=CLOURE[ ] GOTO funtion); q11 q10 C!df" C!d"f C q6 q7!c"!c"e!"ce C!"df!"C e q9!ce" 1.G : ugmented grmmr, with enumertion p of produtions; 2.onstrut the LR(0) utomton (nonil item set C={I0,...,In}, 3.foreh stte i: () if ( α β Ii && GOTO[Ii,]=Ij) dd shift j to CTION[i,]; () if ( α Ii && ) foreh ( FOLLOW()) dd redue p -1 ( α) to CTION[i,]; () if ( Ii) dd ept to CTION[i,$] 4. foreh (stte i,k && symol ) if (GOTO[Ij,]=Ik) dd k to GOTO[s,] 5. if (CTION[i,] is undefined) dd error to CTION[i,] 6. if (GOTO[i,] is undefined) dd error to GOTO[i,]

16 ' Prse tle omplete. Press "prse" to use it. FIRT FOLLOW { } {, } {, } { } { } { $ } q0!" '!" q1 '!" q9!" q4 q0!" '!"!"!"!"!" q1 '!" q9!" q0 q2!" '!"!"!"!" q1 q7 '!"!" q8 q4!"!"!"!"!"!"!"!" q7!" q3!"!"!" q4 q9!"!"!"!" q2!" q12!" q8!" q8 q3!"!"!"!" q12!" q2!"!"!" q7!" q6!"!"!" q6!"!"!" q3!"!"!" q12!" q5!" q10!" q11!" q5!" q6 q10!"!"!"!" q11!" q5!" q10!" q11!" 31 Do eleted Do tep Do ll Next Prse ' Prse tle omplete. Press "prse" to use it. FIRT $ FOLLOW { } {, } 0{, } s2 { } 1 { } 1 { $ } 2 s4 3 3 s6 s7 5 4 s4 s9 8 q0 q2 q3 q5 5 s10!"!"!"!" rse tle omplete. Press "prse" to use it. 6 s6 s7 11 '!"!"!" 7 r5 FIRT FOLLOW!"!" Next Prse tle omplete. to use it. } 8 s12 rse Press { }"prse" {, } {, { } 9 r3 r3 q10 { } {, } { } {, } { $ } { } q7 10 r1 { } { $ } q4!" q9 11 r4!" q6 12!" r2 r2!" q1!"!" q8 q12 q11!"!" q0 q2 q3 q5 '!"!"!"!"!"!"!"!" '!" q0!" '!" q1 '!" q9!" $ 0 s s4 3 3 s6 s7 5 q4!"!"!" q7!" 4 s4 s9 8!"!"!" q6 q10!" 32

17 it is not miguous Item set? 33 Item set : Prsing tle? 34

18 36 Item set : = if ( α Ii && ) foreh ( FOLLOW()) dd redue p -1 ( α) to CTION[i,]; prsing tle shift 6 CTION[2,=] symol = FOLLOW(R) nd therefore: redue R L CTION[2,=] onflit! 35 Vile prefix prefix of right-sententil forms tht n pper on the top of the stk Not ll prefixes of right-sententil forms n pper on the stk, however, sine the prser must not shift pst the hndle Exmple: TCK: (, (E, nd (E), ut not (E)* (E) is hndle (the prser must redue it to F efore shifting *)

19 38 Vile prefix: prefix of right-sententil forms tht n pper on the top of the stk nd tht does not ontinue pst the right end of the rightmost hndle of tht sententil form. prefix γ of αβ, where ' * αw αβw rm rm β 1 β 2 is vlid for vile prefix αβ 1 if ' * αw αβ 1 β 2 w rm rm 37 β 1 β 2 is vlid for vile prefix αβ 1 if ' * αw αβ 1 β 2 w rm rm if β 2 ε then shift if β 2 =ε then redue β 1 possile onflits Two vlid items my tell us to do different things for the sme vile prefix. ome of these onflits n e resolved y looking t the next input symol THEOREM: the set of vlid items for vile prefix γ is extly the set of items rehed from the initil stte long the pth leled γ in the LR(0) utomton for the grmmr

20 Item set : = Prsing tle shift 6 CTION[2,=] symol = FOLLOW(R) nd therefore: redue R L CTION[2,=] Conflit! 39 LR(1) PRING Grmmr: L = R R L R id R L shift 6 CTION[2,=] symol = FOLLOW(R) nd therefore: redue R L CTION[2,=] there is no right-sententil form of the grmmr tht egins R =... Thus stte 2, whih is the stte orresponding to vile prefix L only, should not relly ll for redution of tht L to R $L $R 40

21 In LR(1) prsing, if α i, nd FOLLOW(), then we perform the redution α However, it is possile tht when stte i is on the top of the stk, we hve the vile prefix βα on the top of the stk, nd β nnot e followed y. In this se, we nnot perform the redution α. 41 LR(1) items n LR(1) item is in the form of [ α β,] 1.the first field α β is n LR(0) item 2.the seond field is terminl elonging to suset (possily proper) of FOLLOW[]. Intuition: perform redution sed on n LR(1) item [ α, ] only when the next symol is. Insted of mintining FOLLOW sets of vile prefixes, we mintin FIRT sets of possile future extensions of the urrent vile prefix. [ α β, ] is vlid for vile prefix γ if there exists derivtion where γ = δα w = w' or w=ε nd =$. ' * δw δαβw rm rm γ 42

22 Exmples of LR(1) items Grmmr: = = rm rm vile prefix n reh [, ] = = rm rm vile prefix n reh [,$] [ α β, ] is vlid for vile prefix γ if there exists derivtion ' * δw δαβw rm where γ = δα w = w' or w=ε nd =$. rm 43 Finding ll LR(1) items Ides: redefine the losure funtion. uppose [ α β,] is vlid for vile prefix γ δα. In other words, = δ ω = δ αβ ω. rm rm γ ω is ɛ or sequene of terminls. Then for eh prodution η, ssume βω derives the sequene of terminls eω. γ γ γ = rm δα βω = rm δα eω = rm δαη eω Thus [ η,] is lso vlid for γ for eh FIRT(β). Note is terminl. o FIRT(β) =FIRT(βω). [ α β, ] is vlid for vile prefix γ if there exists derivtion ' * δw δαβw rm rm γ where γ = δα w = w' or w=ε nd =$. 44

23 46 set_of_items CLOURE(I: set_of_items){ J=I; repet{ foreh ( [ α β,] J) foreh ( γ G) foreh ( FIRT[β]) J = J {[ γ,]}; }until (no more new items re dded to J) return J; } 45 set_of_items GOTO(I set_of_items, X:symol){ J= ; foreh([ α Xβ,] I) J = J {[ αx β,]}; return CLOURE(J); }

24 48 CC_LR(1)_I items(g :ugmented_grmmr){ C = {CLOURE({[,$]})} ; repet{ foreh(i C) foreh(grmmr symol X) if(goto(i,x) && GOTO(I,X) C) C = C {GOTO(I,X)}; }until(no new sets of items re dded to C) return C; } 47 1.G : ugmented grmmr, with enumertion p of produtions; 2.onstrut the LR(1) utomton (nonil item set C={I0,...,In}, I0=CLOURE[[,$]] GOTO funtion); 3.foreh stte i: () if ([ α β,] Ii && GOTO[Ii,]=Ij) dd shift j to CTION[i,]; // is terminl () if ([ α,] Ii && ) dd redue p -1 ( α) to CTION[i,]; () if ([,$] Ii) dd ept to CTION[i,$] 4. foreh (stte i,k && symol ) if (GOTO[Ij,]=Ik) dd k to GOTO[s,] 5. if (CTION[i,] is undefined) dd error to CTION[i,] 6. if (GOTO[i,] is undefined) dd error to GOTO[i,]

25 50 Exmple for onstruting LR(1) losures Grmmr: CC C C d losure 1 ({[, $]}) = {[, $], [ CC, $], [C C, /d], J=I; [C d, /d]} Note: repet{ FIRT(ɛ$) = {$} FIRT(C$) = {, d} [C foreh C, /d] ( mens γ G) set_of_items CLOURE(I: set_of_items){ } foreh ( [ α β,] J) [Cforeh C, ] ( nd FIRT[β]) J = J {[ γ,]}; [C C, d]. }until (no more new items re dded to J) return J; tion 1 GOTO 1 stte d $ C 0 s3 s ept 2 s6 s7 5 3 s3 s4 8 4 r3 r3 5 r1 6 s6 s7 9 7 r3 8 r2 r2 9 r2 49 Exmple for onstruting LR(1) losures Grmmr: CC C C d losure 1 ({[, $]}) = {[, $], [ CC, $], [C C, /d], [C d, /d]} Note: FIRT(ɛ$) = {$} FIRT(C$) = {, d} [C C, /d] mens [C C, ] nd [C C, d]. set_of_items CLOURE(I: set_of_items){ J=I; repet{ foreh ( [ α β,] J) foreh ( γ G) foreh ( FIRT[β]) J = J {[ γ,]}; }until (no more new items re dded to J) return J; }

26 52 Exmple for onstruting LR(1) losures Grmmr: CC C C d losure 1 ({[, $]}) = {[, $], [ CC, $], [C C, /d], [C d, /d]} Note: FIRT(ɛ$) = {$} FIRT(C$) = {, d} [C C, /d] mens [C C, ] nd [C C, d]. set_of_items CLOURE(I: set_of_items){ J=I; repet{ foreh ( [ α β,] J) foreh ( γ G) foreh ( FIRT[β]) J = J {[ γ,]}; }until (no more new items re dded to J) return J; } 51 set_of_items CLOURE(I: set_of_items){ J=I; repet{ foreh ( [ α β,] J) foreh ( γ G) foreh ( FIRT[β]) J = J {[ γ,]}; }until (no more new items re dded to J) return J; }

27 54 Exmple for onstruting LR(1) losures Grmmr: CC C C d losure 1 ({[, $]}) = {[, $], [ CC, $], [C C, /d], [C d, /d]} Note: FIRT(ɛ$) = {$} FIRT(C$) = {, d} [C C, /d] mens [C C, ] nd [C C, d]. tion 1 GOTO 1 stte d $ C 0 s3 s ept 2 s6 s7 5 3 s3 s4 8 4 r3 r3 5 r1 6 s6 s7 9 7 r3 8 r2 r2 9 r2 53 LLR(1) prser Lookhed LR The method tht is often used in prtie. Most ommon syntti onstruts of progrmming lnguges n e expressed onveniently y n LLR(1) grmmr [DeRemer 1969]. LR(1) nd LLR(1) lwys hve the sme numer of sttes. Numer of sttes is out 1/10 of tht of LR(1). imple oservtion: n LR(1) item is of the form [ α β,] We ll α β the first omponent. Definition: in n LR(1) stte, set of first omponents is lled its ore.

28 56 1.G : ugmented grmmr, with enumertion p of produtions; 2.onstrut the LR(1) utomton (nonil item set C={I0,...,In}, I0=CLOURE[[,$]] GOTO funtion); 3.foreh stte i: () if ([ α β,] Ii && GOTO[Ii,]=Ij) dd shift j to CTION[i,]; // is terminl () if ([ α,] Ii && ) dd redue p -1 ( α) to CTION[i,]; () if ([,$] Ii) dd ept to CTION[i,$] 4. foreh (stte i,k && symol ) if (GOTO[Ij,]=Ik) dd k to GOTO[s,] 5. if (CTION[i,] is undefined) dd error to CTION[i,] 6. if (GOTO[i,] is undefined) dd error to GOTO[i,] 55 Intuition for LLR(1) grmmrs In n LR(1) prser, it is ommon thing tht severl sttes only differ in lookhed symols, ut hve the sme ore. To redue the numer of sttes, we might wnt to merge sttes with the sme ore. If I 4 nd I 7 re merged, then the new stte is lled I 4,7. fter merging the sttes, revise the GOT O 1 tle ordingly. Merging of sttes n never produe shift-redue onflit tht ws not present in one of the originl sttes. I 1 = {[ α,],...} For I 1, one of the tions is to perform redue when the lookhed symol is. I 2 = {[ β γ,],...} For I 2, one of the tions is to perform shift on input. Merging I 1 nd I 2, the new stte I 1,2 hs shift-redue onflits. However, we merge I 1 nd I 2 euse they hve the sme ore. Tht is, [ α,] I 2 nd [ β γ,d] I 1. The shift-redue onflit lredy ours in I 1 nd I 2. Merging of sttes n produe new redue-redue onflit.

29 LLR(1) trnsition digrm d I 0!>., $!>. CC, $ C!>. C, /d C!>.d, /d C I 3 C!>.C, /d C!>.C, /d C!>.d, /d I 2!> C.C, $ C!>.C, $ C!>.d, $ I 1!>., $ C d I 5!> CC., $ I 6 C!>.C, $ C!>.C, $ C!>.d, $ C d C d I 8 C!> C., /d I 9 C!> C., $ I 4 C!> d., /d I 7 C!> d., $ 57 Possile new onflits from LLR(1) My produe new redue-redue onflit. For exmple (textook pge 267, Exmple 4.58), grmmr: d f e e The lnguge reognized y this grmmr is {d, e, d, e}. You my hek tht this grmmr is LR(1) y onstruting the sets of items. You will find the set of items {[,d], [,e]} is vlid for the vile prefix, nd {[,e], [,d]} is vlid for the vile prefix. Neither of these sets genertes onflit, nd their ores re the sme. However, their union, whih is {[, d/e], [, d/e]}, genertes redue-redue onflit, sine redutions y oth nd re lled for on inputs d nd e. 58

30 60 How to onstrut LLR(1) prsing tle Nive pproh: Construt LR(1) prsing tle, whih tkes lots of intermedite spes. Merging sttes. pe nd/or time effiient methods to onstrut n LLR(1) prsing tle re known. Construting nd merging on the fly. 59 ummry LLR(1) LLR(1) LL(1) LR(1) LR(1) LR(1) LR(1) LR(0) LR(1) nd LLR(1) n lmost express ll importnt progrmming lnguges issues, ut LLR(1) is esier to write nd uses muh less spe. LL(1) is esier to understnd nd uses muh less spe, ut nnot express some importnt ommon-lnguge fetures. My try to use it first for your own pplitions.

31 62 miguous grmmrs re not too d... miguous grmmrs unmiguous grmmrs LR(1) miguous grmmrs often provide shorter, more nturl speifition thn their equivlent unmiguous grmmrs. 61 miguity from preedene nd ssoitivity Preedene nd ssoitivity re importnt lnguge onstruts. Exmple: G 1 : E E + E E E (E) id miguous, ut esy to understnd nd mintin! G 2 : E E + T T T T F F F (E) id Unmiguous, ut diffiult to understnd nd mintin!

32 64 LR(0) sttes input: id+id id the prser enters stte 7 fter proessing id+id 63 miguity from dngling-else Grmmr: ttement Other ttement if Condition then ttement if Condition then ttement else ttement When seeing if C then else there is shift/redue onflit, we lwys fvor shift. Intuition: fvor longer mth. Need mehnism to let user speify the defult onflithndling rule when there is shift/redue onflit.

Overview HC9. Parsing: Top-Down & LL(1) Context-Free Grammars (1) Introduction. CFGs (3) Context-Free Grammars (2) Vertalerbouw HC 9: Ch.

Overview 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 information

CS 573 Automata Theory and Formal Languages

CS 573 Automata Theory and Formal Languages Non-determinism Automt Theory nd Forml Lnguges Professor Leslie Lnder Leture # 3 Septemer 6, 2 To hieve our gol, we need the onept of Non-deterministi Finite Automton with -moves (NFA) An NFA is tuple

More information

The University of Nottingham SCHOOL OF COMPUTER SCIENCE A LEVEL 2 MODULE, SPRING SEMESTER MACHINES AND THEIR LANGUAGES ANSWERS

The University of Nottingham SCHOOL OF COMPUTER SCIENCE A LEVEL 2 MODULE, SPRING SEMESTER MACHINES AND THEIR LANGUAGES ANSWERS The University of ottinghm SCHOOL OF COMPUTR SCIC A LVL 2 MODUL, SPRIG SMSTR 2015 2016 MACHIS AD THIR LAGUAGS ASWRS Time llowed TWO hours Cndidtes my omplete the front over of their nswer ook nd sign their

More information

CS311 Computational Structures Regular Languages and Regular Grammars. Lecture 6

CS311 Computational Structures Regular Languages and Regular Grammars. Lecture 6 CS311 Computtionl Strutures Regulr Lnguges nd Regulr Grmmrs Leture 6 1 Wht we know so fr: RLs re losed under produt, union nd * Every RL n e written s RE, nd every RE represents RL Every RL n e reognized

More information

Nondeterministic Automata vs Deterministic Automata

Nondeterministic Automata vs Deterministic Automata Nondeterministi Automt vs Deterministi Automt We lerned tht NFA is onvenient model for showing the reltionships mong regulr grmmrs, FA, nd regulr expressions, nd designing them. However, we know tht n

More information

CS241 Week 6 Tutorial Solutions

CS241 Week 6 Tutorial Solutions 241 Week 6 Tutoril olutions Lnguges: nning & ontext-free Grmmrs Winter 2018 1 nning Exerises 1. 0x0x0xd HEXINT 0x0 I x0xd 2. 0xend--- HEXINT 0xe I nd ER -- MINU - 3. 1234-120x INT 1234 INT -120 I x 4.

More information

Closure Properties of Regular Languages

Closure 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 information

CS 314 Principles of Programming Languages

CS 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 information

Project 6: Minigoals Towards Simplifying and Rewriting Expressions

Project 6: Minigoals Towards Simplifying and Rewriting Expressions MAT 51 Wldis Projet 6: Minigols Towrds Simplifying nd Rewriting Expressions The distriutive property nd like terms You hve proly lerned in previous lsses out dding like terms ut one prolem with the wy

More information

The transformation to right derivation is called the canonical reduction sequence. Bottom-up analysis

The transformation to right derivation is called the canonical reduction sequence. Bottom-up analysis Bottom-up nlysis Shift-reduce prsing. Constructs the derivtion tree from ottom to top. Reduces the string to the strt symol. Produces reverse right derivtion. Exmple: G(E): 1. E E + T 2. T 3. T T * F 4.

More information

Convert the NFA into DFA

Convert 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 information

Parsing and Pattern Recognition

Parsing and Pattern Recognition Topics in IT Prsing nd Pttern Recognition Week Context-Free Prsing College of Informtion Science nd Engineering Ritsumeikn University this week miguity in nturl lnguge in mchine lnguges top-down, redth-first

More information

NON-DETERMINISTIC FSA

NON-DETERMINISTIC FSA Tw o types of non-determinism: NON-DETERMINISTIC FS () Multiple strt-sttes; strt-sttes S Q. The lnguge L(M) ={x:x tkes M from some strt-stte to some finl-stte nd ll of x is proessed}. The string x = is

More information

FABER Formal Languages, Automata and Models of Computation

FABER Formal Languages, Automata and Models of Computation DVA337 FABER Forml Lnguges, Automt nd Models of Computtion Lecture 5 chool of Innovtion, Design nd Engineering Mälrdlen University 2015 1 Recp of lecture 4 y definition suset construction DFA NFA stte

More information

SEMANTIC ANALYSIS PRINCIPLES OF PROGRAMMING LANGUAGES. Norbert Zeh Winter Dalhousie University 1/28

SEMANTIC ANALYSIS PRINCIPLES OF PROGRAMMING LANGUAGES. Norbert Zeh Winter Dalhousie University 1/28 SEMNTI NLYSIS PRINIPLES OF PROGRMMING LNGUGES Norbert Zeh Winter 2018 Dlhousie University 1/28 PROGRM TRNSLTION FLOW HRT Soure progrm (hrter strem) Snner (lexil nlysis) Front end Prse tree Prser (syntti

More information

Semantic Analysis. CSCI 3136 Principles of Programming Languages. Faculty of Computer Science Dalhousie University. Winter Reading: Chapter 4

Semantic Analysis. CSCI 3136 Principles of Programming Languages. Faculty of Computer Science Dalhousie University. Winter Reading: Chapter 4 Semnti nlysis SI 16 Priniples of Progrmming Lnguges Fulty of omputer Siene Dlhousie University Winter 2012 Reding: hpter 4 Motivtion Soure progrm (hrter strem) Snner (lexil nlysis) Front end Prse tree

More information

Chapter 4 State-Space Planning

Chapter 4 State-Space Planning Leture slides for Automted Plnning: Theory nd Prtie Chpter 4 Stte-Spe Plnning Dn S. Nu CMSC 722, AI Plnning University of Mrylnd, Spring 2008 1 Motivtion Nerly ll plnning proedures re serh proedures Different

More information

General idea LR(0) SLR LR(1) LALR To best exploit JavaCUP, should understand the theoretical basis (LR parsing);

General idea LR(0) SLR LR(1) LALR To best exploit JavaCUP, should understand the theoretical basis (LR parsing); Bottom up prsing Generl ide LR(0) SLR LR(1) LLR To best exploit JvCUP, should understnd the theoreticl bsis (LR prsing); 1 Top-down vs Bottom-up Bottom-up more powerful thn top-down; Cn process more powerful

More information

Finite State Automata and Determinisation

Finite State Automata and Determinisation Finite Stte Automt nd Deterministion Tim Dworn Jnury, 2016 Lnguges fs nf re df Deterministion 2 Outline 1 Lnguges 2 Finite Stte Automt (fs) 3 Non-deterministi Finite Stte Automt (nf) 4 Regulr Expressions

More information

CSCI565 - Compiler Design

CSCI565 - Compiler Design CSCI565 - Compiler Deign Spring 6 Due Dte: Fe. 5, 6 t : PM in Cl Prolem [ point]: Regulr Expreion nd Finite Automt Develop regulr expreion (RE) tht detet the longet tring over the lphet {-} with the following

More information

NFA DFA Example 3 CMSC 330: Organization of Programming Languages. Equivalence of DFAs and NFAs. Equivalence of DFAs and NFAs (cont.

NFA DFA Example 3 CMSC 330: Organization of Programming Languages. Equivalence of DFAs and NFAs. Equivalence of DFAs and NFAs (cont. NFA DFA Exmple 3 CMSC 330: Orgniztion of Progrmming Lnguges NFA {B,D,E {A,E {C,D {E Finite Automt, con't. R = { {A,E, {B,D,E, {C,D, {E 2 Equivlence of DFAs nd NFAs Any string from {A to either {D or {CD

More information

Minimal DFA. minimal DFA for L starting from any other

Minimal 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 information

Regular languages refresher

Regular languages refresher Regulr lnguges refresher 1 Regulr lnguges refresher Forml lnguges Alphet = finite set of letters Word = sequene of letter Lnguge = set of words Regulr lnguges defined equivlently y Regulr expressions Finite-stte

More information

Formal languages, automata, and theory of computation

Formal languages, automata, and theory of computation Mälrdlen University TEN1 DVA337 2015 School of Innovtion, Design nd Engineering Forml lnguges, utomt, nd theory of computtion Thursdy, Novemer 5, 14:10-18:30 Techer: Dniel Hedin, phone 021-107052 The exm

More information

Technische Universität München Winter term 2009/10 I7 Prof. J. Esparza / J. Křetínský / M. Luttenberger 11. Februar Solution

Technische Universität München Winter term 2009/10 I7 Prof. J. Esparza / J. Křetínský / M. Luttenberger 11. Februar Solution Tehnishe Universität Münhen Winter term 29/ I7 Prof. J. Esprz / J. Křetínský / M. Luttenerger. Ferur 2 Solution Automt nd Forml Lnguges Homework 2 Due 5..29. Exerise 2. Let A e the following finite utomton:

More information

CS103B Handout 18 Winter 2007 February 28, 2007 Finite Automata

CS103B 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 information

Chapter 4 Regular Grammar and Regular Sets. (Solutions / Hints)

Chapter 4 Regular Grammar and Regular Sets. (Solutions / Hints) C K Ngpl Forml Lnguges nd utomt Theory Chpter 4 Regulr Grmmr nd Regulr ets (olutions / Hints) ol. (),,,,,,,,,,,,,,,,,,,,,,,,,, (),, (c) c c, c c, c, c, c c, c, c, c, c, c, c, c c,c, c, c, c, c, c, c, c,

More information

Intermediate Math Circles Wednesday, November 14, 2018 Finite Automata II. Nickolas Rollick a b b. a b 4

Intermediate 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 information

Assignment 1 Automata, Languages, and Computability. 1 Finite State Automata and Regular Languages

Assignment 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 information

Prefix-Free Regular-Expression Matching

Prefix-Free Regular-Expression Matching Prefix-Free Regulr-Expression Mthing Yo-Su Hn, Yjun Wng nd Derik Wood Deprtment of Computer Siene HKUST Prefix-Free Regulr-Expression Mthing p.1/15 Pttern Mthing Given pttern P nd text T, find ll sustrings

More information

Review for the Midterm

Review for the Midterm Review for the Midterm Stephen A. Edwrds Columi University Fll 2018 The Midterm Structure of Compiler Scnning Lnguges nd Regulr Expressions NFAs Trnslting REs into NFAs: Thompson s Construction Building

More information

Chapter 2 Finite Automata

Chapter 2 Finite Automata Chpter 2 Finite Automt 28 2.1 Introduction Finite utomt: first model of the notion of effective procedure. (They lso hve mny other pplictions). The concept of finite utomton cn e derived y exmining wht

More information

Compiler Design. Spring Lexical Analysis. Sample Exercises and Solutions. Prof. Pedro C. Diniz

Compiler Design. Spring Lexical Analysis. Sample Exercises and Solutions. Prof. Pedro C. Diniz University of Southern Cliforni Computer Siene Deprtment Compiler Design Spring 7 Lexil Anlysis Smple Exerises nd Solutions Prof. Pedro C. Diniz USC / Informtion Sienes Institute 47 Admirlty Wy, Suite

More information

Designing finite automata II

Designing 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 information

@#? Text Search ] { "!" Nondeterministic Finite Automata. Transformation NFA to DFA and Simulation of NFA. Text Search Using Automata

@#? Text Search ] { ! Nondeterministic Finite Automata. Transformation NFA to DFA and Simulation of NFA. Text Search Using Automata g Text Serh @#? ~ Mrko Berezovský Rdek Mřík PAL 0 Nondeterministi Finite Automt n Trnsformtion NFA to DFA nd Simultion of NFA f Text Serh Using Automt A B R Power of Nondeterministi Approh u j Regulr Expression

More information

CS 275 Automata and Formal Language Theory

CS 275 Automata and Formal Language Theory CS 275 Automt nd Forml Lnguge Theory Course Notes Prt II: The Recognition Problem (II) Chpter II.6.: Push Down Automt Remrk: This mteril is no longer tught nd not directly exm relevnt Anton Setzer (Bsed

More information

Nondeterministic Finite Automata

Nondeterministic Finite Automata Nondeterministi Finite utomt The Power of Guessing Tuesdy, Otoer 4, 2 Reding: Sipser.2 (first prt); Stoughton 3.3 3.5 S235 Lnguges nd utomt eprtment of omputer Siene Wellesley ollege Finite utomton (F)

More information

Petri Nets. Rebecca Albrecht. Seminar: Automata Theory Chair of Software Engeneering

Petri Nets. Rebecca Albrecht. Seminar: Automata Theory Chair of Software Engeneering Petri Nets Ree Alreht Seminr: Automt Theory Chir of Softwre Engeneering Overview 1. Motivtion: Why not just using finite utomt for everything? Wht re Petri Nets nd when do we use them? 2. Introdution:

More information

CMSC 330: Organization of Programming Languages

CMSC 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 information

Homework Solution - Set 5 Due: Friday 10/03/08

Homework 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 information

Algorithm Design and Analysis

Algorithm Design and Analysis Algorithm Design nd Anlysis LECTURE 8 Mx. lteness ont d Optiml Ching Adm Smith 9/12/2008 A. Smith; sed on slides y E. Demine, C. Leiserson, S. Rskhodnikov, K. Wyne Sheduling to Minimizing Lteness Minimizing

More information

Types of Finite Automata. CMSC 330: Organization of Programming Languages. Comparing DFAs and NFAs. NFA for (a b)*abb.

Types 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 information

CS415 Compilers. Lexical Analysis and. These slides are based on slides copyrighted by Keith Cooper, Ken Kennedy & Linda Torczon at Rice University

CS415 Compilers. Lexical Analysis and. These slides are based on slides copyrighted by Keith Cooper, Ken Kennedy & Linda Torczon at Rice University CS415 Compilers Lexicl Anlysis nd These slides re sed on slides copyrighted y Keith Cooper, Ken Kennedy & Lind Torczon t Rice University First Progrmming Project Instruction Scheduling Project hs een posted

More information

Parse trees, ambiguity, and Chomsky normal form

Parse 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 information

Types of Finite Automata. CMSC 330: Organization of Programming Languages. Comparing DFAs and NFAs. Comparing DFAs and NFAs (cont.) Finite Automata 2

Types 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 information

Thoery of Automata CS402

Thoery of Automata CS402 Thoery of Automt C402 Theory of Automt Tle of contents: Lecture N0. 1... 4 ummry... 4 Wht does utomt men?... 4 Introduction to lnguges... 4 Alphets... 4 trings... 4 Defining Lnguges... 5 Lecture N0. 2...

More information

Normal Forms for Context-free Grammars

Normal Forms for Context-free Grammars Norml Forms for Context-free Grmmrs 1 Linz 6th, Section 6.2 wo Importnt Norml Forms, pges 171--178 2 Chomsky Norml Form All productions hve form: A BC nd A vrile vrile terminl 3 Exmples: S AS S AS S S

More information

1 PYTHAGORAS THEOREM 1. Given a right angled triangle, the square of the hypotenuse is equal to the sum of the squares of the other two sides.

1 PYTHAGORAS THEOREM 1. Given a right angled triangle, the square of the hypotenuse is equal to the sum of the squares of the other two sides. 1 PYTHAGORAS THEOREM 1 1 Pythgors Theorem In this setion we will present geometri proof of the fmous theorem of Pythgors. Given right ngled tringle, the squre of the hypotenuse is equl to the sum of the

More information

Formal Languages Simplifications of CFGs

Formal 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 information

The University of Nottingham SCHOOL OF COMPUTER SCIENCE A LEVEL 2 MODULE, SPRING SEMESTER LANGUAGES AND COMPUTATION ANSWERS

The University of Nottingham SCHOOL OF COMPUTER SCIENCE A LEVEL 2 MODULE, SPRING SEMESTER LANGUAGES AND COMPUTATION ANSWERS The University of Nottinghm SCHOOL OF COMPUTER SCIENCE LEVEL 2 MODULE, SPRING SEMESTER 2016 2017 LNGUGES ND COMPUTTION NSWERS Time llowed TWO hours Cndidtes my complete the front cover of their nswer ook

More information

Table of contents: Lecture N Summary... 3 What does automata mean?... 3 Introduction to languages... 3 Alphabets... 3 Strings...

Table of contents: Lecture N Summary... 3 What does automata mean?... 3 Introduction to languages... 3 Alphabets... 3 Strings... Tle of contents: Lecture N0.... 3 ummry... 3 Wht does utomt men?... 3 Introduction to lnguges... 3 Alphets... 3 trings... 3 Defining Lnguges... 4 Lecture N0. 2... 7 ummry... 7 Kleene tr Closure... 7 Recursive

More information

Algorithm Design and Analysis

Algorithm Design and Analysis Algorithm Design nd Anlysis LECTURE 5 Supplement Greedy Algorithms Cont d Minimizing lteness Ching (NOT overed in leture) Adm Smith 9/8/10 A. Smith; sed on slides y E. Demine, C. Leiserson, S. Rskhodnikov,

More information

Grammar. Languages. Content 5/10/16. Automata and Languages. Regular Languages. Regular Languages

Grammar. 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 information

= state, a = reading and q j

= state, a = reading and q j 4 Finite Automt CHAPTER 2 Finite Automt (FA) (i) Derterministi Finite Automt (DFA) A DFA, M Q, q,, F, Where, Q = set of sttes (finite) q Q = the strt/initil stte = input lphet (finite) (use only those

More information

AP Calculus BC Chapter 8: Integration Techniques, L Hopital s Rule and Improper Integrals

AP Calculus BC Chapter 8: Integration Techniques, L Hopital s Rule and Improper Integrals AP Clulus BC Chpter 8: Integrtion Tehniques, L Hopitl s Rule nd Improper Integrls 8. Bsi Integrtion Rules In this setion we will review vrious integrtion strtegies. Strtegies: I. Seprte the integrnd into

More information

Regular expressions, Finite Automata, transition graphs are all the same!!

Regular 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 information

CS 330 Formal Methods and Models

CS 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 information

Data Structures and Algorithm. Xiaoqing Zheng

Data Structures and Algorithm. Xiaoqing Zheng Dt Strutures nd Algorithm Xioqing Zheng zhengxq@fudn.edu.n String mthing prolem Pttern P ours with shift s in text T (or, equivlently, tht pttern P ours eginning t position s + in text T) if T[s +... s

More information

Lecture 6: Coding theory

Lecture 6: Coding theory Leture 6: Coing theory Biology 429 Crl Bergstrom Ferury 4, 2008 Soures: This leture loosely follows Cover n Thoms Chpter 5 n Yeung Chpter 3. As usul, some of the text n equtions re tken iretly from those

More information

Counting Paths Between Vertices. Isomorphism of Graphs. Isomorphism of Graphs. Isomorphism of Graphs. Isomorphism of Graphs. Isomorphism of Graphs

Counting Paths Between Vertices. Isomorphism of Graphs. Isomorphism of Graphs. Isomorphism of Graphs. Isomorphism of Graphs. Isomorphism of Graphs Isomorphism of Grphs Definition The simple grphs G 1 = (V 1, E 1 ) n G = (V, E ) re isomorphi if there is ijetion (n oneto-one n onto funtion) f from V 1 to V with the property tht n re jent in G 1 if

More information

5. (±±) Λ = 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.

5. (±±) Λ = 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 information

Exercises Chapter 1. Exercise 1.1. Let Σ be an alphabet. Prove wv = w + v for all strings w and v.

Exercises Chapter 1. Exercise 1.1. Let Σ be an alphabet. Prove wv = w + v for all strings w and v. 1 Exercises Chpter 1 Exercise 1.1. Let Σ e n lphet. Prove wv = w + v for ll strings w nd v. Prove # (wv) = # (w)+# (v) for every symol Σ nd every string w,v Σ. Exercise 1.2. Let w 1,w 2,...,w k e k strings,

More information

CSCI 340: Computational Models. Kleene s Theorem. Department of Computer Science

CSCI 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 information

First Midterm Examination

First 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 information

2.4 Theoretical Foundations

2.4 Theoretical Foundations 2 Progrmming Lnguge Syntx 2.4 Theoretil Fountions As note in the min text, snners n prsers re se on the finite utomt n pushown utomt tht form the ottom two levels of the Chomsky lnguge hierrhy. At eh level

More information

Tutorial Worksheet. 1. Find all solutions to the linear system by following the given steps. x + 2y + 3z = 2 2x + 3y + z = 4.

Tutorial Worksheet. 1. Find all solutions to the linear system by following the given steps. x + 2y + 3z = 2 2x + 3y + z = 4. Mth 5 Tutoril Week 1 - Jnury 1 1 Nme Setion Tutoril Worksheet 1. Find ll solutions to the liner system by following the given steps x + y + z = x + y + z = 4. y + z = Step 1. Write down the rgumented mtrix

More information

CS 373, Spring Solutions to Mock midterm 1 (Based on first midterm in CS 273, Fall 2008.)

CS 373, Spring Solutions to Mock midterm 1 (Based on first midterm in CS 273, Fall 2008.) CS 373, Spring 29. Solutions to Mock midterm (sed on first midterm in CS 273, Fll 28.) Prolem : Short nswer (8 points) The nswers to these prolems should e short nd not complicted. () If n NF M ccepts

More information

Chapter 3. Vector Spaces. 3.1 Images and Image Arithmetic

Chapter 3. Vector Spaces. 3.1 Images and Image Arithmetic Chpter 3 Vetor Spes In Chpter 2, we sw tht the set of imges possessed numer of onvenient properties. It turns out tht ny set tht possesses similr onvenient properties n e nlyzed in similr wy. In liner

More information

1 From NFA to regular expression

1 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 information

1.4 Nonregular Languages

1.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 information

Non Deterministic Automata. Linz: Nondeterministic Finite Accepters, page 51

Non Deterministic Automata. Linz: Nondeterministic Finite Accepters, page 51 Non Deterministic Automt Linz: Nondeterministic Finite Accepters, pge 51 1 Nondeterministic Finite Accepter (NFA) Alphbet ={} q 1 q2 q 0 q 3 2 Nondeterministic Finite Accepter (NFA) Alphbet ={} Two choices

More information

Chapter Five: Nondeterministic Finite Automata. Formal Language, chapter 5, slide 1

Chapter 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 information

Running an NFA & the subset algorithm (NFA->DFA) CS 350 Fall 2018 gilray.org/classes/fall2018/cs350/

Running an NFA & the subset algorithm (NFA->DFA) CS 350 Fall 2018 gilray.org/classes/fall2018/cs350/ Running n NFA & the suset lgorithm (NFA->DFA) CS 350 Fll 2018 gilry.org/lsses/fll2018/s350/ 1 NFAs operte y simultneously exploring ll pths nd epting if ny pth termintes t n ept stte.!2 Try n exmple: L

More information

CS 275 Automata and Formal Language Theory

CS 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 information

CS 311 Homework 3 due 16:30, Thursday, 14 th October 2010

CS 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 information

First Midterm Examination

First 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 information

Harvard University Computer Science 121 Midterm October 23, 2012

Harvard 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 information

1 Nondeterministic Finite Automata

1 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 information

Introduction to Olympiad Inequalities

Introduction to Olympiad Inequalities Introdution to Olympid Inequlities Edutionl Studies Progrm HSSP Msshusetts Institute of Tehnology Snj Simonovikj Spring 207 Contents Wrm up nd Am-Gm inequlity 2. Elementry inequlities......................

More information

Formal Languages and Automata

Formal Languages and Automata Moile Computing nd Softwre Engineering p. 1/5 Forml Lnguges nd Automt Chpter 2 Finite Automt Chun-Ming Liu cmliu@csie.ntut.edu.tw Deprtment of Computer Science nd Informtion Engineering Ntionl Tipei University

More information

System Validation (IN4387) November 2, 2012, 14:00-17:00

System Validation (IN4387) November 2, 2012, 14:00-17:00 System Vlidtion (IN4387) Novemer 2, 2012, 14:00-17:00 Importnt Notes. The exmintion omprises 5 question in 4 pges. Give omplete explntion nd do not onfine yourself to giving the finl nswer. Good luk! Exerise

More information

Discrete Structures, Test 2 Monday, March 28, 2016 SOLUTIONS, VERSION α

Discrete Structures, Test 2 Monday, March 28, 2016 SOLUTIONS, VERSION α Disrete Strutures, Test 2 Mondy, Mrh 28, 2016 SOLUTIONS, VERSION α α 1. (18 pts) Short nswer. Put your nswer in the ox. No prtil redit. () Consider the reltion R on {,,, d with mtrix digrph of R.. Drw

More information

Unit 4. Combinational Circuits

Unit 4. Combinational Circuits Unit 4. Comintionl Ciruits Digitl Eletroni Ciruits (Ciruitos Eletrónios Digitles) E.T.S.I. Informáti Universidd de Sevill 5/10/2012 Jorge Jun 2010, 2011, 2012 You re free to opy, distriute

More information

Kleene s Theorem. Kleene s Theorem. Kleene s Theorem. Kleene s Theorem. Kleene s Theorem. Kleene s Theorem 2/16/15

Kleene s Theorem. Kleene s Theorem. Kleene s Theorem. Kleene s Theorem. Kleene s Theorem. Kleene s Theorem 2/16/15 Models of Comput:on Lecture #8 Chpter 7 con:nued Any lnguge tht e defined y regulr expression, finite utomton, or trnsi:on grph cn e defined y ll three methods We prove this y showing tht ny lnguge defined

More information

CS 330 Formal Methods and Models Dana Richards, George Mason University, Spring 2016 Quiz Solutions

CS 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 information

Arrow s Impossibility Theorem

Arrow s Impossibility Theorem Rep Voting Prdoxes Properties Arrow s Theorem Arrow s Impossiility Theorem Leture 12 Arrow s Impossiility Theorem Leture 12, Slide 1 Rep Voting Prdoxes Properties Arrow s Theorem Leture Overview 1 Rep

More information

22: Union Find. CS 473u - Algorithms - Spring April 14, We want to maintain a collection of sets, under the operations of:

22: Union Find. CS 473u - Algorithms - Spring April 14, We want to maintain a collection of sets, under the operations of: 22: Union Fin CS 473u - Algorithms - Spring 2005 April 14, 2005 1 Union-Fin We wnt to mintin olletion of sets, uner the opertions of: 1. MkeSet(x) - rete set tht ontins the single element x. 2. Fin(x)

More information

Arrow s Impossibility Theorem

Arrow s Impossibility Theorem Rep Fun Gme Properties Arrow s Theorem Arrow s Impossiility Theorem Leture 12 Arrow s Impossiility Theorem Leture 12, Slide 1 Rep Fun Gme Properties Arrow s Theorem Leture Overview 1 Rep 2 Fun Gme 3 Properties

More information

CS 310 (sec 20) - Winter Final Exam (solutions) SOLUTIONS

CS 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 information

Compiler Design. Fall Lexical Analysis. Sample Exercises and Solutions. Prof. Pedro C. Diniz

Compiler Design. Fall Lexical Analysis. Sample Exercises and Solutions. Prof. Pedro C. Diniz University of Southern Cliforni Computer Science Deprtment Compiler Design Fll Lexicl Anlysis Smple Exercises nd Solutions Prof. Pedro C. Diniz USC / Informtion Sciences Institute 4676 Admirlty Wy, Suite

More information

Homework 3 Solutions

Homework 3 Solutions CS 341: Foundtions of Computer Science II Prof. Mrvin Nkym Homework 3 Solutions 1. Give NFAs with the specified numer of sttes recognizing ech of the following lnguges. In ll cses, the lphet is Σ = {,1}.

More information

Name Ima Sample ASU ID

Name 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 information

Alpha Algorithm: Limitations

Alpha Algorithm: Limitations Proess Mining: Dt Siene in Ation Alph Algorithm: Limittions prof.dr.ir. Wil vn der Alst www.proessmining.org Let L e n event log over T. α(l) is defined s follows. 1. T L = { t T σ L t σ}, 2. T I = { t

More information

CS 275 Automata and Formal Language Theory

CS 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 information

Coalgebra, Lecture 15: Equations for Deterministic Automata

Coalgebra, 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 information

Lecture 08: Feb. 08, 2019

Lecture 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 information

CSE 401 Compilers. Today s Agenda

CSE 401 Compilers. Today s Agenda CSE 401 Compilers Leture 3: Regulr Expressions & Snning, on?nued Mihel Ringenurg Tody s Agend Lst?me we reviewed lnguges nd grmmrs, nd riefly strted disussing regulr expressions. Tody I ll restrt the regulr

More information

For 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

For 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 information

PART 2. REGULAR LANGUAGES, GRAMMARS AND AUTOMATA

PART 2. REGULAR LANGUAGES, GRAMMARS AND AUTOMATA PART 2. REGULAR LANGUAGES, GRAMMARS AND AUTOMATA RIGHT LINEAR LANGUAGES. Right Liner Grmmr: Rules of the form: A α B, A α A,B V N, α V T + Left Liner Grmmr: Rules of the form: A Bα, A α A,B V N, α V T

More information

Exercise 3 Logic Control

Exercise 3 Logic Control Exerise 3 Logi Control OBJECTIVE The ojetive of this exerise is giving n introdution to pplition of Logi Control System (LCS). Tody, LCS is implemented through Progrmmle Logi Controller (PLC) whih is lled

More information