Review for the Midterm

Size: px
Start display at page:

Download "Review for the Midterm"

Transcription

1 Review for the Midterm Stephen A. Edwrds Columi University Fll 2018

2 The Midterm Structure of Compiler Scnning Lnguges nd Regulr Expressions NFAs Trnslting REs into NFAs: Thompson s Construction Building DFA from n NFA: Suset Construction Prsing Resolving Amiguity Rightmost nd Reverse-Rightmost Derivtions Building the LR(0) Automton FIRST nd FOLLOW Building n SLR Prsing Tle Shift/Reduce Prsing

3 The Midterm 75 minutes Closed ook One doule-sided sheet of notes of your own devising Anything discussed in clss is fir gme Little, if ny, progrmming Detils of OCml/C/C++/Jv syntx not required

4 Compiling Simple Progrm int gcd(int, int ) { while (!= ) { if ( > ) -= ; else -= ; } return ; }

5 Wht the Compiler Sees int gcd(int, int ) { while (!= ) { if ( > ) -= ; else -= ; } return ; } i n t sp g c d ( i n t sp, sp i n t sp ) nl { nl sp sp w h i l e sp ( sp! = sp ) sp { nl sp sp sp sp i f sp ( sp > sp ) sp sp - = sp ; nl sp sp sp sp e l s e sp sp - = sp ; nl sp sp } nl sp sp r e t u r n sp ; nl } nl Text file is sequence of chrcters

6 Lexicl Anlysis Gives Tokens int gcd(int, int ) { while (!= ) { if ( > ) -= ; else -= ; } return ; } int gcd ( int, int ) { while (!= ) { if ( > ) -= ; else -= ; } return ; } A strem of tokens. Whitespce, comments removed.

7 Prsing Gives n Astrct Syntx Tree func int gcd rgs seq rg rg while return int int!= if int gcd(int, int ) { while (!= ) { if ( > ) -= ; else -= ; } return ; } > -= -=

8 Semntic Anlysis Resolves Symols nd Checks Types func int gcd rgs seq rg rg while return int int!= if Symol Tle > -= -= int int

9 Trnsltion into 3-Address Code L0: sne $1,, seq $0, $1, 0 true $0, L1 # while (!= ) sl $3,, seq $2, $3, 0 true $2, L4 # if ( < ) su,, # -= jmp L5 L4: su,, # -= L5: jmp L0 L1: ret int gcd(int, int ) { while (!= ) { if ( > ) -= ; else -= ; } return ; } elized ssemly lnguge w/ infinite registers

10 Genertion of Assemly gcd: pushl %ep # Sve BP movl %esp,%ep movl 8(%ep),%ex # Lod from stck movl 12(%ep),%edx # Lod from stck.l8: cmpl %edx,%ex je.l3 # while (!= ) jle.l5 # if ( < ) sul %edx,%ex # -= jmp.l8.l5: sul %ex,%edx # -= jmp.l8.l3: leve # Restore SP, BP ret

11 Descriing Tokens Alphet: A finite set of symols Exmples: { 0, 1 }, { A, B, C,..., Z }, ASCII, Unicode String: A finite sequence of symols from n lphet Exmples: (the empty string), Stephen, αβγ Lnguge: A set of strings over n lphet Exmples: (the empty lnguge), { 1, 11, 111, 1111 }, ll English words, strings tht strt with letter followed y ny sequence of letters nd digits

12 Opertions on Lnguges Let L = {, wo }, M = { mn, men } Conctention: Strings from one followed y the other LM = { mn, men, womn, women } Union: All strings from ech lnguge L M = {, wo, mn, men } Kleene Closure: Zero or more conctentions M = {} M MM MMM = {, mn, men, mnmn, mnmen, menmn, menmen, mnmnmn, mnmnmen, mnmenmn,... }

13 Regulr Expressions over n Alphet Σ A stndrd wy to express lnguges for tokens. 1. is regulr expression tht denotes {} 2. If Σ, is n RE tht denotes {} 3. If r nd s denote lnguges L(r ) nd L(s), (r ) (s) denotes L(r ) L(s) (r )(s) denotes {tu : t L(r ),u L(s)} (r ) denotes i=0 Li (L 0 = {} nd L i = LL i 1 )

14 Nondeterministic Finite Automt All strings contining n even numer of 0 s nd 1 s A 1 1 C B D 1 1. Set{ of sttes S : A B C D 2. Set of input symols Σ : {0,1} 3. Trnsition function σ : S Σ 2 S stte 0 1 A {B} {C} B {A} {D} C {D} {A} D {C} {B} 4. Strt stte s 0 : A 5. Set{ of ccepting } sttes F : A }

15 The Lnguge induced y n NFA An NFA ccepts n input string x iff there is pth from the strt stte to n ccepting stte tht spells out x. A 1 1 C B 1 1 D Show tht the string is ccepted A B D C D B A

16 Trnslting REs into NFAs Symol r 1 r r 1 r 2 2 Sequence r 1 r 1 r 2 r 2 Choice (r ) r Kleene Closure

17 Trnslting REs into NFAs Exmple: Trnslte ( ) into n NFA. Answer: Show tht the string is ccepted. Answer:

18 Simulting NFAs Prolem: you must follow the right rcs to show tht string is ccepted. How do you know which rc is right? Solution: follow them ll nd sort it out lter. Two-stck NFA simultion lgorithm: 1. Initil sttes: the -closure of the strt stte 2. For ech chrcter c, New sttes: follow ll trnsitions leled c Form the -closure of the current sttes 3. Accept if ny finl stte is ccepting

19 Simulting n NFA:, Strt

20 Simulting n NFA:

21 Simulting n NFA:

22 Simulting n NFA:

23 Simulting n NFA:, Done

24 Deterministic Finite Automt Restricted form of NFAs: No stte hs trnsition on For ech stte s nd symol, there is t most one edge leled leving s. Differs sutly from the definition used in COMS W3261 (Sipser, Introduction to the Theory of Computtion) Very esy to check cceptnce: simulte y mintining current stte. Accept if you end up on n ccepting stte. Reject if you end on non-ccepting stte or if there is no trnsition from the current stte for the next symol.

25 Deterministic Finite Automt { } type token = ELSE ELSEIF rule token = prse "else" { ELSE } "elseif" { ELSEIF } e l s e i f

26 Deterministic Finite Automt { type token = IF ID of string NUM of string } rule token = prse "if" { IF } [ - z ] [ - z 0-9 ]* s lit { ID(lit) } [ 0-9 ]+ s num { NUM(num) } i ID f eg z0 9 IF z0 9 hj z ID z NUM 0 9

27 Building DFA from n NFA Suset construction lgorithm Simulte the NFA for ll possile inputs nd trck the sttes tht pper. Ech unique stte during simultion ecomes stte in the DFA.

28 Suset construction for ( )

29 Suset construction for ( )

30 Suset construction for ( )

31 Suset construction for ( )

32 Suset construction for ( )

33 Result of suset construction for ( ) Is this miniml? (Suset construction does not involve minimiztion)

34 Amiguous Arithmetic Amiguity cn e prolem in expressions. Consider prsing 3-4 * with the grmmr e e + e e e e e e /e N * * * * *

35 Opertor Precedence Defines how sticky n opertor is. 1 * * 4 * t higher precedence thn +: (1 * 2) + (3 * 4) * * 3 4 * + t higher precedence thn * : 1 * (2 + 3) * 4 *

36 Associtivity Whether to evlute left-to-right or right-to-left Most opertors re left-ssocitive ((1 2) 3) 4 1 (2 (3 4)) left ssocitive right ssocitive

37 Fixing Amiguous Grmmrs A grmmr specifiction: expr : expr PLUS expr expr MINUS expr expr TIMES expr expr DIVIDE expr NUMBER Amiguous: no precedence or ssocitivity. Ocmlycc s complint: 16 shift/reduce conflicts.

38 Assigning Precedence Levels Split into multiple rules, one per level expr : expr PLUS expr expr MINUS expr term term : term TIMES term term DIVIDE term tom tom : NUMBER Still miguous: ssocitivity not defined Ocmlycc s complint: 8 shift/reduce conflicts.

39 Assigning Associtivity Mke one side the next level of precedence expr : expr PLUS term expr MINUS term term term : term TIMES tom term DIVIDE tom tom tom : NUMBER This is left-ssocitive. No shift/reduce conflicts.

40 Rightmost Derivtion of + 1 :e t + e 2 :e t 3 : t t 4 : t e t + e t + t t + t + + At ech step, expnd the rightmost nonterminl. nonterminl hndle : The right side of production Fun nd interesting fct: there is exctly one rightmost expnsion if the grmmr is unmigious.

41 Rightmost Derivtion: Wht to Expnd 1 :e t + e 2 :e t 3 : t t 4 : t e t + e t + t t + t + + e t + e t + t t + t + + Expnd here Terminls only

42 Reverse Rightmost Derivtion 1 :e t + e 2 :e t 3 : t t 4 : t e t + e t + t t + t t + t + t + t t + e e vile prefixes terminls t t t + e e

43 Shift/Reduce Prsing Using n Orcle 1 :e t + e 2 :e t 3 : t t 4 : t e t + e t + t t + t + + stck + shift + shift + shift + reduce 4 t + reduce 3 t + shift t + shift t + reduce 4 t + t reduce 2 t + e e reduce 1 ccept input

44 Hndle Hunting Right Sententil Form: ny step in rightmost derivtion Hndle: in sententil form, RHS of rule tht, when rewritten, yields the previous step in rightmost derivtion. The ig question in shift/reduce prsing: When is there hndle on the top of the stck? Enumerte ll the right-sententil forms nd pttern-mtch ginst them? Usully infinite in numer, ut let s try nywy.

45 The Hndle-entifying Automton Mgicl result, due to Knuth: An utomton suffices to locte hndle in right-sententil form. e e t t + t + + t + e t + t + + t+ t + t + + t + t t + t + + t t t t e t + e + t t

46 Building the Initil Stte of the LR(0) Automton 1 :e t + e 2 :e t 3 : t t 4 : t e e Key ide: utomt identify vile prefixes of right sententil forms. Ech stte is n equivlence clss of possile plces in productions. At the eginning, ny vile prefix must e t the eginning of string expnded from e. We write this condition e e

47 Building the Initil Stte of the LR(0) Automton 1 :e t + e 2 :e t 3 : t t 4 : t e e e t + e e t Key ide: utomt identify vile prefixes of right sententil forms. Ech stte is n equivlence clss of possile plces in productions. At the eginning, ny vile prefix must e t the eginning of string expnded from e. We write this condition e e There re two choices for wht n e my expnd to: t + e nd t. So when e e, e t + e nd e t re lso true, i.e., it must strt with string expnded from t.

48 Building the Initil Stte of the LR(0) Automton 1 :e t + e 2 :e t 3 : t t 4 : t e e e t + e e t t t t Key ide: utomt identify vile prefixes of right sententil forms. Ech stte is n equivlence clss of possile plces in productions. At the eginning, ny vile prefix must e t the eginning of string expnded from e. We write this condition e e There re two choices for wht n e my expnd to: t + e nd t. So when e e, e t + e nd e t re lso true, i.e., it must strt with string expnded from t. Similrly, t must e either t or, so t t nd t.

49 Building the LR(0) Automton e e e t + e S0 : e t t t t The first stte suggests vile prefix cn strt s ny string derived from e, ny string derived from t, or.

50 Building the LR(0) Automton Just pssed string derived from e S7 : e e e e e e t + e S0 : e t t t t t t S1 : t Just pssed prefix tht ended in n Just pssed prefix ending in string derived from t t S2 : e t +e e t The first stte suggests vile prefix cn strt s ny string derived from e, ny string derived from t, or. The items for these three sttes come from dvncing the cross ech thing, then performing the closure opertion (vcuous here).

51 Building the LR(0) Automton S7 : e e e e e e t + e S0 : e t t t t t S2 : e t +e e t + S4 : e t + e t t S1 : t In S2, + my e next. This gives t + e. t t S3 : In S1, my e next, giving t

52 Building the LR(0) Automton S7 : e e e e e e t + e S0 : e t t t t t S2 : e t +e e t + e t + e e t + e S4 : e t t t t t t S1 : t t t S3 : t t t In S2, + my e next. This gives t + e. Closure dds 4 more items. In S1, my e next, giving t nd two others.

53 Building the LR(0) Automton S7 : e e e e e e t + e S0 : e t t t t t S2 : e t +e e t + t e t + e e t + e S4 : e t t t t e t t S1 : t S6 : e t + e t t S3 : t t t t S5 : t t

54 The first function If you cn derive string tht strts with terminl t from sequence of terminls nd nonterminls α, then t first(α). 1. If X is terminl, first(x ) = {X }. 2. If X, then dd to first(x ). 3. If X Y 1 Y k nd first(y 1 ), first(y 2 ),..., nd first(y i 1 ) for i = 1,...,k for some k, dd first(y i ) {} to first(x ) X strts with nything tht ppers fter skipping empty strings. Usully just first(y 1 ) first(x ) 4. If X Y 1 Y K nd first(y 1 ), first(y 2 ),..., nd first(y k ), dd to first(x ) If ll of X cn e empty, X cn e empty 1 :e t + e 2 :e t 3 : t t 4 : t first() = {} first(t) = {} ecuse t t nd t first(e) = {} ecuse e t + e, e t, nd first(t) = {}.

55 First nd first(α) mens α cn derive the empty string. 1. If X is terminl, first(x ) = {X }. 2. If X, then dd to first(x ). 3. If X Y 1 Y k nd first(y 1 ), first(y 2 ),..., nd first(y i 1 ) for i = 1,...,k for some k, dd first(y i ) {} to first(x ) 4. If X Y 1 Y K nd first(y 1 ), first(y 2 ),..., nd first(y k ), dd to first(x ) X Y Z Y Y Z c Z W W W d first() = {} first(c) = {c} first(d) = {d} (1) first(w ) = {} first(d) = {,d} (2,3) first(z ) = first(c) (first(w ) {}) {} = {,c,d} (3,3,4) first(y ) = {} {} = {,} (2,3) first(x ) = (first(y ) {}) (first(z ) {}) first() = {,,c,d} (3,3,3)

56 The follow function If t is terminl, A is nonterminl, nd At cn e derived, then t follow(a). 1. Add $ ( end-of-input ) to follow(s) (strt symol). End-of-input comes fter the strt symol 2. For ech prod. Aα, dd first(α) {} to follow(a). A is followed y the first thing fter it 3. For ech prod. A B or A Bα where first(α), then dd everything in follow(a) to follow(b). If B ppers t the end of production, it cn e followed y whtever follows tht production 1 :e t + e 2 :e t 3 : t t 4 : t first(t) = {} first(e) = {} follow(e) = {$} follow(t) = { } 1. Becuse e is the strt symol

57 The follow function If t is terminl, A is nonterminl, nd At cn e derived, then t follow(a). 1. Add $ ( end-of-input ) to follow(s) (strt symol). End-of-input comes fter the strt symol 2. For ech prod. Aα, dd first(α) {} to follow(a). A is followed y the first thing fter it 3. For ech prod. A B or A Bα where first(α), then dd everything in follow(a) to follow(b). If B ppers t the end of production, it cn e followed y whtever follows tht production 1 :e t + e 2 :e t 3 : t t 4 : t first(t) = {} first(e) = {} follow(e) = {$} follow(t) = { + } 2. Becuse e t + e nd first(+) = {+}

58 The follow function If t is terminl, A is nonterminl, nd At cn e derived, then t follow(a). 1. Add $ ( end-of-input ) to follow(s) (strt symol). End-of-input comes fter the strt symol 2. For ech prod. Aα, dd first(α) {} to follow(a). A is followed y the first thing fter it 3. For ech prod. A B or A Bα where first(α), then dd everything in follow(a) to follow(b). If B ppers t the end of production, it cn e followed y whtever follows tht production 1 :e t + e 2 :e t 3 : t t 4 : t first(t) = {} first(e) = {} follow(e) = {$} follow(t) = { +,$} 3. Becuse e t nd $ follow(e)

59 The follow function If t is terminl, A is nonterminl, nd At cn e derived, then t follow(a). 1. Add $ ( end-of-input ) to follow(s) (strt symol). End-of-input comes fter the strt symol 2. For ech prod. Aα, dd first(α) {} to follow(a). A is followed y the first thing fter it 3. For ech prod. A B or A Bα where first(α), then dd everything in follow(a) to follow(b). If B ppers t the end of production, it cn e followed y whtever follows tht production 1 :e t + e 2 :e t 3 : t t 4 : t first(t) = {} first(e) = {} follow(e) = {$} follow(t) = { +,$} Fixed-point reched: pplying ny rule does not chnge ny set

60 Converting the LR(0) Automton to n SLR Tle S7: e e S0 S1: t S3 e t t S5: t t S2: e t t 1 :e t + e 2 :e t 3 : t t 4 : t S4 e + S6: e t + e Stte Action Goto + $ e t 0 s1 7 2 From S0, shift n nd go to S1; or cross t nd go to S2; or cross n e nd go to S7.

61 Converting the LR(0) Automton to n SLR Tle S7: e e S0 S1: t S3 e t t S5: t t S2: e t t 1 :e t + e 2 :e t 3 : t t 4 : t S4 e + S6: e t + e Stte Action Goto + $ e t 0 s r4 s3 r4 From S1, shift nd go to S3; or, if the next input could follow t, reduce y rule 4. According to rule 1, + could follow t; from rule 2, $ could.

62 Converting the LR(0) Automton to n SLR Tle S7: e e S0 S1: t S3 e t t S5: t t S2: e t t 1 :e t + e 2 :e t 3 : t t 4 : t S4 e + S6: e t + e Stte Action Goto + $ e t 0 s r4 s3 r4 2 s4 r2 From S2, shift + nd go to S4; or, if the next input could follow n e (only the end-of-input $), reduce y rule 2.

63 Converting the LR(0) Automton to n SLR Tle S7: e e S0 S1: t S3 e t t S5: t t S2: e t t 1 :e t + e 2 :e t 3 : t t 4 : t S4 e + S6: e t + e Stte Action Goto + $ e t 0 s r4 s3 r4 2 s4 r2 3 s1 5 From S3, shift n nd go to S1; or cross t nd go to S5.

64 Converting the LR(0) Automton to n SLR Tle S7: e e S0 S1: t S3 e t t S5: t t S2: e t t 1 :e t + e 2 :e t 3 : t t 4 : t S4 e + S6: e t + e Stte Action Goto + $ e t 0 s r4 s3 r4 2 s4 r2 3 s1 5 4 s1 6 2 From S4, shift n nd go to S1; or cross n e or t.

65 Converting the LR(0) Automton to n SLR Tle S7: e e S0 S1: t S3 e t t S5: t t S2: e t t 1 :e t + e 2 :e t 3 : t t 4 : t S4 e + S6: e t + e Stte Action Goto + $ e t 0 s r4 s3 r4 2 s4 r2 3 s1 5 4 s r3 r3 From S5, reduce using rule 3 if the next symol could follow t (gin, + nd $).

66 Converting the LR(0) Automton to n SLR Tle S7: e e S0 S1: t S3 e t t S5: t t S2: e t t 1 :e t + e 2 :e t 3 : t t 4 : t S4 e + S6: e t + e Stte Action Goto + $ e t 0 s r4 s3 r4 2 s4 r2 3 s1 5 4 s r3 r3 6 r1 From S6, reduce using rule 1 if the next symol could follow n e ($ only).

67 Converting the LR(0) Automton to n SLR Tle S7: e e S0 S1: t S3 e t t S5: t t S2: e t t 1 :e t + e 2 :e t 3 : t t 4 : t S4 e + S6: e t + e Stte Action Goto + $ e t 0 s r4 s3 r4 2 s4 r2 3 s1 5 4 s r3 r3 6 r1 7 If, in S7, we just crossed n e, ccept if we re t the end of the input.

68 Shift/Reduce Prsing with n SLR Tle Stck Input Action 1 :e t + e 2 :e t 3 : t t 4 : t Stte Action Goto + $ e t 0 s r4 s3 r4 2 s4 r2 3 s1 5 4 s r3 r3 6 r $ Shift, goto 1 Look t the stte on top of the stck nd the next input token. Find the ction (shift, reduce, or error) in the tle. In this cse, shift the token onto the stck nd mrk it with stte 1.

69 Shift/Reduce Prsing with n SLR Tle Stck Input Action 1 :e t + e 2 :e t 3 : t t 4 : t Stte Action Goto + $ e t 0 s r4 s3 r4 2 s4 r2 3 s1 5 4 s r3 r3 6 r $ Shift, goto $ Shift, goto 3 Here, the stte is 1, the next symol is, so shift nd mrk it with stte 3.

70 Shift/Reduce Prsing with n SLR Tle Stck Input Action 1 :e t + e 2 :e t 3 : t t 4 : t 0 +$ Shift, goto $ Shift, goto $ Shift, goto 1 Stte Action Goto $ Reduce 4 + $ e t 0 s r4 s3 r4 2 s4 r2 3 s1 5 4 s r3 r3 6 r1 7 Here, the stte is 1, the next symol is +. The tle sys reduce using rule 4.

71 Shift/Reduce Prsing with n SLR Tle Stck Input Action 1 :e t + e 2 :e t 3 : t t 4 : t Stte Action Goto + $ e t 0 s r4 s3 r4 2 s4 r2 3 s1 5 4 s r3 r3 6 r $ Shift, goto $ Shift, goto $ Shift, goto $ Reduce $ Remove the RHS of the rule (here, just ), oserve the stte on the top of the stck, nd consult the goto portion of the tle.

72 Shift/Reduce Prsing with n SLR Tle Stck Input Action 1 :e t + e 2 :e t 3 : t t 4 : t 0 +$ Shift, goto $ Shift, goto $ Shift, goto 1 Stte Action Goto + $ e t $ Reduce 4 3 t 5 +$ Reduce 3 0 s r4 s3 r4 2 s4 r2 3 s1 5 4 s r3 r3 6 r1 7 Here, we push t with stte 5. This effectively cks up the LR(0) utomton nd runs it over the newly dded nonterminl. In stte 5 with n upcoming +, the ction is reduce 3.

73 Shift/Reduce Prsing with n SLR Tle Stck Input Action 1 :e t + e 2 :e t 3 : t t 4 : t 0 +$ Shift, goto $ Shift, goto $ Shift, goto 1 Stte Action Goto + $ e t $ Reduce 4 3 t 5 +$ Reduce 3 0 s r4 s3 r4 2 s4 r2 3 s1 5 4 s r3 r3 6 r1 7 0 t 2 +$ Shift, goto 4 This time, we strip off the RHS for rule 3, t, exposing stte 0, so we push t with stte 2.

74 Shift/Reduce Prsing with n SLR Tle Stck Input Action 1 :e t + e 2 :e t 3 : t t 4 : t 0 +$ Shift, goto $ Shift, goto $ Shift, goto 1 Stte Action Goto + $ e t $ Reduce 4 3 t 5 +$ Reduce 3 0 s r4 s3 r4 2 s4 r2 3 s1 5 4 s r3 r3 6 r t +$ Shift, goto t + 4 $ Shift, goto t $ Reduce t t $ Reduce t e $ Reduce 1 0 e 7 $ Accept

75 Shift/Reduce nd Reduce/Reduce Conflicts Shift/reduce conflicts re cused y stte like t Else s t If the next token is Else, do you reduce it since Else my follow t, or shift it? Reduce/reduce conflicts re cused y stte like t t e t Do you reduce y t t or y e t?

76 A Reduce/Reduce Conflict S1 : 1 : 2 : 3 : S0 : S3 : S2 : S4 :

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

Regular Expressions (RE) Regular Expressions (RE) Regular Expressions (RE) Regular Expressions (RE) Kleene-*

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

AUTOMATA AND LANGUAGES. Definition 1.5: Finite Automaton

AUTOMATA 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 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

Scanner. Specifying patterns. Specifying patterns. Operations on languages. A scanner must recognize the units of syntax Some parts are easy:

Scanner. 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 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

Let's start with an example:

Let'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 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

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

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

CS 301. Lecture 04 Regular Expressions. Stephen Checkoway. January 29, 2018

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

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

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

Finite Automata-cont d

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

Lexical Analysis Part III

Lexical 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 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

Converting Regular Expressions to Discrete Finite Automata: A Tutorial

Converting 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 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

Java II Finite Automata I

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

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

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

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

1. For each of the following theorems, give a two or three sentence sketch of how the proof goes or why it is not true.

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

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

Theory of Computation Regular Languages. (NTU EE) Regular Languages Fall / 38

Theory 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 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

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

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

Finite-State Automata: Recap

Finite-State Automata: Recap Finite-Stte Automt: Recp Deepk D Souz Deprtment of Computer Science nd Automtion Indin Institute of Science, Bnglore. 09 August 2016 Outline 1 Introduction 2 Forml Definitions nd Nottion 3 Closure under

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

Worked out examples Finite Automata

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

3 Regular expressions

3 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 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

More on automata. Michael George. March 24 April 7, 2014

More 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 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

Non-Deterministic Finite Automata. Fall 2018 Costas Busch - RPI 1

Non-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 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

CISC 4090 Theory of Computation

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

Theory of Computation Regular Languages

Theory of Computation Regular Languages Theory of Computtion Regulr Lnguges Bow-Yw Wng Acdemi Sinic Spring 2012 Bow-Yw Wng (Acdemi Sinic) Regulr Lnguges Spring 2012 1 / 38 Schemtic of Finite Automt control 0 0 1 0 1 1 1 0 Figure: Schemtic of

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

a,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

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

Finite Automata. Informatics 2A: Lecture 3. Mary Cryan. 21 September School of Informatics University of Edinburgh

Finite Automata. Informatics 2A: Lecture 3. Mary Cryan. 21 September School of Informatics University of Edinburgh Finite Automt Informtics 2A: Lecture 3 Mry Cryn School of Informtics University of Edinburgh mcryn@inf.ed.c.uk 21 September 2018 1 / 30 Lnguges nd Automt Wht is lnguge? Finite utomt: recp Some forml definitions

More information

Fundamentals of Computer Science

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

Finite Automata. Informatics 2A: Lecture 3. John Longley. 22 September School of Informatics University of Edinburgh

Finite 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 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

Deterministic Finite Automata

Deterministic 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 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

Anatomy of a Deterministic Finite Automaton. Deterministic Finite Automata. A machine so simple that you can understand it in less than one minute

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

NFAs and Regular Expressions. NFA-ε, continued. Recall. Last class: Today: Fun:

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

Context-Free Grammars and Languages

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

Automata Theory 101. Introduction. Outline. Introduction Finite Automata Regular Expressions ω-automata. Ralf Huuck.

Automata 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 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

Formal Language and Automata Theory (CS21004)

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

2. Lexical Analysis. Oscar Nierstrasz

2. Lexical Analysis. Oscar Nierstrasz 2. Lexicl Anlysis Oscr Nierstrsz Thnks to Jens Plserg nd Tony Hosking for their kind permission to reuse nd dpt the CS132 nd CS502 lecture notes. http://www.cs.ucl.edu/~plserg/ http://www.cs.purdue.edu/homes/hosking/

More information

SWEN 224 Formal Foundations of Programming WITH ANSWERS

SWEN 224 Formal Foundations of Programming WITH ANSWERS T E W H A R E W Ā N A N G A O T E Ū P O K O O T E I K A A M Ā U I VUW V I C T O R I A UNIVERSITY OF WELLINGTON Time Allowed: 3 Hours EXAMINATIONS 2011 END-OF-YEAR SWEN 224 Forml Foundtions of Progrmming

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

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

CMPSCI 250: Introduction to Computation. Lecture #31: What DFA s Can and Can t Do David Mix Barrington 9 April 2014

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

12.1 Nondeterminism Nondeterministic Finite Automata. a a b ε. CS125 Lecture 12 Fall 2016

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

CS375: Logic and Theory of Computing

CS375: Logic and Theory of Computing CS375: Logic nd Theory of Computing Fuhu (Frnk) Cheng Deprtment of Computer Science University of Kentucky 1 Tle of Contents: Week 1: Preliminries (set lger, reltions, functions) (red Chpters 1-4) Weeks

More information

CSE : Exam 3-ANSWERS, Spring 2011 Time: 50 minutes

CSE : 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 information

Lexical Analysis Finite Automate

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

CHAPTER 1 Regular Languages. Contents. definitions, examples, designing, regular operations. Non-deterministic Finite Automata (NFA)

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

CSC 311 Theory of Computation

CSC 311 Theory of Computation CSC 11 Theory of Computtion Tutoril on DFAs, NFAs, regulr expressions, regulr grmmr, closure of regulr lnguges, context-free grmmrs, non-deterministic push-down utomt, Turing mchines,etc. Tutoril 2 Second

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

CHAPTER 1 Regular Languages. Contents

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

Non-deterministic Finite Automata

Non-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 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

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

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

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

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

Speech Recognition Lecture 2: Finite Automata and Finite-State Transducers

Speech 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 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

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

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

Non-deterministic Finite Automata

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

Nondeterminism and Nodeterministic Automata

Nondeterminism 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 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

CS 267: Automated Verification. Lecture 8: Automata Theoretic Model Checking. Instructor: Tevfik Bultan

CS 267: Automated Verification. Lecture 8: Automata Theoretic Model Checking. Instructor: Tevfik Bultan CS 267: Automted Verifiction Lecture 8: Automt Theoretic Model Checking Instructor: Tevfik Bultn LTL Properties Büchi utomt [Vrdi nd Wolper LICS 86] Büchi utomt: Finite stte utomt tht ccept infinite strings

More information

NFAs continued, Closure Properties of Regular Languages

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

Speech Recognition Lecture 2: Finite Automata and Finite-State Transducers. Mehryar Mohri Courant Institute and Google Research

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

12.1 Nondeterminism Nondeterministic Finite Automata. a a b ε. CS125 Lecture 12 Fall 2014

12.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 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

Non-Deterministic Finite Automata

Non-Deterministic Finite Automata Non-Deterministic Finite Automt http://users.comlb.ox.c.uk/luke. ong/teching/moc/nf2up.pdf 1 Nondeterministic Finite Automton (NFA) Alphbet ={} q1 q2 2 Alphbet ={} Two choices q1 q2 3 Alphbet ={} Two choices

More information

CSCI 340: Computational Models. Transition Graphs. Department of Computer Science

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

Closure Properties of Regular Languages

Closure Properties of Regular Languages of Regulr Lnguges Dr. Neil T. Dntm CSCI-561, Colordo School of Mines Fll 2018 Dntm (Mines CSCI-561) Closure Properties of Regulr Lnguges Fll 2018 1 / 50 Outline Introduction Closure Properties Stte Minimiztion

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

Languages & Automata

Languages & 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 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

CS375: Logic and Theory of Computing

CS375: Logic and Theory of Computing CS375: Logic nd Theory of Computing Fuhu (Frnk) Cheng Deprtment of Computer Science University of Kentucky 1 Tble of Contents: Week 1: Preliminries (set lgebr, reltions, functions) (red Chpters 1-4) Weeks

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

Lecture 6 Regular Grammars

Lecture 6 Regular Grammars Lecture 6 Regulr Grmmrs COT 4420 Theory of Computtion Section 3.3 Grmmr A grmmr G is defined s qudruple G = (V, T, S, P) V is finite set of vribles T is finite set of terminl symbols S V is specil vrible

More information

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018 Finite Automt Theory nd Forml Lnguges TMV027/DIT321 LP4 2018 Lecture 10 An Bove April 23rd 2018 Recp: Regulr Lnguges We cn convert between FA nd RE; Hence both FA nd RE ccept/generte regulr lnguges; More

More information

1.3 Regular Expressions

1.3 Regular Expressions 56 1.3 Regulr xpressions These hve n importnt role in describing ptterns in serching for strings in mny pplictions (e.g. wk, grep, Perl,...) All regulr expressions of lphbet re 1.Ønd re regulr expressions,

More information

CMSC 330: Organization of Programming Languages. DFAs, and NFAs, and Regexps (Oh my!)

CMSC 330: Organization of Programming Languages. DFAs, and NFAs, and Regexps (Oh my!) CMSC 330: Orgniztion of Progrmming Lnguges DFAs, nd NFAs, nd Regexps (Oh my!) CMSC330 Spring 2018 Types of Finite Automt Deterministic Finite Automt (DFA) Exctly one sequence of steps for ech string All

More information

In-depth introduction to main models, concepts of theory of computation:

In-depth introduction to main models, concepts of theory of computation: CMPSCI601: Introduction Lecture 1 In-depth introduction to min models, concepts of theory of computtion: Computility: wht cn e computed in principle Logic: how cn we express our requirements Complexity:

More information