Compiler Design. Fall Lexical Analysis. Sample Exercises and Solutions. Prof. Pedro C. Diniz
|
|
- Darrell Walker
- 5 years ago
- Views:
Transcription
1 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 Mrin del Rey, Cliforni 99 pedro@isi.edu Lexicl Anlysis Smple Exercises Fll
2 University of Southern Cliforni Computer Science Deprtment Prolem : Considering the lphet Σ = {,} derive Non-Deterministic-Finite Automton (NFA) using the Thompson construction tht is le to recognize the sentences generted y the regulr expression *( )*. Does the sentence w = elong to the lnguge generted y this regulr expression? Justify. Solution: Considering simplifction of the comintion of the NFA during the Thompson construction (e.g., sequence of two -trnsitions cn e considered s single -trnsition) possile NFA is s shown elow nd where the strt stte is the stte leled The word w = elongs to the lnguge generted y this RE ecuse there is pth from the strt stte to the ccepting stte tht spells out the word, respectively the pth,,4,6,8,,,,,,. Prolem : Strting from the NFA you derived in prolem, convert it to DFA using the su-set construction descried in clss. Verify tht the DFA yields the sme output s the originl NFA for the sme input string w. Solution: Using the -closure nd DFAedge computtion s descried in clss, we hve the following mpping of set of sttes of the NFA to sets of sttes of the DFA: I = -closure () = {,,, 4, } I = DFAedge(I,) = -closure ({,,, 4, }, ) = {6} I = DFAedge(I,) = -closure ({,,, 4, }, ) = {,,, 4,, 7} I = DFAedge(I,) = -closure ({6}, ) = Ierr I4 = DFAedge(I,) = -closure ({6}, ) = {8,,, } I = DFAedge(I,) = -closure ({,,, 4,, 7}, ) = {6, 9,,, } I6 = DFAedge(I,) = -closure ({,,, 4,, 7}, ) = {,,, 4,, 7} = I I7 = DFAedge(I4,) = -closure ({8,,, }, ) = Ierr I8 = DFAedge(I4,) = -closure ({8,,, }, ) = {,, } I9 = DFAedge(I,) = -closure ({6, 9,,, }, ) = Ierr I = DFAedge(I,) = -closure ({6, 9,,, }, ) = {8,,,, } I = DFAedge(I8,) = -closure ({,, }, ) = Ierr I = DFAedge(I8,) = -closure ({,, }, ) = {,, } = I8 I = DFAedge(I,) = -closure ({8,,,, }, ) = Ierr I4 = DFAedge(I,) = -closure ({8,,,, }, ) = I8 Effectively there re only 8 sttes s shown in the DFA elow nd this is clerly not the miniml DFA tht cn recognize this regulr expression. Lexicl Anlysis Smple Exercises Fll
3 University of Southern Cliforni Computer Science Deprtment, Ierr I I I4 I8 I I I For the input sentence w = in his DFA we would rech the stte I8, through sttes I, I4 nd I8 nd thus ccepting this string. Prolem : Strting from the DFA you constructed in the previous prolem, convert it to miniml DFA using the minimiztion lgorithm descried in clss. Verify tht the DFA yields the sme output s the originl NFA for the sme input string w. Solution: The first prtition would hve the two sets of sttes P = {I, I, I, Ierr} nd = {I4, I, I8, I}. A second prtition would mintin nd prtition P into {I, I, Ierr} nd generte P = {I} since I goes to itself on nd to on. Next the lgorithm would generte = {I) nd next generte P = {Ierr} leving P = {I}. The finl DFA would hve therefore sttes hs shown elow., P P P Agin on the input string w = the DFA would trverse P,, nd loop in therefore ccepting the string. Importnt Note: If you try to pply the sme construction, i.e. prtitioning the set of sttes strting with n incomplete DFA where the trp stte is missing you might e surprised to find tht you rech t n incorrect miniml DFA. Lexicl Anlysis Smple Exercises Fll
4 University of Southern Cliforni Computer Science Deprtment Prolem 4: Considering the lphet Σ = {,} construct Non-Deterministic-Finite Automton (NFA) using the Thompson construction tht is le to recognize the sentences generted y the regulr expression (**)**. Does the sentence w = elong to the lnguge generted y this regulr expression? Justify. Solution: The NFA is s shown elow nd where the strt stte is stte leled S = -closure () = {,,, 4,,, } this is finl stte ecuse of = DFAedge(S,) = -closure (S, ) = {, 6, 8} S = DFAedge(S,) = -closure (S, ) = {,, 4,,, } finl stte DFAedge(S,) = -closure (S, ) = {, 6, 8} = DFAedge(S,) = -closure (S, ) = {,, 4,,, } = S S = DFAedge(,) = -closure (, ) = {,, 4, 9,,, } finl stte S4 = DFAedge(,) = -closure (, ) = {6, 7, 8} DFAedge(S4,) = -closure (S4, ) = {,, 4, 9,,, } = S DFAedge(S4,) = -closure (S4, ) = {6, 7, 8} = S4 DFAedge(S,) = -closure (S, ) = {, 6, 8} = DFAedge(S,) = -closure (S, ) = {,, 4,,, } = S This results in the DFA shown elow with strting stte S. S S S S S4 4 This DFA cn e further minimize y recognizing tht S, S nd S form self-contined prtition nd nd S4 nother prtition resulting in the DFA on the right-hnd-side. Lexicl Anlysis Smple Exercises 4 Fll
5 University of Southern Cliforni Computer Science Deprtment Prolem : Consider the lphet Σ = {,}.. Construct Non-Deterministic-Finite Automton (NFA) using the Thompson construction tht is le to recognize the sentences generted y the regulr expression RE = ()*.()*.. Do the sentences w = nd w = elong to the lnguge generted y this regulr expression? Justify. c. Convert the NFA in prt ) to DFA using the suset construction. Show the mpping etween the sttes in the NFA nd the resulting DFA. d. Minimize the DFA using the itertive refinement lgorithm discussed in clss. Show your intermedite prtition results nd doule check the DFA using the sentences w nd w. Solution: ) A possile construction (lredy simplified to hve only single -trnsition etween sttes) would result in the NFA shown elow nd where the strt stte is leled. 4 6 ) Both words re recognized y this NFA. Regrding the word there is pth from stte to the ccepting stte 6, nmely:,,,,4,,4,,6. Regrding the word the utomton my rech stte 6 following the pth,,,4,,4,,4,,6. c) Using the suset construction we rrive t the following susets nd trnsitions. S = -closure () = {,,, 4,, 6} this is finl stte ecuse of stte 6 S = DFAedge(S,) = -closure (goto(s, )) = {, 4,, 6} finl stte SE = DFAedge(S,) = -closure (goto(s, )) = { } = DFAedge(S,) = -closure (goto(s, )) = {4,, 6} finl stte S = DFAedge(S,) = -closure (goto(s, )) = {, 4,, 6} finl stte DFAedge(,) = -closure (goto(, )) = {4,, 6} = DFAedge(,) = -closure (goto(, )) = { } = SE DFAedge(S,) = -closure (goto(s, )) = {, 4,, 6} = S DFAedge(S,) = -closure (goto(s, )) = { } = SE This results in the DFA shown elow with strting stte S. S SE S S, d) This DFA cn e further minimize y using the itertive refinement prtitioning yeilding the sequence of prtitions indicted elow. Lexicl Anlysis Smple Exercises Fll
6 University of Southern Cliforni Computer Science Deprtment S SE S S S P SE S S P, P, Initil prtitioning on finl sttes Prtitioning on S P SE S S S SE S P,, Prtitioning on finl miniml DFA Lexicl Anlysis Smple Exercises 6 Fll
7 University of Southern Cliforni Computer Science Deprtment Prolem 6: Minimize the FA shown elow over the lphet {,}. Mke sure to convert it first into DFA nd them pply the itertive refinement lgorithm discussed in clss. strt 4 Solution: The first oservtion is tht there re some sttes for which one of the trnsitions on the lphet symols is missing. This is the cse with sttes "" nd "". As such s need to ugment this FA with "trp-stte" tht is non-ccepting s shown elow in ). The reminder DFA result from the ppliction of the itertive prtitioning lgorithm descried in clss. strt strt P 4, 4 P, ) Augmented DFA strt ) Prtion sed on ccepting nd non-ccepting sttes strt P P 4 P, 4 P, P c) Prtion sed on '' trnsistions d) Prtion sed on '' trnsistions strt strt P 4 P e) Prtion sed on '' trnsistions P, f) Minimized DFA, Lexicl Anlysis Smple Exercises 7 Fll
8 University of Southern Cliforni Computer Science Deprtment Prolem 7: Consider the DFA elow with strting stte nd ccepting stte :, 4, ) Using the Kleene construction lgorithm derive regulr expression. ) Symplify the expression found in ) ove. Solution: Before engging in very long sequence of conctention nd symolic opertions we mke the oservtion tht stte 4 is trp-stte. As such we cn sfely ignore it since it is not n ccepting stte. Wht this mens is tht we cn use the lgorithm simply with k = nd need to use it to compute R s there re pths from the strt stte to the finl stte vi stte. Expressions for k = R = () R = ( ) R = () R = () R = ( ) Expressions for k = R = R (R )*R R = () R = R (R )*R R = ( ) R = R (R )*R R = () R = R (R )*R R = () R = R (R )*R R = ( ) Expressions for k = R = R (R )*R R = R = () R = R (R )*R R = ( ) ( )* ( ) ( ) = ( ) * R = R (R )*R R = ( ) ( )* () () = *() R = R (R )*R R = () ( )* ( ) () = () * R = R (R )*R R = ( ) ( )* ( ) ( ) = * R = R (R )*R R = ( ) ( )* () = ( ) * () R = R (R )*R R = () ( )* () = () *() Expressions for k = R = R (R )*R R = R = () R = R (R )*R R = ( ) * () (() *())* () * ( )* R = R (R )*R R = *() (() *())* () *() * () R = R (R )*R R = () *() (() *())* () * () * R = R (R )*R R = *() (() *())* () * * R = R (R )*R R = ( ) * () (() *())* () *() ( ) * () R = R (R )*R R = () *() (() *())* () *() () *() Lexicl Anlysis Smple Exercises 8 Fll
9 University of Southern Cliforni Computer Science Deprtment Clerly these expressions hve lot of redundnt terms. In fct we re only interested in R = ( ) * () (() *())* () * ( )* since the strting stte is stte nd the only ccepting stte is stte. ) To simplify the expression found ove is very hrd, s there re lot of prtil terms in this expression. Insted you follow the edges in the DFA nd try to compose the regulr expressions (in some sense ignoring wht you hve done in the previous step). The simplest wy to look t this prolem is to see tht there is prefix ( ) nd then you return to stte either y (*) or (), so compct regulr expressions would e R = ( )(() ())* much more compct regulr expressions tht R ove. Prolem 8: Consider the lphet Σ = {; }. Define short, possily the shortest, regulr expression tht genertes strings over Σ tht contin exctly one nd t lest one. Solution: The string must either strt with one or n, so we cn use * preffix to ccount for ny possile numer of leding s efore the first. The single must hve t lest one either preceeding it or just efore it. After this single there cn e ny numer of triling s. As possile (lthough not necessrily unique) regulr expression denoting the sought lnguge is R = *( )*. Prolem 9: Given n NFA with -trnsitions how do you derive n equivlent NFA without those - trnsitions? Justify. Solution: For those sttes with -trnsitions merge the edges of the sttes t the end of those trnsitions into the current stte. Iterte until there re no -trnsitions left. You still hve NFA ut there will e t more multiple edges with the lel lel out of given stte. Prolem : Given n NFA with severl ccept sttes, show how to convert it onto NFA with exctly one strt stte nd one ccepting stte. Solution: The initl stte is the sme s in the originl NFA. As to the ccepting sttes just dd - trnsitions from the orignl ccepting sttes to new ccepting stte nd lel tht ccepting stte s the only ccepting stte of the new NFA. Lexicl Anlysis Smple Exercises 9 Fll
10 University of Southern Cliforni Computer Science Deprtment Prolem : Given the Finite Automton elow with initil stte nd lphet {,} nswer the following questions: 4, () Why is this FA Non-Deterministic Finite Automton (NFA)? () Convert this NFA to DFA using the closure computtion. (c) Minimize the resulting DFA. (d) Wht is the Regulr Expression mtched y this NFA? You re dvised not to use the utomtic Kleene construction or try to look t the input NFA ut rther the correctly minimized DFA. Solution: () This FA is lredy DFA, s the only trnsitions tht re missing ll go to the trp stte. () The suset construction, which in this cse yields the sme originl DFA on the left where we hve noted the suset ech stte stnds for. {} {} {} {4} {},, (c) Using the itertive prtition refinement we hve the following prtitions (elow left) nd the resulting minimized DFA on the right gin with the sttes releled. Notice tht this is specil cse where the refinement lgorithm cnnot refine ny su-sets of sttes given tht the originl DFA ws lredy miniml. {} P {} {} P {4} {} P,, (d) Bsed on the lst DFA the regulr expression identified y this FA must hve exctly two consecutive symol possily preceded y single symol. For instnce, the string is in the lnguge ut the string or re not. The regulr expression cn e denoted y *. Lexicl Anlysis Smple Exercises Fll
11 University of Southern Cliforni Computer Science Deprtment Prolem : Drw the smllest DFA tht ccepts the lnguge derived y the regulr expression (** **). Solution: A possile trnsltion guided y the ide of the Thompson construction is shown elow. 6, 4 Using the itertive refinements lgorithm for DFA minimiztion indeed confirms tht this is the smllest possile DFA. The sequence of refinements is shown elow., 4 6, 4 6 4, 6, 4 6 4, 6 4, 6 Prolem : Given the regulr expression RE = ( *)*(*) over the lphet Σ = {,} do the following trnsformtions:. Derive NFA using the Thompson construction cple of identifying the strings generted y this regulr expression.. Convert the NFA otined in ) to DFA. c. Minimize the resulting DFA using the itertive refinement lgorithm discussed in clss. d. Determine in how mny steps is the sequence processed. Justify. Solution: Regrding ) the NFA is given elow. Here we mde some very simple simplifiction tht two or more sequences of -trnsitions cn e converted to single -trnsitions. This sustntilly reduces the numer of sttes in the NFA nd thius fcilittes the construction of the equivlent DFA. Lexicl Anlysis Smple Exercises Fll
12 University of Southern Cliforni Computer Science Deprtment Applying the suset construction we hve the following sttes S = -closure () = {,, 4, 7, 8,,,,, 4, } this is finl stte ecuse of S = DFAedge(S,) = -closure (goto(s, )) = {} = DFAedge(S,) = -closure (goto(s, )) = {,,, 4, 7, 8, 9,,, 4, } finl S = DFAedge(S,) = -closure (goto(s, )) = {} S4 = DFAedge(S,) = -closure (goto(s, )) = {,,, 4, 6, 7, 8,,, 4, } finl S = DFAedge(,) = -closure (goto(, )) = {} = S S6 = DFAedge(,) = -closure (goto(, )) = {,,, 4, 7, 8, 9,,,, 4, } finl S7 = DFAedge(S,) = -closure (goto(s, )) = {} = S S8 = DFAedge(S,) = -closure (goto(s, )) = {} = S S9 = DFAedge(S4,) = -closure (goto(s4, )) = {} = S S = DFAedge(S4,) = -closure (goto(s4, )) = {,,, 4,, 7, 8, 8,,,, 4, } = S6 S = DFAedge(S6,) = -closure (goto(s6, )) = {,,, 4, } finl = DFAedge(S6,) = -closure (goto(s6, )) = {,,, 4, 7, 8, 9,,, 4, } = S = DFAedge(S,) = -closure (goto(s, )) = {} = S S4 = DFAedge(S,) = -closure (goto(s, )) = {,,, 4, 6, 7, 8,,, 4, }= S4 So there re totl of 7 sttes, S, S,, S, S4, S6, S nd the corresponding DFA is s shown y the tle elow (old sttes re finl sttes) nd then in the figure elow the tle. Next Stte Current Stte S S S S S4 S S6 S S S S4 S S6 S6 S S S S4, 4 6 Lexicl Anlysis Smple Exercises Fll
13 University of Southern Cliforni Computer Science Deprtment, P 4 6 initil refinement on cceptnce criteri 6, 4 refinement of on P P, 4 6 P refinement of on P, P 4 6 refinement of P on P P P6 P P, 4 6 refinement of on P P6 P P, 4 6 finl refinement with 6 sttes P Prolem 4: Given the DFA elow descrie in English the set of strings ccepted y it., Solution: Any string over the lphet tht contins ny numer of consecutive s, including none with preffix of zero or more consecutive s. Lexicl Anlysis Smple Exercises Fll
14 University of Southern Cliforni Computer Science Deprtment Prolem : Given regulr lnguge L. i.e., lnguge descried y regulr expression, prove tht the reverse of L is lso regulr lnguge (Note: the reverse of lnguge L is L R where for ech word w in L, w R is in L R. Given word w over the given lphet, w R is constructed y spelling w ckwrds). Solution: If L is regulr lnguge then there exists DFA M tht recognizes it. Now given M we cn construct M tht recognizes the reverse of L with respect to the input lphet. We now descrie how to construct M. M is replic of M ut reversing ll the edges. The finl stte of M is the stte tht used to e the strt stte of M. The strt stte of M is new stte with -trnsitions to the sttes in M tht used to e the finl sttes of M. Now ecuse M might hve multiple finl sttes M is y construction NFA. Given the equivlence of NFA nd regulr expressions we hve shown tht if L is regulr so is L R. Prolem 6: Drw the DFA cple of recognizing the set of ll strings eginning with which interpreted s the inry representtion of n integer (ssuming the lst digit to e processed is the lest significnt) is congruent to zero modulo i.e., the numeric vlue of this inry representtion is multiple of. Solution: The hrd prt out this prolem is tht you need to keep trck with the lredy oserved its wht the reminder of the division y is. Given tht you hve reminder you would need no more tht sttes, one for ech of the reminder vlues through eing the stte tht represents reminder of zero the ccepting stte, in this cse stte S. The DFA elow ccomplishes this. You cn verify this DFA y trying the numer in inry or in inry. Notice tht in the lst stte S ny dditionl mens you re shifting the its y one it, i.e., multiplying y, hence stying in the sme stte. S S S Prolem 7: Consider the lphet Σ = {,}.. Consider the Non-Deterministic Finite Automton (NFA) depicted elow. Why is this utomton non-deterministic? Explin the vrious source on indetermincy.. Do the sentences w = nd w = elong to the lnguge recognized y this FA? Justify. c. Convert the NFA in prt ) to DFA using the suset construction. Show the mpping etween the sttes in the NFA nd the resulting DFA. d. Minimize the DFA using the itertive refinement lgorithm descried in clss. Show your intermedite prtition results nd doule check the DFA using the sentences w nd w. Lexicl Anlysis Smple Exercises 4 Fll
15 University of Southern Cliforni Computer Science Deprtment 4 6 strt Solution: ) This is indeed NFA for two resons. First, it includes -trnsitions. Second, in stte there re two trnsistions on the sme terminl or lphet symol, "". ) Regrding the word there is pth from stte to the ccepting stte 6, nmely:,4,,6. Regrding the word the utomton will never e le to rech the stte 6 s in order to spell out the chrcter will necessrily e in stte nd to rech tht stte we cnnot hve two consecutive "" chrcters we we would e either in stte or stte 4. c) Using the suset construction we rrive t the following susets nd trnsitions. S = -closure ({}) = {,, 4} this is not finl stte. = DFAedge(S,) = -closure (goto(s, )) = {,,, 6} finl stte S = DFAedge(S,) = -closure (goto(s, )) = {} S9 = DFAedge(,) = -closure (goto(, )) = {,, 6} finl stte S4 = DFAedge(,) = -closure (goto(, )) = {,, 6} finl stte. S = DFAedge(S,) = -closure (goto(s, )) = {,, 6} finl stte. DFAedge(S,) = -closure (goto(s, )) = {} = S DFAedge(S4,) = -closure (goto(s4, )) = {,, 6} = S finl stte. DFAedge(S4,) = -closure (goto(s4, )) = {,, 6} = S4 finl stte. S6 = DFAedge(S,) = -closure (goto(s, )) = {, 6} finl stte. S7 = DFAedge(S,) = -closure (goto(s, )) = {, 6} finl stte. DFAedge(S6,) = -closure (goto(s6, )) = {, 6} = S6 finl stte. S8 = DFAedge(S6,) = -closure (goto(s6, )) = { } DFAedge(S7,) = -closure (goto(s7, )) = { } = S8 DFAedge(S7,) = -closure (goto(s7, )) = {, 6} = S7 finl stte. DFAedge(S8,) = -closure (goto(s8, )) = { } = S8 DFAedge(S8,) = -closure (goto(s8, )) = { } = S8 DFAedge(S9,) = -closure (goto(s9, )) = {,, 6} = S9 DFAedge(S9,) = -closure (goto(s9, )) = {} = S This results in the DFA shown elow with strting stte S. strt S S9 S S4 S S7 S6 S8, Lexicl Anlysis Smple Exercises Fll
16 University of Southern Cliforni Computer Science Deprtment d) We cn try to minimize this DFA using the itertive refinement lgorithm descried in clss. The figure elow depicts possile sequence of refinements. For ech step we indicte the criteri used to discriminte etween sttes in the previous prtition. As cn e seen, the lgorithm leds to no refinement, so this is prticulr cse where the su-set lgorithm tht help us derive the DFA from its originl NFA does yield miniml DFA. P P P P strt S S S9 S4 S S7 S6 S8, strt S S9 S S4 S S7 S6, S8 strt S S S4 S9 S S7 S6, S8 P P P () Prtition etween ccepting nd non-ccepting sttes () Discrimintion sed on "" trnsitions (c) Discrimintion sed on "" trnsitions strt P S P S P9 S9 S4 S S7 S6 P P S8, strt P S P S S P6 S4 P9 S9 S7 S6 P P S8, strt P S P7 P S S P6 S4 P9 S9 S7 S6 P P S8, (d) Discrimintion sed on "" trnsitions (e) Discrimintion sed on "" trnsitions (f) Discriminion sed on "" trnsitions Lexicl Anlysis Smple Exercises 6 Fll
17 University of Southern Cliforni Computer Science Deprtment Prolem 8: Consider the DFA elow with strting stte nd ccepting stte : strt ) Descrie in English the set of strings ccepted y this DFA. ) Using the Kleene construction lgorithm derive the regulr expression recognized y this utomton symplifying it s much s possile. Solution: ) This utomton recognizes ll non-null strings over the {,} lphet tht end with "". ) The derivtions re shown elow with the ovious symplifiction. Expressions for k = R = ( ) R = () R = () R = ( ) Expressions for k = R = R (R )*R R = ( ). ( )*. ( ) ( ) = * R = R (R )*R R = ( ). ( )*. () () = * * R = R (R )*R R = (). ( )*. ( ) () = + + R = R (R )*R R = (). ( )*. ( ) ( ) = (* ) Expressions for k = R = R (R )*R R = ( * * ). (* )*. ( + + ) ( * ) R = R (R )*R R = ( * * ). (* )*. ( + + ) ( * * ) R = R (R )*R R = ( * * ). (* )*. ( + + ) ( + + ) R = R (R )*R R = ( * * ). (* )*. ( + + ) (* ) L = R = ( * * ). (* )*. ( + + ) ( * * ) As cn e seen the simplifiction of ny of these regulr expressions eyond the expresions for k= is firly complicted. This method, lthough correct y design leds to regulr expressions tht re fr from eing miniml or even the most compct representtion of the regulr lnguge the DFA recognizes. Lexicl Anlysis Smple Exercises 7 Fll
18 University of Southern Cliforni Computer Science Deprtment Prolem 9: For the regulr expression depicted elow nswer the following questions: RE = ( - +)?. (e E). (-9)+ ) Using the Thompson construction (or simplifiction thereof) derive NFA tht recognizes the strings specified y this RE. ) Convert the NFA in ) to n equivlent DFA using the suset construction. c) Mke sure the DFA M found in ) ove is miniml (you do not need to show tht it is in fct miniml) nd construct the DFA M tht ccepts the complement of the regulr lnguge the first DFA ccepts. Show tht M does ccept the word w = "e" which is not ccepted y the originl DFA. Solution: ) The figure elow depicts the NFA with -trnsitions nd where we hve simplified the trnsition on numeric digits. 'e' '' strt '-' 4 6 'E' 7 '9' 8 9 '+' ) We use the suset construction y trcing for every set of sttes the other possile sttes the NFA could e in if it were to trverse -edges only. The list elow depicts the results of this construction where we lso descrie the computtion of edge DFA edge using the function DFA_edge nd then computing the e-closure of the resulting intermedite set of sttes. -closure({}) DFA_edge(S,'-') DFA_edge(S,'+') DFA_edge(S,'e') DFA_edge(S,'E') DFA_edge(S,'<digit>') DFA_edge(S,'-') DFA_edge(S,'+') DFA_edge(S,'e') DFA_edge(S,'E') DFA_edge(S,'<digit>') = {,,,, 4} = S = -closure({}) = {,, 4} = S = -closure({}) = {,, 4} = S = -closure({}) = {, 6, 7} = = -closure({}) = {, 6, 7} = = -closure( {} ) = SE; error stte = -closure( {} ) = SE; error stte = -closure( {} ) = SE; error stte = -closure({}) = {, 6, 7 } = = -closure({}) = {, 6,7 } = = -closure( {} ) = SE; error stte DFA_edge(,'-') = -closure( {} ) = SE; error stte DFA_edge(,'+') = -closure( {} ) = SE; error stte DFA_edge(,'e') = -closure( {} ) = SE; error stte DFA_edge(,'E') = -closure( {} ) = SE; error stte DFA_edge(,'<digit>') = -closure( {8} ) = { 6, 7, 8, 9, } = S; DFA_edge(S,'-') = -closure( {} ) = SE; error stte DFA_edge(S,'+') = -closure( {} ) = SE; error stte DFA_edge(S,'e') = -closure( {} ) = SE; error stte DFA_edge(S,'E') = -closure( {} ) = SE; error stte DFA_edge(S,'<digit>') = -closure( {8} ) = { 6, 7, 8, 9, } = S; The figure elow depicts the DFA resulting from the ppliction of the suset construction. Notice tht this is fully specified DFA where ech stte includes trnsition for ll the chrcters in the considered lphet. Lexicl Anlysis Smple Exercises 8 Fll
19 University of Southern Cliforni Computer Science Deprtment strt '-' '+' S 'e' 'E' '' '9' S '' '9' '' '9' 'e' 'E' '-' '+' 'e' 'E' '' S 'e' 'E' '-' '+' SE '9' 'e' 'E' '-' '+' '' '9' c) Let M e the DFA found in ). This DGA is in fct miniml. Informl proof: All sttes re required. S is the strt stte. S cptures the fct tht we hve oserved sign.. Stte cptures to fct we need to oserve t lest one digit. All the digits re then cptured y stte. Stte SE is the trp error stte. Let M e this first DFA. We construct M y mking ll ccepting sttes of M non-ccepting sttes nd ll non-ccepting stte s of M s ccepting sttes of M. The stte strt is unchnged. This is DFA s we only chnge the stte of non-ccepting sttes. The strt stte is still singleton nd ll trnsitions re clerly identified in the newly creted DFA s shown elow. '-' '+' S S 'e' 'E' 'e' 'E' '' S '' '9' strt '' '9' '' '9' '' '9' 'e' 'E' '-' '+' 'e' 'E' '-' '+' SE '9' 'e' 'E' '-' '+' In this newly creted DFA the input string w = "e" tkes the DFA to stte SE which is n ccepting stte n this "complement" mchine. Lexicl Anlysis Smple Exercises 9 Fll
20 University of Southern Cliforni Computer Science Deprtment Prolem Consider the lphet Σ = {,, c}.. Consider the Non-Deterministic Finite Automton (NFA) depicted elow. Why is this utomton non-deterministic? Explin the vrious source on indetermincy.. Do the sentences w = nd w = elong to the lnguge generted y this FA? Justify. c. Convert the NFA in prt ) to DFA using the suset construction. Show the mpping etween the sttes in the NFA nd the resulting DFA. d. By inspection cn you derive regulr expression (RE) this NFA detects? c c, c,c 4,, c strt 6, c Solution: ) This FA is non-deterministic s for t lest one of its sttes there re two trnsitions on the sme lel to two distinct sttes. This is the cse with stte where on '' the FA goes to stte nd 6. Similrly, sttes nd exhiit the sme ehvior. ) The sentence w = elongs to the lnguge ccepted y this FA s there is pth through sttes, nd tht speels out this ord nd stte is n ccepting stte. As to the word w = ny word tht egins with '' leds to stte 4 which is trp nd non-ccepting stte. As such w does not elong to the lnguge recognized y this FA. c) A simplified su-set construction is s shown elow: S = -closure ({}) = {} this is not finl stte. DFAedge(S, ) = -closure (goto(s, )) = {,6} = DFAedge(S, ) = -closure (goto(s, )) = {4} DFAedge(S, c) = -closure (goto(s, c)) = {4} DFAedge(, ) = -closure (goto(, )) = {4} = S = S = S DFAedge(, ) = -closure (goto(, )) = {,4} = S4 DFAedge(, c) = -closure (goto(, c)) = {4,} = S DFAedge(S, ) = -closure (goto(s, )) = {4} DFAedge(S, ) = -closure (goto(s, )) = {4} DFAedge(S, c) = -closure (goto(s, c)) = {4} = S = S = S DFAedge(S4, ) = -closure (goto(s4, )) = {4} = S DFAedge(S4, ) = -closure (goto(s4, )) = {4} = S DFAedge(S4, c) = -closure (goto(s4, c)) = {,4} = S4 DFAedge(S, ) = -closure (goto(s, )) = {4} = S DFAedge(S, ) = -closure (goto(s, )) = {4,} = S DFAedge(S, c) = -closure (goto(s, c)) = {4} = S Lexicl Anlysis Smple Exercises Fll
21 University of Southern Cliforni Computer Science Deprtment In this construction we hve simplified the resulting DFA y mking the trnsition etween stte {,6} on '' direclty move to stte 4 which is trp or error stte. A more mechnicl procedure would hve seen the cretion of n dditionl trp stte tht is equivlent to stte 4. c,4,,6 c,c 4,, c strt 4,,c d) By inspection of the two pths from stte to either stte or stte we cn immeditely see tht the lnguge ccepted y this FA cn e descried y the regulr expressions RE = c* c*. Lexicl Anlysis Smple Exercises Fll
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 informationHomework 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 informationAUTOMATA AND LANGUAGES. Definition 1.5: Finite Automaton
25. Finite Automt AUTOMATA AND LANGUAGES A system of computtion tht only hs finite numer of possile sttes cn e modeled using finite utomton A finite utomton is often illustrted s stte digrm d d d. d q
More informationWorked out examples Finite Automata
Worked out exmples Finite Automt Exmple Design Finite Stte Automton which reds inry string nd ccepts only those tht end with. Since we re in the topic of Non Deterministic Finite Automt (NFA), we will
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 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 information1. For each of the following theorems, give a two or three sentence sketch of how the proof goes or why it is not true.
York University CSE 2 Unit 3. DFA Clsses Converting etween DFA, NFA, Regulr Expressions, nd Extended Regulr Expressions Instructor: Jeff Edmonds Don t chet y looking t these nswers premturely.. For ech
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 informationCS415 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 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 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 informationCS 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 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 informationRegular Expressions (RE) Regular Expressions (RE) Regular Expressions (RE) Regular Expressions (RE) Kleene-*
Regulr Expressions (RE) Regulr Expressions (RE) Empty set F A RE denotes the empty set Opertion Nottion Lnguge UNIX Empty string A RE denotes the set {} Alterntion R +r L(r ) L(r ) r r Symol Alterntion
More informationFormal 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 informationCompiler 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 informationCompiler Design. Spring Lexical Analysis. Sample Exercises and Solutions. Prof. Pedro C. Diniz
Compiler Design Spring 2011 Lexical Analysis Sample Exercises and Solutions Prof. Pedro C. Diniz USC / Information Sciences Institute 4676 Admiralty Way, Suite 1001 Marina del Rey, California 90292 pedro@isi.edu
More informationFinite Automata-cont d
Automt Theory nd Forml Lnguges Professor Leslie Lnder Lecture # 6 Finite Automt-cont d The Pumping Lemm WEB SITE: http://ingwe.inghmton.edu/ ~lnder/cs573.html Septemer 18, 2000 Exmple 1 Consider L = {ww
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 informationThe 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 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 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 informationCompiler Design. Spring Lexical Analysis. Sample Exercises and Solutions. Prof. Pedro Diniz
Compiler Design Spring 2010 Lexical Analysis Sample Exercises and Solutions Prof. Pedro Diniz USC / Information Sciences Institute 4676 Admiralty Way, Suite 1001 Marina del Rey, California 90292 pedro@isi.edu
More informationLet's start with an example:
Finite Automt Let's strt with n exmple: Here you see leled circles tht re sttes, nd leled rrows tht re trnsitions. One of the sttes is mrked "strt". One of the sttes hs doule circle; this is terminl stte
More informationFABER 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 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 informationDeterministic Finite Automata
Finite Automt Deterministic Finite Automt H. Geuvers nd J. Rot Institute for Computing nd Informtion Sciences Version: fll 2016 J. Rot Version: fll 2016 Tlen en Automten 1 / 21 Outline Finite Automt Finite
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 informationJava II Finite Automata I
Jv II Finite Automt I Bernd Kiefer Bernd.Kiefer@dfki.de Deutsches Forschungszentrum für künstliche Intelligenz Finite Automt I p.1/13 Processing Regulr Expressions We lredy lerned out Jv s regulr expression
More informationFormal 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 informationLecture 09: Myhill-Nerode Theorem
CS 373: Theory of Computtion Mdhusudn Prthsrthy Lecture 09: Myhill-Nerode Theorem 16 Ferury 2010 In this lecture, we will see tht every lnguge hs unique miniml DFA We will see this fct from two perspectives
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 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 informationCS 301. Lecture 04 Regular Expressions. Stephen Checkoway. January 29, 2018
CS 301 Lecture 04 Regulr Expressions Stephen Checkowy Jnury 29, 2018 1 / 35 Review from lst time NFA N = (Q, Σ, δ, q 0, F ) where δ Q Σ P (Q) mps stte nd n lphet symol (or ) to set of sttes We run n NFA
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 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 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 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 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 informationNFA 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 informationThoery 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 information1. For each of the following theorems, give a two or three sentence sketch of how the proof goes or why it is not true.
York University CSE 2 Unit 3. DFA Clsses Converting etween DFA, NFA, Regulr Expressions, nd Extended Regulr Expressions Instructor: Jeff Edmonds Don t chet y looking t these nswers premturely.. For ech
More informationModel Reduction of Finite State Machines by Contraction
Model Reduction of Finite Stte Mchines y Contrction Alessndro Giu Dip. di Ingegneri Elettric ed Elettronic, Università di Cgliri, Pizz d Armi, 09123 Cgliri, Itly Phone: +39-070-675-5892 Fx: +39-070-675-5900
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 informationTable 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 informationConverting Regular Expressions to Discrete Finite Automata: A Tutorial
Converting Regulr Expressions to Discrete Finite Automt: A Tutoril Dvid Christinsen 2013-01-03 This is tutoril on how to convert regulr expressions to nondeterministic finite utomt (NFA) nd how to convert
More informationCISC 4090 Theory of Computation
9/6/28 Stereotypicl computer CISC 49 Theory of Computtion Finite stte mchines & Regulr lnguges Professor Dniel Leeds dleeds@fordhm.edu JMH 332 Centrl processing unit (CPU) performs ll the instructions
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 informationLexical Analysis Finite Automate
Lexicl Anlysis Finite Automte CMPSC 470 Lecture 04 Topics: Deterministic Finite Automt (DFA) Nondeterministic Finite Automt (NFA) Regulr Expression NFA DFA A. Finite Automt (FA) FA re grph, like trnsition
More informationSome Theory of Computation Exercises Week 1
Some Theory of Computtion Exercises Week 1 Section 1 Deterministic Finite Automt Question 1.3 d d d d u q 1 q 2 q 3 q 4 q 5 d u u u u Question 1.4 Prt c - {w w hs even s nd one or two s} First we sk whether
More informationGNFA GNFA GNFA GNFA GNFA
DFA RE NFA DFA -NFA REX GNFA Definition GNFA A generlize noneterministic finite utomton (GNFA) is grph whose eges re lele y regulr expressions, with unique strt stte with in-egree, n unique finl stte with
More informationState Minimization for DFAs
Stte Minimiztion for DFAs Red K & S 2.7 Do Homework 10. Consider: Stte Minimiztion 4 5 Is this miniml mchine? Step (1): Get rid of unrechle sttes. Stte Minimiztion 6, Stte is unrechle. Step (2): Get rid
More information3 Regular expressions
3 Regulr expressions Given n lphet Σ lnguge is set of words L Σ. So fr we were le to descrie lnguges either y using set theory (i.e. enumertion or comprehension) or y n utomton. In this section we shll
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 informationNFAs continued, Closure Properties of Regular Languages
Algorithms & Models of Computtion CS/ECE 374, Fll 2017 NFAs continued, Closure Properties of Regulr Lnguges Lecture 5 Tuesdy, Septemer 12, 2017 Sriel Hr-Peled (UIUC) CS374 1 Fll 2017 1 / 31 Regulr Lnguges,
More informationCSE : Exam 3-ANSWERS, Spring 2011 Time: 50 minutes
CSE 260-002: Exm 3-ANSWERS, Spring 20 ime: 50 minutes Nme: his exm hs 4 pges nd 0 prolems totling 00 points. his exm is closed ook nd closed notes.. Wrshll s lgorithm for trnsitive closure computtion is
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 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 informationScanner. Specifying patterns. Specifying patterns. Operations on languages. A scanner must recognize the units of syntax Some parts are easy:
Scnner Specifying ptterns source code tokens scnner prser IR A scnner must recognize the units of syntx Some prts re esy: errors mps chrcters into tokens the sic unit of syntx x = x + y; ecomes
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 informationNon-deterministic Finite Automata
Non-deterministic Finite Automt From Regulr Expressions to NFA- Eliminting non-determinism Rdoud University Nijmegen Non-deterministic Finite Automt H. Geuvers nd J. Rot Institute for Computing nd Informtion
More informationFundamentals of Computer Science
Fundmentls of Computer Science Chpter 3: NFA nd DFA equivlence Regulr expressions Henrik Björklund Umeå University Jnury 23, 2014 NFA nd DFA equivlence As we shll see, it turns out tht NFA nd DFA re equivlent,
More informationCSCI 340: Computational Models. Transition Graphs. Department of Computer Science
CSCI 340: Computtionl Models Trnsition Grphs Chpter 6 Deprtment of Computer Science Relxing Restrints on Inputs We cn uild n FA tht ccepts only the word! 5 sttes ecuse n FA cn only process one letter t
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 informationHomework 4. 0 ε 0. (00) ε 0 ε 0 (00) (11) CS 341: Foundations of Computer Science II Prof. Marvin Nakayama
CS 341: Foundtions of Computer Science II Prof. Mrvin Nkym Homework 4 1. UsetheproceduredescriedinLemm1.55toconverttheregulrexpression(((00) (11)) 01) into n NFA. Answer: 0 0 1 1 00 0 0 11 1 1 01 0 1 (00)
More informationAnatomy of a Deterministic Finite Automaton. Deterministic Finite Automata. A machine so simple that you can understand it in less than one minute
Victor Admchik Dnny Sletor Gret Theoreticl Ides In Computer Science CS 5-25 Spring 2 Lecture 2 Mr 3, 2 Crnegie Mellon University Deterministic Finite Automt Finite Automt A mchine so simple tht you cn
More informationSpeech Recognition Lecture 2: Finite Automata and Finite-State Transducers
Speech Recognition Lecture 2: Finite Automt nd Finite-Stte Trnsducers Eugene Weinstein Google, NYU Cournt Institute eugenew@cs.nyu.edu Slide Credit: Mehryr Mohri Preliminries Finite lphet, empty string.
More informationTalen en Automaten Test 1, Mon 7 th Dec, h45 17h30
Tlen en Automten Test 1, Mon 7 th Dec, 2015 15h45 17h30 This test consists of four exercises over 5 pges. Explin your pproch, nd write your nswer to ech exercise on seprte pge. You cn score mximum of 100
More informationPART 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 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 informationNon-deterministic Finite Automata
Non-deterministic Finite Automt Eliminting non-determinism Rdoud University Nijmegen Non-deterministic Finite Automt H. Geuvers nd T. vn Lrhoven Institute for Computing nd Informtion Sciences Intelligent
More informationLexical Analysis Part III
Lexicl Anlysis Prt III Chpter 3: Finite Automt Slides dpted from : Roert vn Engelen, Florid Stte University Alex Aiken, Stnford University Design of Lexicl Anlyzer Genertor Trnslte regulr expressions to
More informationNON-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 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 information80 CHAPTER 2. DFA S, NFA S, REGULAR LANGUAGES. 2.6 Finite State Automata With Output: Transducers
80 CHAPTER 2. DFA S, NFA S, REGULAR LANGUAGES 2.6 Finite Stte Automt With Output: Trnsducers So fr, we hve only considered utomt tht recognize lnguges, i.e., utomt tht do not produce ny output on ny input
More informationTheory of Computation Regular Languages. (NTU EE) Regular Languages Fall / 38
Theory of Computtion Regulr Lnguges (NTU EE) Regulr Lnguges Fll 2017 1 / 38 Schemtic of Finite Automt control 0 0 1 0 1 1 1 0 Figure: Schemtic of Finite Automt A finite utomton hs finite set of control
More informationAutomata Theory 101. Introduction. Outline. Introduction Finite Automata Regular Expressions ω-automata. Ralf Huuck.
Outline Automt Theory 101 Rlf Huuck Introduction Finite Automt Regulr Expressions ω-automt Session 1 2006 Rlf Huuck 1 Session 1 2006 Rlf Huuck 2 Acknowledgement Some slides re sed on Wolfgng Thoms excellent
More informationCHAPTER 1 Regular Languages. Contents. definitions, examples, designing, regular operations. Non-deterministic Finite Automata (NFA)
Finite Automt (FA or DFA) CHAPTER Regulr Lnguges Contents definitions, exmples, designing, regulr opertions Non-deterministic Finite Automt (NFA) definitions, equivlence of NFAs DFAs, closure under regulr
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 informationTutorial Automata and formal Languages
Tutoril Automt nd forml Lnguges Notes for to the tutoril in the summer term 2017 Sestin Küpper, Christine Mik 8. August 2017 1 Introduction: Nottions nd sic Definitions At the eginning of the tutoril we
More informationChapter 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 informationReview 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 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 informationNFAs and Regular Expressions. NFA-ε, continued. Recall. Last class: Today: Fun:
CMPU 240 Lnguge Theory nd Computtion Spring 2019 NFAs nd Regulr Expressions Lst clss: Introduced nondeterministic finite utomt with -trnsitions Tody: Prove n NFA- is no more powerful thn n NFA Introduce
More informationNormal 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 informationa,b a 1 a 2 a 3 a,b 1 a,b a,b 2 3 a,b a,b a 2 a,b CS Determinisitic Finite Automata 1
CS4 45- Determinisitic Finite Automt -: Genertors vs. Checkers Regulr expressions re one wy to specify forml lnguge String Genertor Genertes strings in the lnguge Deterministic Finite Automt (DFA) re nother
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 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 informationFormal Language and Automata Theory (CS21004)
Forml Lnguge nd Automt Forml Lnguge nd Automt Theory (CS21004) Khrgpur Khrgpur Khrgpur Forml Lnguge nd Automt Tle of Contents Forml Lnguge nd Automt Khrgpur 1 2 3 Khrgpur Forml Lnguge nd Automt Forml Lnguge
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 informationContext-Free Grammars and Languages
Context-Free Grmmrs nd Lnguges (Bsed on Hopcroft, Motwni nd Ullmn (2007) & Cohen (1997)) Introduction Consider n exmple sentence: A smll ct ets the fish English grmmr hs rules for constructing sentences;
More information12.1 Nondeterminism Nondeterministic Finite Automata. a a b ε. CS125 Lecture 12 Fall 2014
CS125 Lecture 12 Fll 2014 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 informationCompiler Design. Fall Lexical Analysis. Sample Exercises and Solutions. Prof. Pedro C. Diniz
Univerity of Southern Cliforni Computer Siene Deprtment Compiler Deign Fll 6 Lexil Anlyi Smple Exerie nd Solution Prof. Pedro C. Dini USC / Informtion Siene Intitute 4676 Admirlty Wy, Suite Mrin del Rey,
More informationSpeech Recognition Lecture 2: Finite Automata and Finite-State Transducers. Mehryar Mohri Courant Institute and Google Research
Speech Recognition Lecture 2: Finite Automt nd Finite-Stte Trnsducers Mehryr Mohri Cournt Institute nd Google Reserch mohri@cims.nyu.com Preliminries Finite lphet Σ, empty string. Set of ll strings over
More informationNFAs continued, Closure Properties of Regular Languages
lgorithms & Models of omputtion S/EE 374, Spring 209 NFs continued, losure Properties of Regulr Lnguges Lecture 5 Tuesdy, Jnury 29, 209 Regulr Lnguges, DFs, NFs Lnguges ccepted y DFs, NFs, nd regulr expressions
More informationLanguages & Automata
Lnguges & Automt Dr. Lim Nughton Lnguges A lnguge is sed on n lphet which is finite set of smols such s {, } or {, } or {,..., z}. If Σ is n lphet, string over Σ is finite sequence of letters from Σ, (strings
More informationCS103 Handout 32 Fall 2016 November 11, 2016 Problem Set 7
CS103 Hndout 32 Fll 2016 Novemer 11, 2016 Prolem Set 7 Wht cn you do with regulr expressions? Wht re the limits of regulr lnguges? On this prolem set, you'll find out! As lwys, plese feel free to drop
More informationDFA minimisation using the Myhill-Nerode theorem
DFA minimistion using the Myhill-Nerode theorem Johnn Högerg Lrs Lrsson Astrct The Myhill-Nerode theorem is n importnt chrcteristion of regulr lnguges, nd it lso hs mny prcticl implictions. In this chpter,
More informationRevision Sheet. (a) Give a regular expression for each of the following languages:
Theoreticl Computer Science (Bridging Course) Dr. G. D. Tipldi F. Bonirdi Winter Semester 2014/2015 Revision Sheet University of Freiurg Deprtment of Computer Science Question 1 (Finite Automt, 8 + 6 points)
More information