Topic 2: Lexing and Flexing

Size: px
Start display at page:

Download "Topic 2: Lexing and Flexing"

Transcription

1 Topic 2: Lexing nd Flexing COS 320 Compiling Techniques Princeton University Spring 2016 Lennrt Beringer 1

2 2 The Compiler

3 Lexicl Anlysis Gol: rek strem of ASCII chrcters (source/input) into sequence of tokens Token: sequence of chrcters treted s unit (cf. word) Ech token hs token type (cf. clssifiction ver - noun - punctution symol): IDENTIFIER REAL SEMI foo, x, quicksort, 6.7, 3.9E-33, -4.9 ; NUM IF THEN 1, 50, -100 if then LPAREN ( RPAREN ) EQ = PLUS + Mny tokens hve ssocited semntic informtion: NUM(1), NUM(50), IDENTIFIER(foo), IDENTIFIER(x), ut typiclly not SEMI(;), LPAREN(() Definition of tokens (mostly) prt of lnguge definition White spce nd comments often discrded. Pros/Cons? 3

4 Lexicl Anlysis Gol: rek strem of ASCII chrcters (source/input) into sequence of tokens Token: sequence of chrcters treted s unit (cf. word) Ech token hs token type (cf. clssifiction ver - noun - punctution symol): IDENTIFIER REAL SEMI foo, x, quicksort, 6.7, 3.9E-33, -4.9 ; NUM IF THEN 1, 50, -100 if then LPAREN ( RPAREN ) EQ = PLUS + Mny tokens hve ssocited semntic informtion: NUM(1), NUM(50), IDENTIFIER(foo), IDENTIFIER(x), ut typiclly not SEMI(;), LPAREN(() Definition of tokens (mostly) prt of lnguge definition White spce nd comments often discrded. Pros/Cons? 4

5 Lexicl Anlysis Gol: rek strem of ASCII chrcters (source/input) into sequence of tokens Token: sequence of chrcters treted s unit (cf. word) Ech token hs token type (cf. clssifiction ver - noun - punctution symol): IDENTIFIER REAL SEMI foo, x, quicksort, 6.7, 3.9E-33, -4.9 ; NUM IF THEN 1, 50, -100 if then LPAREN ( RPAREN ) EQ = PLUS + Mny tokens hve ssocited semntic informtion: NUM(1), NUM(50), IDENTIFIER(foo), IDENTIFIER(x), ut typiclly not SEMI(;), LPAREN(() Definition of tokens (mostly) prt of lnguge definition White spce nd comments often discrded. Pros/Cons? 5

6 Lexicl Anlysis Gol: rek strem of ASCII chrcters (source/input) into sequence of tokens Token: sequence of chrcters treted s unit (cf. word) Ech token hs token type (cf. clssifiction ver - noun - punctution symol): IDENTIFIER REAL SEMI foo, x, quicksort, 6.7, 3.9E-33, -4.9 ; NUM IF THEN 1, 50, -100 if then LPAREN ( RPAREN ) EQ = PLUS + Mny tokens hve ssocited semntic informtion: NUM(1), NUM(50), IDENTIFIER(foo), IDENTIFIER(x), ut typiclly not SEMI(;), LPAREN(() Definition of tokens (mostly) prt of lnguge definition White spce nd comments often discrded. Pros/Cons? 6

7 Lexicl Anlysis Gol: rek strem of ASCII chrcters (source/input) into sequence of tokens Token: sequence of chrcters treted s unit (cf. word) Ech token hs token type (cf. clssifiction ver - noun - punctution symol): IDENTIFIER REAL SEMI foo, x, quicksort, 6.7, 3.9E-33, -4.9 ; NUM IF THEN 1, 50, -100 if then LPAREN ( RPAREN ) EQ = PLUS + Mny tokens hve ssocited semntic informtion: NUM(1), NUM(50), IDENTIFIER(foo), IDENTIFIER(x), ut typiclly not SEMI(;), LPAREN(() Definition of tokens (mostly) prt of lnguge definition White spce nd comments often discrded. Pros/Cons? 7

8 8 Lexicl Anlysis Exmple

9 Lexicl Anlysis Exmple IDENTIFIER(x) EQ LPAREN IDENTIFIER(y) PLUS NUM(4.0) RPAREN SEMI 9

10 Implementing Lexicl Anlyzer (Lexer) Option 1: write it from scrtch: Source: text file Lexer for lnguge L Strem of tokens 10

11 Implementing Lexicl Anlyzer (Lexer) Option 1: write it from scrtch: Source: text file Lexer for lnguge L Strem of tokens Option 2: et your own dog food! (use lexicl nlyzer genertor): Source: text file Token strem wrt L1 Lexer for L1 Lexer for L2 Token strem wrt L2 Input: lexing rules for L1 Lexer genertor Input: lexing rules for L2 11

12 Implementing Lexicl Anlyzer (Lexer) Option 1: write it from scrtch Source: text file Lexer for lnguge L Strem of tokens Option 2: et your own dog food! (use lexicl nlyzer genertor) Source: text file Token strem wrt L1 Lexer for L1 Lexer for L2 Token strem wrt L2 Input: lexing rules for L1 Lexer genertor Input: lexing rules for L2 12 Q: how do we descrie the tokens for L1, L2,? A: using nother lnguge, of course! Yeh, ut how do we descrie the tokens of tht lnguge???

13 Theory to the rescue: regulr expressions Some definitions An lphet is (finite) collection of symols. Exmples: ASCII, {0, 1}, {A,..Z,,.. Z}, {0,..9} 13

14 Theory to the rescue: regulr expressions Some definitions An lphet is (finite) collection of symols. Exmples: ASCII, {0, 1}, {A,..Z,,.. Z}, {0,..9} A string/word (over lphet A) is finite sequence of symols from A. 14

15 Theory to the rescue: regulr expressions Some definitions An lphet is (finite) collection of symols. Exmples: ASCII, {0, 1}, {A,..Z,,.. Z}, {0,..9} A string/word (over lphet A) is finite sequence of symols from A. A lnguge (over A) is (finite or infinite) set of strings over A. 15

16 Theory to the rescue: regulr expressions Some definitions An lphet is (finite) collection of symols. Exmples: ASCII, {0, 1}, {A,..Z,,.. Z}, {0,..9} A string/word (over lphet A) is finite sequence of symols from A. A lnguge (over A) is (finite or infinite) set of strings over A. Exmples: the ML lnguge: set of ll strings representing correct ML progrms (infinite) the lnguge of ML keywords: set of ll strings tht re ML keywords (finite) the lnguge of ML tokens: set of ll strings tht mp to ML tokens (infinite) 16

17 Theory to the rescue: regulr expressions Some definitions An lphet is (finite) collection of symols. Exmples: ASCII, {0, 1}, {A,..Z,,.. Z}, {0,..9} A string/word (over lphet A) is finite sequence of symols from A. A lnguge (over A) is (finite or infinite) set of strings over A. Exmples: the ML lnguge: set of ll strings representing correct ML progrms (infinite) the lnguge of ML keywords: set of ll strings tht re ML keywords (finite) the lnguge of ML tokens: set of ll strings tht mp to ML tokens (infinite) Q: How to descrie lnguges? A(for lexing): regulr expressions! REs re finite descriptions/representtions of (certin) finite or infinite lnguges, including the lnguge of (progrmming) lnguge s tokens (eg the lnguge of ML tokens) the lnguge descriing the lnguge of (progrmming) lnguge s tokens, the lnguge descriing 17

18 Constructing regulr expressions Bse cses Inductive cses: given RE s M nd N, 18

19 Constructing regulr expressions Bse cses the RE ε (epsilon): the (finite) lnguge contining only the empty string. for ech symol from A, the RE denotes the (finite) lnguge contining only the string. Inductive cses: given RE s M nd N, 19

20 Constructing regulr expressions Bse cses the RE ε (epsilon): the (finite) lnguge contining only the empty string. for ech symol from A, the RE denotes the (finite) lnguge contining only the string. Inductive cses: given RE s M nd N, the RE M N (lterntion, union) descries the lnguge contining the strings in M or N. Exmple: denotes the two-element lnguge {, } 20

21 Constructing regulr expressions Bse cses the RE ε (epsilon): the (finite) lnguge contining only the empty string. for ech symol from A, the RE denotes the (finite) lnguge contining only the string. Inductive cses: given RE s M nd N, the RE M N (lterntion, union) descries the lnguge contining the strings in M or N. Exmple: denotes the two-element lnguge {, } The RE MN (conctention) denotes the strings tht cn e written s the conctention mn where m in from M nd n is from N. Exmple: ( )( c) denotes the lnguge {, c,, c} 21

22 Constructing regulr expressions Bse cses the RE ε (epsilon): the (finite) lnguge contining only the empty string. for ech symol from A, the RE denotes the (finite) lnguge contining only the string. Inductive cses: given RE s M nd N, the RE M N (lterntion, union) descries the lnguge contining the strings in M or N. Exmple: denotes the two-element lnguge {, } The RE MN (conctention) denotes the strings tht cn e written s the conctention mn where m in from M nd n is from N. Exmple: ( )( c) denotes the lnguge {, c,, c} The RE M* (Kleene closure/str) denotes the (infinitely mny) strings otined y conctenting finitely mny elements from M. Exmple: ( )* denotes the lnguge {ε,,,,,,,,,,, } 22

23 Regulr Expression Exmples For lphet Σ = {,}: Strings with n even numer of s: RE = Strings tht with n odd numer of s: RE =

24 Regulr Expression Exmples For lphet Σ = {,}: Strings with n even numer of s: RE = Solutions not unique! * ( * * )* Strings tht with n odd numer of s: RE =

25 Regulr Expression Exmples For lphet Σ = {,}: Strings with n even numer of s: RE = Strings tht with n odd numer of s: RE = Solutions not unique! * ( * * )* * * ( * *)*

26 Regulr Expression Exmples For lphet Σ = {,}: Strings with n even numer of s: RE = Strings tht with n odd numer of s: RE = * ( * * )* * * ( * *)* Strings with n even numer of s OR n odd numer of s:, RE = Strings tht cn e split into string with n even numer of s, followed y string with n odd numer of s:

27 Regulr Expression Exmples For lphet Σ = {,}: Strings with n even numer of s: RE = Strings tht with n odd numer of s: RE = * ( * * )* * * ( * *)* Strings with n even numer of s OR n odd numer of s:, RE = RE RE Strings tht cn e split into string with n even numer of s, followed y string with n odd numer of s:

28 Regulr Expression Exmples For lphet Σ = {,}: Strings with n even numer of s: RE = Strings tht with n odd numer of s: RE = * ( * * )* * * ( * *)* Strings with n even numer of s OR n odd numer of s:, RE = RE RE Strings tht cn e split into string with n even numer of s, followed y string with n odd numer of s: RE, = RE RE

29 Regulr Expression Exmples For lphet Σ = {,}: Strings with n even numer of s: RE = Strings with n odd numer of s: RE = * ( * * )* * * ( * *)* Strings with n even numer of s OR n odd numer of s:, RE = RE RE Strings tht cn e split into string with n even numer of s, followed y string with n odd numer of s: RE, = RE RE Optionl Homework: Strings with n even numer of s nd n odd numer of s.

30 Implementing RE s: finite utomt Source: text file Token strem wrt L1 Automton Lexer for L1 Automton Lexer for L2 Token strem wrt L2 RE Input: lexing rules for L1 Lexer genertor RE Input: lexing rules for L2 Finite utomt (k finite stte mchines, FSM s): computtionl model of mchines with finite memory Components of n utomton over lphet A: 30 finite set S of nodes ( sttes ) set of directed edges ( trnsitions ) s t, ech linking two sttes nd leled with symol from A designted strt stte s0 from S, indicted y rrow from nowhere nonempty set of finl ( ccepting ) sttes (indicted y doule circle)

31 Finite Automt recognize lnguges Definition: the lnguge recognized y n FA is the set of (finite) strings it ccepts. Q: how does the finite utomton D c ccept string A? A: follow the trnsitions: 1. strt in the strt stte s0 nd inspect the first symol, 1 2. when in stte s nd inspecting symol, trverse one edge leled to get to the next stte. Look t the next symol. 3. After reding in ll n symols: if the current stte s is finl one, ccept. Otherwise, reject. 4. whenever there s no edge whose lel mtches the next symol: reject. 31

32 Clsses of Finite Automt Deterministic finite utomton (DFA) ll edges leving node re uniquely leled. Nondeterministic finite utomton (NFA) two (or more) edges leving node my e identiclly uniquely leled. Any choice tht leds to cceptnce is fine. edges my lso e leled with ε. So cn jump to the next stte without consuming n input symol. 32

33 Clsses of Finite Automt Deterministic finite utomton (DFA) ll edges leving node re uniquely leled. Nondeterministic finite utomton (NFA) two (or more) edges leving node my e identiclly uniquely leled. Any choice tht leds to cceptnce is fine. edges my lso e leled with ε. So cn jump to the next stte without consuming n input symol. Strtegy for otining DFA tht recognizes exctly the lnguge descried y n RE: 1. convert RE into n NFA tht recognizes the lnguge 2. trnsform the NFA into n equivlent DFA Rememer Tuesdy s quiz? 33

34 NFA Exmples Over lphet {, }: Strings with n even numer of s: Strings with n odd numer of s:

35 NFA Exmples Over lphet {, }: Strings with n even numer of s: D : Strings with n odd numer of s:

36 NFA Exmples (dhoc) Over lphet {, }: Strings with n even numer of s: D : Strings with n odd numer of s: D : Cn we systemticlly generte NFA s from RE s?

37 37 RE to NFA Rules

38 38 RE to NFA Rules

39 39 RE to NFA Rules

40 40 RE to NFA Rules

41 RE to NFA Conversion: exmples for nd conct Strings with n even numer of s OR n odd numer of s: RE RE D D ε ε Strings tht cn e split into string with n even numer of s, followed y string with n odd numer of s: RE RE D D 41

42 RE to NFA Conversion: exmples for nd conct Strings with n even numer of s OR n odd numer of s: RE RE D D ε ε Strings tht cn e split into string with n even numer of s followed y string with n odd numer of s: RE RE D D 42

43 NFA to DFA Conversion c ε 5 c ε 6 Ide: comine identiclly leled NFA trnsitions DFA sttes represent sets of equivlent NFA sttes 43

44 NFA to DFA conversion Auxiliry definitions: edge(s, ) = { t s t } set of NFA sttes rechle from NFA stte s y n step closure(s) = S U ( U edge(s, ε)) s є S set of NFA sttes rechle from ny s є S y n ε step Min clcultion: DFA-edge(D,) = closure( U edge(s,)) s є D set of NFA sttes rechle from D y mking one step nd (then) ny numer of ε steps 44

45 NFA to DFA Exmple c ε 5 c ε 6 45 closure(s) S U ( U edge(s, ε)) s є S

46 NFA to DFA Exmple c ε 5 c ε 6 Step 1: closure sets 1 : {1} 2:{2} 3:{3,5} 4:{4,6} 5:{5} 6:{6} 46 closure(s) S U ( U edge(s, ε)) s є S edge(s, ) { t s t }

47 NFA to DFA Exmple c ε 5 c ε 6 Step 1: closure sets 1 {1} 2 {2} 3 {3,5} 4 {4,6} 5 {5} 6 {6} Step 2: edge sets c 1 2, , closure(s) edge(s, ) DFA-edge(D,) 47 S U ( U edge(s, ε)) s є S { t s t } closure( U edge(s,)) s є D

48 NFA to DFA Exmple 1 1 {1} 2 {2} 3 {3,5} 4 {4,6} 5 {5} 6 {6} c ε 5 c ε 6 Step 3: DFA-sets c 1 2, , D c {1} Cl(2) + Cl(3) = {2,3,5} {} {} {2,3,5} {} Cl(2)+Cl(4) = {2,4,6} {2,4,6} {} Cl(4) = {4,6} {} {4,6} {} {} {} Cl(4) + Cl(6) = {4,6} closure(s) edge(s, ) DFA-edge(D,) 48 S U ( U edge(s, ε)) s є S { t s t } closure( U edge(s,)) s є D

49 NFA to DFA Exmple c ε 5 c ε 6 Step 4: Trnsition mtrix A B C D D c {1} Cl(2) + Cl(3) = {2,3,5} {} {} {2,3,5} {} Cl(2)+Cl(4) = {2,4,6} {2,4,6} {} Cl(4) = {4,6} {} {4,6} {} {} {} A B C c Cl(4) +Cl(6) = {4,6} D 49

50 NFA to DFA Exmple c ε 5 c ε 6 Step 5: Initil stte: closure of initil NFA stte A B C D D c {1} Cl(2) + Cl(3) = {2,3,5} {} {} {2,3,5} {} Cl(2)+Cl(4) = {2,4,6} {2,4,6} {} Cl(4) = {4,6} {} {4,6} {} {} {} A B C c Cl(4) + Cl(6) = {4,6} D 50

51 NFA to DFA Exmple c ε 5 c ε 6 Step 6: Finl stte(s): DFA sttes contining finl NFA stte 51 A B C D D c {1} Cl(2) + Cl(3) = {2,3,5} {} {} {2,3,5} {} Cl(2)+Cl(4) = {2,4,6} {2,4,6} {} Cl(4) = {4,6} {} {4,6} {} {} {} A Algorithm in pseudo-code: Appel, pge 27 B C c Cl(4) + Cl(6) = {4,6} D

52 The Longest Token Lexer should identify the longest mtching token: ifz8 should e lexed s IDENTIFIER, not s two tokens IF, IDENTIFIER Hence, the implementtion sves the most recently encountered ccepting stte of the DFA (nd the corresponding strem position) nd updtes this info when pssing through nother ccepting stte Uses the order of rules s tie-reker in cse severl tokens (of equl length) mtch 52

53 Other Useful Techniques (see exercise 2.7) (generlized NFA s: trnsitions my e leled with RE s) 53

54 Summry Motivted use of lexer genertors for prtitioning input strem into tokens Three formlisms for descriing nd implementing lexers: Regulr expressions NFA s DFA s Conversions RE -> NFA -> DFA Next lecture: prcticlities of lexing (ML-LEX) 54

55 55 The Compiler

56 56 Prcticlities of lexing: ML Lex, Lex, Flex,

57 57 ML Lex: lexer genertor for ML (similr tools for C: lex, flex)

58 Lexicl Specifiction Specifiction of lexer hs three prts: User Declrtions %% ML-LEX Definitions %% Rules User declrtions: definitions of vlues to e used in the ction frgments of rules Two vlues must e defined in the section: type lexresult: type of the vlue returned y the rule ctions fun eof(): function to e clled y the generted lexer when end of input strem is reched (eg cll prser, print done ) 58

59 Lexicl Specifiction Specifiction of lexer hs three prts: User Declrtions %% ML-LEX Definitions %% Rules ML-LEX Definitions: definitions of regulr expressions revitions: DIGITS=[0..9]+; LETTER = [-za-z]; definitions of strt sttes to permit multiple lexers to run together: %s STATE1 STATE2 STATE3; Exmple: entering comment mode, e.g. for supporting nested comments 59

60 Lexicl Specifiction Specifiction of lexer hs three prts: optionl, sttes must e defined in ML-LEX section User Declrtions %% ML-LEX Definitions %% Rules ML expression (eg construct token nd return it to reg.expr the invoking function) Rules: formt: <strt-stte-list> pttern => (ction_code); Intuitive reding: if you re in stte mode, lex strings mtching the pttern s descried y the ction. 60

61 61 Rule Ptterns

62 62 Rule Actions

63 63 Strt Sttes

64 64 Rule Mtching nd Strt Sttes

65 65 Rule Dismigution

66 66 Exmple

67 67 Exmple in Action

CS412/413. Introduction to Compilers Tim Teitelbaum. Lecture 4: Lexical Analyzers 28 Jan 08

CS412/413. Introduction to Compilers Tim Teitelbaum. Lecture 4: Lexical Analyzers 28 Jan 08 CS412/413 Introduction to Compilers Tim Teitelum Lecture 4: Lexicl Anlyzers 28 Jn 08 Outline DFA stte minimiztion Lexicl nlyzers Automting lexicl nlysis Jlex lexicl nlyzer genertor CS 412/413 Spring 2008

More information

Dr. D.M. Akbar Hussain

Dr. D.M. Akbar Hussain Dr. D.M. Akr Hussin Lexicl Anlysis. Bsic Ide: Red the source code nd generte tokens, it is similr wht humns will do to red in; just tking on the input nd reking it down in pieces. Ech token is sequence

More information

CS321 Languages and Compiler Design I. Winter 2012 Lecture 5

CS321 Languages and Compiler Design I. Winter 2012 Lecture 5 CS321 Lnguges nd Compiler Design I Winter 2012 Lecture 5 1 FINITE AUTOMATA A non-deterministic finite utomton (NFA) consists of: An input lphet Σ, e.g. Σ =,. A set of sttes S, e.g. S = {1, 3, 5, 7, 11,

More information

Definition of Regular Expression

Definition of Regular Expression Definition of Regulr Expression After the definition of the string nd lnguges, we re redy to descrie regulr expressions, the nottion we shll use to define the clss of lnguges known s regulr sets. Recll

More information

Fig.25: the Role of LEX

Fig.25: the Role of LEX The Lnguge for Specifying Lexicl Anlyzer We shll now study how to uild lexicl nlyzer from specifiction of tokens in the form of list of regulr expressions The discussion centers round the design of n existing

More information

ΕΠΛ323 - Θεωρία και Πρακτική Μεταγλωττιστών

ΕΠΛ323 - Θεωρία και Πρακτική Μεταγλωττιστών ΕΠΛ323 - Θωρία και Πρακτική Μταγλωττιστών Lecture 3 Lexicl Anlysis Elis Athnsopoulos elisthn@cs.ucy.c.cy Recognition of Tokens if expressions nd reltionl opertors if è if then è then else è else relop

More information

Lexical Analysis: Constructing a Scanner from Regular Expressions

Lexical Analysis: Constructing a Scanner from Regular Expressions Lexicl Anlysis: Constructing Scnner from Regulr Expressions Gol Show how to construct FA to recognize ny RE This Lecture Convert RE to n nondeterministic finite utomton (NFA) Use Thompson s construction

More information

In the last lecture, we discussed how valid tokens may be specified by regular expressions.

In the last lecture, we discussed how valid tokens may be specified by regular expressions. LECTURE 5 Scnning SYNTAX ANALYSIS We know from our previous lectures tht the process of verifying the syntx of the progrm is performed in two stges: Scnning: Identifying nd verifying tokens in progrm.

More information

Finite Automata. Lecture 4 Sections Robb T. Koether. Hampden-Sydney College. Wed, Jan 21, 2015

Finite Automata. Lecture 4 Sections Robb T. Koether. Hampden-Sydney College. Wed, Jan 21, 2015 Finite Automt Lecture 4 Sections 3.6-3.7 Ro T. Koether Hmpden-Sydney College Wed, Jn 21, 2015 Ro T. Koether (Hmpden-Sydney College) Finite Automt Wed, Jn 21, 2015 1 / 23 1 Nondeterministic Finite Automt

More information

Reducing a DFA to a Minimal DFA

Reducing a DFA to a Minimal DFA Lexicl Anlysis - Prt 4 Reducing DFA to Miniml DFA Input: DFA IN Assume DFA IN never gets stuck (dd ded stte if necessry) Output: DFA MIN An equivlent DFA with the minimum numer of sttes. Hrry H. Porter,

More information

CS 432 Fall Mike Lam, Professor a (bc)* Regular Expressions and Finite Automata

CS 432 Fall Mike Lam, Professor a (bc)* Regular Expressions and Finite Automata CS 432 Fll 2017 Mike Lm, Professor (c)* Regulr Expressions nd Finite Automt Compiltion Current focus "Bck end" Source code Tokens Syntx tree Mchine code chr dt[20]; int min() { flot x = 42.0; return 7;

More information

Languages. L((a (b)(c))*) = { ε,a,bc,aa,abc,bca,... } εw = wε = w. εabba = abbaε = abba. (a (b)(c)) *

Languages. L((a (b)(c))*) = { ε,a,bc,aa,abc,bca,... } εw = wε = w. εabba = abbaε = abba. (a (b)(c)) * Pln for Tody nd Beginning Next week Interpreter nd Compiler Structure, or Softwre Architecture Overview of Progrmming Assignments The MeggyJv compiler we will e uilding. Regulr Expressions Finite Stte

More information

ΕΠΛ323 - Θεωρία και Πρακτική Μεταγλωττιστών. Lecture 3b Lexical Analysis Elias Athanasopoulos

ΕΠΛ323 - Θεωρία και Πρακτική Μεταγλωττιστών. Lecture 3b Lexical Analysis Elias Athanasopoulos ΕΠΛ323 - Θωρία και Πρακτική Μταγλωττιστών Lecture 3 Lexicl Anlysis Elis Athnsopoulos elisthn@cs.ucy.c.cy RecogniNon of Tokens if expressions nd relnonl opertors if è if then è then else è else relop è

More information

Lexical analysis, scanners. Construction of a scanner

Lexical analysis, scanners. Construction of a scanner Lexicl nlysis scnners (NB. Pges 4-5 re for those who need to refresh their knowledge of DFAs nd NFAs. These re not presented during the lectures) Construction of scnner Tools: stte utomt nd trnsition digrms.

More information

Lexical Analysis and Lexical Analyzer Generators

Lexical Analysis and Lexical Analyzer Generators 1 Lexicl Anlysis nd Lexicl Anlyzer Genertors Chpter 3 COP5621 Compiler Construction Copyright Roert vn Engelen, Florid Stte University, 2007-2009 2 The Reson Why Lexicl Anlysis is Seprte Phse Simplifies

More information

Example: Source Code. Lexical Analysis. The Lexical Structure. Tokens. What do we really care here? A Sample Toy Program:

Example: Source Code. Lexical Analysis. The Lexical Structure. Tokens. What do we really care here? A Sample Toy Program: Lexicl Anlysis Red source progrm nd produce list of tokens ( liner nlysis) source progrm The lexicl structure is specified using regulr expressions Other secondry tsks: (1) get rid of white spces (e.g.,

More information

CS 340, Fall 2014 Dec 11 th /13 th Final Exam Note: in all questions, the special symbol ɛ (epsilon) is used to indicate the empty string.

CS 340, Fall 2014 Dec 11 th /13 th Final Exam Note: in all questions, the special symbol ɛ (epsilon) is used to indicate the empty string. CS 340, Fll 2014 Dec 11 th /13 th Finl Exm Nme: Note: in ll questions, the specil symol ɛ (epsilon) is used to indicte the empty string. Question 1. [5 points] Consider the following regulr expression;

More information

Principles of Programming Languages

Principles of Programming Languages Principles of Progrmming Lnguges h"p://www.di.unipi.it/~ndre/did2c/plp- 14/ Prof. Andre Corrdini Deprtment of Computer Science, Pis Lesson 5! Gener;on of Lexicl Anlyzers Creting Lexicl Anlyzer with Lex

More information

CSc 453. Compilers and Systems Software. 4 : Lexical Analysis II. Department of Computer Science University of Arizona

CSc 453. Compilers and Systems Software. 4 : Lexical Analysis II. Department of Computer Science University of Arizona CSc 453 Compilers nd Systems Softwre 4 : Lexicl Anlysis II Deprtment of Computer Science University of Arizon collerg@gmil.com Copyright c 2009 Christin Collerg Implementing Automt NFAs nd DFAs cn e hrd-coded

More information

Deterministic. Finite Automata. And Regular Languages. Fall 2018 Costas Busch - RPI 1

Deterministic. Finite Automata. And Regular Languages. Fall 2018 Costas Busch - RPI 1 Deterministic Finite Automt And Regulr Lnguges Fll 2018 Costs Busch - RPI 1 Deterministic Finite Automton (DFA) Input Tpe String Finite Automton Output Accept or Reject Fll 2018 Costs Busch - RPI 2 Trnsition

More information

Lexical Analysis. Amitabha Sanyal. (www.cse.iitb.ac.in/ as) Department of Computer Science and Engineering, Indian Institute of Technology, Bombay

Lexical Analysis. Amitabha Sanyal. (www.cse.iitb.ac.in/ as) Department of Computer Science and Engineering, Indian Institute of Technology, Bombay Lexicl Anlysis Amith Snyl (www.cse.iit.c.in/ s) Deprtment of Computer Science nd Engineering, Indin Institute of Technology, Bomy Septemer 27 College of Engineering, Pune Lexicl Anlysis: 2/6 Recp The input

More information

CS 430 Spring Mike Lam, Professor. Parsing

CS 430 Spring Mike Lam, Professor. Parsing CS 430 Spring 2015 Mike Lm, Professor Prsing Syntx Anlysis We cn now formlly descrie lnguge's syntx Using regulr expressions nd BNF grmmrs How does tht help us? Syntx Anlysis We cn now formlly descrie

More information

CS143 Handout 07 Summer 2011 June 24 th, 2011 Written Set 1: Lexical Analysis

CS143 Handout 07 Summer 2011 June 24 th, 2011 Written Set 1: Lexical Analysis CS143 Hndout 07 Summer 2011 June 24 th, 2011 Written Set 1: Lexicl Anlysis In this first written ssignment, you'll get the chnce to ply round with the vrious constructions tht come up when doing lexicl

More information

Compilation

Compilation Compiltion 0368-3133 Lecture 2: Lexicl Anlysis Nom Rinetzky 1 2 Lexicl Anlysis Modern Compiler Design: Chpter 2.1 3 Conceptul Structure of Compiler Compiler Source text txt Frontend Semntic Representtion

More information

Should be done. Do Soon. Structure of a Typical Compiler. Plan for Today. Lab hours and Office hours. Quiz 1 is due tonight, was posted Tuesday night

Should be done. Do Soon. Structure of a Typical Compiler. Plan for Today. Lab hours and Office hours. Quiz 1 is due tonight, was posted Tuesday night Should e done L hours nd Office hours Sign up for the miling list t, strting to send importnt info to list http://groups.google.com/group/cs453-spring-2011 Red Ch 1 nd skim Ch 2 through 2.6, red 3.3 nd

More information

Assignment 4. Due 09/18/17

Assignment 4. Due 09/18/17 Assignment 4. ue 09/18/17 1. ). Write regulr expressions tht define the strings recognized by the following finite utomt: b d b b b c c b) Write FA tht recognizes the tokens defined by the following regulr

More information

Compiler Construction D7011E

Compiler Construction D7011E Compiler Construction D7011E Lecture 3: Lexer genertors Viktor Leijon Slides lrgely y John Nordlnder with mteril generously provided y Mrk P. Jones. 1 Recp: Hndwritten Lexers: Don t require sophisticted

More information

Fall Compiler Principles Lecture 1: Lexical Analysis. Roman Manevich Ben-Gurion University of the Negev

Fall Compiler Principles Lecture 1: Lexical Analysis. Roman Manevich Ben-Gurion University of the Negev Fll 2016-2017 Compiler Principles Lecture 1: Lexicl Anlysis Romn Mnevich Ben-Gurion University of the Negev Agend Understnd role of lexicl nlysis in compiler Regulr lnguges reminder Lexicl nlysis lgorithms

More information

CSCE 531, Spring 2017, Midterm Exam Answer Key

CSCE 531, Spring 2017, Midterm Exam Answer Key CCE 531, pring 2017, Midterm Exm Answer Key 1. (15 points) Using the method descried in the ook or in clss, convert the following regulr expression into n equivlent (nondeterministic) finite utomton: (

More information

Scanner Termination. Multi Character Lookahead. to its physical end. Most parsers require an end of file token. Lex and Jlex automatically create an

Scanner Termination. Multi Character Lookahead. to its physical end. Most parsers require an end of file token. Lex and Jlex automatically create an Scnner Termintion A scnner reds input chrcters nd prtitions them into tokens. Wht hppens when the end of the input file is reched? It my be useful to crete n Eof pseudo-chrcter when this occurs. In Jv,

More information

Implementing Automata. CSc 453. Compilers and Systems Software. 4 : Lexical Analysis II. Department of Computer Science University of Arizona

Implementing Automata. CSc 453. Compilers and Systems Software. 4 : Lexical Analysis II. Department of Computer Science University of Arizona Implementing utomt Sc 5 ompilers nd Systems Softwre : Lexicl nlysis II Deprtment of omputer Science University of rizon collerg@gmil.com opyright c 009 hristin ollerg NFs nd DFs cn e hrd-coded using this

More information

CMPSC 470: Compiler Construction

CMPSC 470: Compiler Construction CMPSC 47: Compiler Construction Plese complete the following: Midterm (Type A) Nme Instruction: Mke sure you hve ll pges including this cover nd lnk pge t the end. Answer ech question in the spce provided.

More information

Fall Compiler Principles Lecture 1: Lexical Analysis. Roman Manevich Ben-Gurion University

Fall Compiler Principles Lecture 1: Lexical Analysis. Roman Manevich Ben-Gurion University Fll 2014-2015 Compiler Principles Lecture 1: Lexicl Anlysis Romn Mnevich Ben-Gurion University Agend Understnd role of lexicl nlysis in compiler Lexicl nlysis theory Implementing professionl scnner vi

More information

Theory of Computation CSE 105

Theory of Computation CSE 105 $ $ $ Theory of Computtion CSE 105 Regulr Lnguges Study Guide nd Homework I Homework I: Solutions to the following problems should be turned in clss on July 1, 1999. Instructions: Write your nswers clerly

More information

CSE 401 Midterm Exam 11/5/10 Sample Solution

CSE 401 Midterm Exam 11/5/10 Sample Solution Question 1. egulr expressions (20 points) In the Ad Progrmming lnguge n integer constnt contins one or more digits, but it my lso contin embedded underscores. Any underscores must be preceded nd followed

More information

CMPT 379 Compilers. Lexical Analysis

CMPT 379 Compilers. Lexical Analysis CMPT 379 Compilers Anoop Srkr http://www.cs.sfu.c/~noop 9//7 Lexicl Anlysis Also clled scnning, tke input progrm string nd convert into tokens Exmple: T_DOUBLE ( doule ) T_IDENT ( f ) T_OP ( = ) doule

More information

LR Parsing, Part 2. Constructing Parse Tables. Need to Automatically Construct LR Parse Tables: Action and GOTO Table

LR Parsing, Part 2. Constructing Parse Tables. Need to Automatically Construct LR Parse Tables: Action and GOTO Table TDDD55 Compilers nd Interpreters TDDB44 Compiler Construction LR Prsing, Prt 2 Constructing Prse Tles Prse tle construction Grmmr conflict hndling Ctegories of LR Grmmrs nd Prsers Peter Fritzson, Christoph

More information

CS 340, Fall 2016 Sep 29th Exam 1 Note: in all questions, the special symbol ɛ (epsilon) is used to indicate the empty string.

CS 340, Fall 2016 Sep 29th Exam 1 Note: in all questions, the special symbol ɛ (epsilon) is used to indicate the empty string. CS 340, Fll 2016 Sep 29th Exm 1 Nme: Note: in ll questions, the speil symol ɛ (epsilon) is used to indite the empty string. Question 1. [10 points] Speify regulr expression tht genertes the lnguge over

More information

this grammar generates the following language: Because this symbol will also be used in a later step, it receives the

this grammar generates the following language: Because this symbol will also be used in a later step, it receives the LR() nlysis Drwcks of LR(). Look-hed symols s eplined efore, concerning LR(), it is possile to consult the net set to determine, in the reduction sttes, for which symols it would e possile to perform reductions.

More information

TO REGULAR EXPRESSIONS

TO REGULAR EXPRESSIONS Suject :- Computer Science Course Nme :- Theory Of Computtion DA TO REGULAR EXPRESSIONS Report Sumitted y:- Ajy Singh Meen 07000505 jysmeen@cse.iit.c.in BASIC DEINITIONS DA:- A finite stte mchine where

More information

Compilers Spring 2013 PRACTICE Midterm Exam

Compilers Spring 2013 PRACTICE Midterm Exam Compilers Spring 2013 PRACTICE Midterm Exm This is full length prctice midterm exm. If you wnt to tke it t exm pce, give yourself 7 minutes to tke the entire test. Just like the rel exm, ech question hs

More information

CSCI 3130: Formal Languages and Automata Theory Lecture 12 The Chinese University of Hong Kong, Fall 2011

CSCI 3130: Formal Languages and Automata Theory Lecture 12 The Chinese University of Hong Kong, Fall 2011 CSCI 3130: Forml Lnguges nd utomt Theory Lecture 12 The Chinese University of Hong Kong, Fll 2011 ndrej Bogdnov In progrmming lnguges, uilding prse trees is significnt tsk ecuse prse trees tell us the

More information

Some Thoughts on Grad School. Undergraduate Compilers Review and Intro to MJC. Structure of a Typical Compiler. Lexing and Parsing

Some Thoughts on Grad School. Undergraduate Compilers Review and Intro to MJC. Structure of a Typical Compiler. Lexing and Parsing Undergrdute Compilers Review nd Intro to MJC Announcements Miling list is in full swing Tody Some thoughts on grd school Finish prsing Semntic nlysis Visitor pttern for bstrct syntx trees Some Thoughts

More information

What are suffix trees?

What are suffix trees? Suffix Trees 1 Wht re suffix trees? Allow lgorithm designers to store very lrge mount of informtion out strings while still keeping within liner spce Allow users to serch for new strings in the originl

More information

Operator Precedence. Java CUP. E E + T T T * P P P id id id. Does a+b*c mean (a+b)*c or

Operator Precedence. Java CUP. E E + T T T * P P P id id id. Does a+b*c mean (a+b)*c or Opertor Precedence Most progrmming lnguges hve opertor precedence rules tht stte the order in which opertors re pplied (in the sence of explicit prentheses). Thus in C nd Jv nd CSX, +*c mens compute *c,

More information

Applied Databases. Sebastian Maneth. Lecture 13 Online Pattern Matching on Strings. University of Edinburgh - February 29th, 2016

Applied Databases. Sebastian Maneth. Lecture 13 Online Pattern Matching on Strings. University of Edinburgh - February 29th, 2016 Applied Dtses Lecture 13 Online Pttern Mtching on Strings Sestin Mneth University of Edinurgh - Ferury 29th, 2016 2 Outline 1. Nive Method 2. Automton Method 3. Knuth-Morris-Prtt Algorithm 4. Boyer-Moore

More information

2014 Haskell January Test Regular Expressions and Finite Automata

2014 Haskell January Test Regular Expressions and Finite Automata 0 Hskell Jnury Test Regulr Expressions nd Finite Automt This test comprises four prts nd the mximum mrk is 5. Prts I, II nd III re worth 3 of the 5 mrks vilble. The 0 Hskell Progrmming Prize will be wrded

More information

Quiz2 45mins. Personal Number: Problem 1. (20pts) Here is an Table of Perl Regular Ex

Quiz2 45mins. Personal Number: Problem 1. (20pts) Here is an Table of Perl Regular Ex Long Quiz2 45mins Nme: Personl Numer: Prolem. (20pts) Here is n Tle of Perl Regulr Ex Chrcter Description. single chrcter \s whitespce chrcter (spce, t, newline) \S non-whitespce chrcter \d digit (0-9)

More information

CS 241. Fall 2017 Midterm Review Solutions. October 24, Bits and Bytes 1. 3 MIPS Assembler 6. 4 Regular Languages 7.

CS 241. Fall 2017 Midterm Review Solutions. October 24, Bits and Bytes 1. 3 MIPS Assembler 6. 4 Regular Languages 7. CS 241 Fll 2017 Midterm Review Solutions Octoer 24, 2017 Contents 1 Bits nd Bytes 1 2 MIPS Assemly Lnguge Progrmming 2 3 MIPS Assemler 6 4 Regulr Lnguges 7 5 Scnning 9 1 Bits nd Bytes 1. Give two s complement

More information

Midterm I Solutions CS164, Spring 2006

Midterm I Solutions CS164, Spring 2006 Midterm I Solutions CS164, Spring 2006 Februry 23, 2006 Plese red ll instructions (including these) crefully. Write your nme, login, SID, nd circle the section time. There re 8 pges in this exm nd 4 questions,

More information

LEX5: Regexps to NFA. Lexical Analysis. CMPT 379: Compilers Instructor: Anoop Sarkar. anoopsarkar.github.io/compilers-class

LEX5: Regexps to NFA. Lexical Analysis. CMPT 379: Compilers Instructor: Anoop Sarkar. anoopsarkar.github.io/compilers-class LEX5: Regexps to NFA Lexicl Anlysis CMPT 379: Compilers Instructor: Anoop Srkr noopsrkr.github.io/compilers-clss Building Lexicl Anlyzer Token POern POern Regulr Expression Regulr Expression NFA NFA DFA

More information

Regular Expression Matching with Multi-Strings and Intervals. Philip Bille Mikkel Thorup

Regular Expression Matching with Multi-Strings and Intervals. Philip Bille Mikkel Thorup Regulr Expression Mtching with Multi-Strings nd Intervls Philip Bille Mikkel Thorup Outline Definition Applictions Previous work Two new problems: Multi-strings nd chrcter clss intervls Algorithms Thompson

More information

Tries. Yufei Tao KAIST. April 9, Y. Tao, April 9, 2013 Tries

Tries. Yufei Tao KAIST. April 9, Y. Tao, April 9, 2013 Tries Tries Yufei To KAIST April 9, 2013 Y. To, April 9, 2013 Tries In this lecture, we will discuss the following exct mtching prolem on strings. Prolem Let S e set of strings, ech of which hs unique integer

More information

COMP 423 lecture 11 Jan. 28, 2008

COMP 423 lecture 11 Jan. 28, 2008 COMP 423 lecture 11 Jn. 28, 2008 Up to now, we hve looked t how some symols in n lphet occur more frequently thn others nd how we cn sve its y using code such tht the codewords for more frequently occuring

More information

CS481: Bioinformatics Algorithms

CS481: Bioinformatics Algorithms CS481: Bioinformtics Algorithms Cn Alkn EA509 clkn@cs.ilkent.edu.tr http://www.cs.ilkent.edu.tr/~clkn/teching/cs481/ EXACT STRING MATCHING Fingerprint ide Assume: We cn compute fingerprint f(p) of P in

More information

Java CUP. Java CUP Specifications. User Code Additions. Package and Import Specifications

Java CUP. Java CUP Specifications. User Code Additions. Package and Import Specifications Jv CUP Jv CUP is prser-genertion tool, similr to Ycc. CUP uilds Jv prser for LALR(1) grmmrs from production rules nd ssocited Jv code frgments. When prticulr production is recognized, its ssocited code

More information

Regular Expressions and Automata using Miranda

Regular Expressions and Automata using Miranda Regulr Expressions nd Automt using Mirnd Simon Thompson Computing Lortory Univerisity of Kent t Cnterury My 1995 Contents 1 Introduction ::::::::::::::::::::::::::::::::: 1 2 Regulr Expressions :::::::::::::::::::::::::::::

More information

ECE 468/573 Midterm 1 September 28, 2012

ECE 468/573 Midterm 1 September 28, 2012 ECE 468/573 Midterm 1 September 28, 2012 Nme:! Purdue emil:! Plese sign the following: I ffirm tht the nswers given on this test re mine nd mine lone. I did not receive help from ny person or mteril (other

More information

CS311H: Discrete Mathematics. Graph Theory IV. A Non-planar Graph. Regions of a Planar Graph. Euler s Formula. Instructor: Işıl Dillig

CS311H: Discrete Mathematics. Graph Theory IV. A Non-planar Graph. Regions of a Planar Graph. Euler s Formula. Instructor: Işıl Dillig CS311H: Discrete Mthemtics Grph Theory IV Instructor: Işıl Dillig Instructor: Işıl Dillig, CS311H: Discrete Mthemtics Grph Theory IV 1/25 A Non-plnr Grph Regions of Plnr Grph The plnr representtion of

More information

Lecture T1: Pattern Matching

Lecture T1: Pattern Matching Introduction to Theoreticl CS Lecture T: Pttern Mtchin Two fundmentl questions. Wht cn computer do? Wht cn computer do with limited resources? Generl pproch. Don t tlk out specific mchines or prolems.

More information

CS 321 Programming Languages and Compilers. Bottom Up Parsing

CS 321 Programming Languages and Compilers. Bottom Up Parsing CS 321 Progrmming nguges nd Compilers Bottom Up Prsing Bottom-up Prsing: Shift-reduce prsing Grmmr H: fi ; fi b Input: ;;b hs prse tree ; ; b 2 Dt for Shift-reduce Prser Input string: sequence of tokens

More information

12 <= rm <digit> 2 <= rm <no> 2 <= rm <no> <digit> <= rm <no> <= rm <number>

12 <= rm <digit> 2 <= rm <no> 2 <= rm <no> <digit> <= rm <no> <= rm <number> DDD16 Compilers nd Interpreters DDB44 Compiler Construction R Prsing Prt 1 R prsing concept Using prser genertor Prse ree Genertion Wht is R-prsing? eft-to-right scnning R Rigthmost derivtion in reverse

More information

Scanner Termination. Multi Character Lookahead

Scanner Termination. Multi Character Lookahead If d.doublevlue() represents vlid integer, (int) d.doublevlue() will crete the pproprite integer vlue. If string representtion of n integer begins with ~ we cn strip the ~, convert to double nd then negte

More information

UNIVERSITY OF EDINBURGH COLLEGE OF SCIENCE AND ENGINEERING SCHOOL OF INFORMATICS INFORMATICS 1 COMPUTATION & LOGIC INSTRUCTIONS TO CANDIDATES

UNIVERSITY OF EDINBURGH COLLEGE OF SCIENCE AND ENGINEERING SCHOOL OF INFORMATICS INFORMATICS 1 COMPUTATION & LOGIC INSTRUCTIONS TO CANDIDATES UNIVERSITY OF EDINBURGH COLLEGE OF SCIENCE AND ENGINEERING SCHOOL OF INFORMATICS INFORMATICS COMPUTATION & LOGIC Sturdy st April 7 : to : INSTRUCTIONS TO CANDIDATES This is tke-home exercise. It will not

More information

COS 333: Advanced Programming Techniques

COS 333: Advanced Programming Techniques COS 333: Advnced Progrmming Techniques Brin Kernighn wk@cs, www.cs.princeton.edu/~wk 311 CS Building 609-258-2089 (ut emil is lwys etter) TA's: Junwen Li, li@cs, CS 217,258-0451 Yong Wng,yongwng@cs, CS

More information

ASTs, Regex, Parsing, and Pretty Printing

ASTs, Regex, Parsing, and Pretty Printing ASTs, Regex, Prsing, nd Pretty Printing CS 2112 Fll 2016 1 Algeric Expressions To strt, consider integer rithmetic. Suppose we hve the following 1. The lphet we will use is the digits {0, 1, 2, 3, 4, 5,

More information

Suffix trees, suffix arrays, BWT

Suffix trees, suffix arrays, BWT ALGORITHMES POUR LA BIO-INFORMATIQUE ET LA VISUALISATION COURS 3 Rluc Uricru Suffix trees, suffix rrys, BWT Bsed on: Suffix trees nd suffix rrys presenttion y Him Kpln Suffix trees course y Pco Gomez Liner-Time

More information

CMSC 331 First Midterm Exam

CMSC 331 First Midterm Exam 0 00/ 1 20/ 2 05/ 3 15/ 4 15/ 5 15/ 6 20/ 7 30/ 8 30/ 150/ 331 First Midterm Exm 7 October 2003 CMC 331 First Midterm Exm Nme: mple Answers tudent ID#: You will hve seventy-five (75) minutes to complete

More information

Context-Free Grammars

Context-Free Grammars Context-Free Grmmrs Descriing Lnguges We've seen two models for the regulr lnguges: Finite utomt ccept precisely the strings in the lnguge. Regulr expressions descrie precisely the strings in the lnguge.

More information

Lexical Analysis. Role, Specification & Recognition Tool: LEX Construction: - RE to NFA to DFA to min-state DFA - RE to DFA

Lexical Analysis. Role, Specification & Recognition Tool: LEX Construction: - RE to NFA to DFA to min-state DFA - RE to DFA Lexicl Anlysis Role, Specifiction & Recognition Tool: LEX Construction: - RE to NFA to DFA to min-stte DFA - RE to DFA Conducting Lexicl Anlysis Techniques for specifying nd implementing lexicl nlyzers

More information

CS 241 Week 4 Tutorial Solutions

CS 241 Week 4 Tutorial Solutions CS 4 Week 4 Tutoril Solutions Writing n Assemler, Prt & Regulr Lnguges Prt Winter 8 Assemling instrutions utomtilly. slt $d, $s, $t. Solution: $d, $s, nd $t ll fit in -it signed integers sine they re 5-it

More information

COS 333: Advanced Programming Techniques

COS 333: Advanced Programming Techniques COS 333: Advnced Progrmming Techniques How to find me wk@cs, www.cs.princeton.edu/~wk 311 CS Building 609-258-2089 (ut emil is lwys etter) TA's: Mtvey Arye (rye), Tom Jlin (tjlin), Nick Johnson (npjohnso)

More information

Solving Problems by Searching. CS 486/686: Introduction to Artificial Intelligence Winter 2016

Solving Problems by Searching. CS 486/686: Introduction to Artificial Intelligence Winter 2016 Solving Prolems y Serching CS 486/686: Introduction to Artificil Intelligence Winter 2016 1 Introduction Serch ws one of the first topics studied in AI - Newell nd Simon (1961) Generl Prolem Solver Centrl

More information

COMBINATORIAL PATTERN MATCHING

COMBINATORIAL PATTERN MATCHING COMBINATORIAL PATTERN MATCHING Genomic Repets Exmple of repets: ATGGTCTAGGTCCTAGTGGTC Motivtion to find them: Genomic rerrngements re often ssocited with repets Trce evolutionry secrets Mny tumors re chrcterized

More information

LING/C SC/PSYC 438/538. Lecture 21 Sandiway Fong

LING/C SC/PSYC 438/538. Lecture 21 Sandiway Fong LING/C SC/PSYC 438/538 Lecture 21 Sndiwy Fong Tody's Topics Homework 8 Review Optionl Homework 9 (mke up on Homework 7) Homework 8 Review Question1: write Prolog regulr grmmr for the following lnguge:

More information

Lecture T4: Pattern Matching

Lecture T4: Pattern Matching Introduction to Theoreticl CS Lecture T4: Pttern Mtching Two fundmentl questions. Wht cn computer do? How fst cn it do it? Generl pproch. Don t tlk bout specific mchines or problems. Consider miniml bstrct

More information

2 Computing all Intersections of a Set of Segments Line Segment Intersection

2 Computing all Intersections of a Set of Segments Line Segment Intersection 15-451/651: Design & Anlysis of Algorithms Novemer 14, 2016 Lecture #21 Sweep-Line nd Segment Intersection lst chnged: Novemer 8, 2017 1 Preliminries The sweep-line prdigm is very powerful lgorithmic design

More information

Context-Free Grammars

Context-Free Grammars Context-Free Grmmrs Descriing Lnguges We've seen two models for the regulr lnguges: Finite utomt ccept precisely the strings in the lnguge. Regulr expressions descrie precisely the strings in the lnguge.

More information

stack of states and grammar symbols Stack-Bottom marker C. Kessler, IDA, Linköpings universitet. 1. <list> -> <list>, <element> 2.

stack of states and grammar symbols Stack-Bottom marker C. Kessler, IDA, Linköpings universitet. 1. <list> -> <list>, <element> 2. TDDB9 Compilers nd Interpreters TDDB44 Compiler Construction LR Prsing Updted/New slide mteril 007: Pushdown Automton for LR-Prsing Finite-stte pushdown utomton contins lterntingly sttes nd symols in NUΣ

More information

CPSC 213. Polymorphism. Introduction to Computer Systems. Readings for Next Two Lectures. Back to Procedure Calls

CPSC 213. Polymorphism. Introduction to Computer Systems. Readings for Next Two Lectures. Back to Procedure Calls Redings for Next Two Lectures Text CPSC 213 Switch Sttements, Understnding Pointers - 2nd ed: 3.6.7, 3.10-1st ed: 3.6.6, 3.11 Introduction to Computer Systems Unit 1f Dynmic Control Flow Polymorphism nd

More information

Information Retrieval and Organisation

Information Retrieval and Organisation Informtion Retrievl nd Orgnistion Suffix Trees dpted from http://www.mth.tu.c.il/~himk/seminr02/suffixtrees.ppt Dell Zhng Birkeck, University of London Trie A tree representing set of strings { } eef d

More information

10/12/17. Motivating Example. Lexical and Syntax Analysis (2) Recursive-Descent Parsing. Recursive-Descent Parsing. Recursive-Descent Parsing

10/12/17. Motivating Example. Lexical and Syntax Analysis (2) Recursive-Descent Parsing. Recursive-Descent Parsing. Recursive-Descent Parsing Motivting Exmple Lexicl nd yntx Anlysis (2) In Text: Chpter 4 Consider the grmmr -> cad A -> b Input string: w = cd How to build prse tree top-down? 2 Initilly crete tree contining single node (the strt

More information

Sample Midterm Solutions COMS W4115 Programming Languages and Translators Monday, October 12, 2009

Sample Midterm Solutions COMS W4115 Programming Languages and Translators Monday, October 12, 2009 Deprtment of Computer cience Columbi University mple Midterm olutions COM W4115 Progrmming Lnguges nd Trnsltors Mondy, October 12, 2009 Closed book, no ids. ch question is worth 20 points. Question 5(c)

More information

acronyms possibly used in this test: CFG :acontext free grammar CFSM :acharacteristic finite state machine DFA :adeterministic finite automata

acronyms possibly used in this test: CFG :acontext free grammar CFSM :acharacteristic finite state machine DFA :adeterministic finite automata EE573 Fll 2002, Exm open book, if question seems mbiguous, sk me to clrify the question. If my nswer doesn t stisfy you, plese stte your ssumptions. cronyms possibly used in this test: CFG :context free

More information

CS201 Discussion 10 DRAWTREE + TRIES

CS201 Discussion 10 DRAWTREE + TRIES CS201 Discussion 10 DRAWTREE + TRIES DrwTree First instinct: recursion As very generic structure, we could tckle this problem s follows: drw(): Find the root drw(root) drw(root): Write the line for the

More information

Fall 2018 Midterm 1 October 11, ˆ You may not ask questions about the exam except for language clarifications.

Fall 2018 Midterm 1 October 11, ˆ You may not ask questions about the exam except for language clarifications. 15-112 Fll 2018 Midterm 1 October 11, 2018 Nme: Andrew ID: Recittion Section: ˆ You my not use ny books, notes, extr pper, or electronic devices during this exm. There should be nothing on your desk or

More information

From Dependencies to Evaluation Strategies

From Dependencies to Evaluation Strategies From Dependencies to Evlution Strtegies Possile strtegies: 1 let the user define the evlution order 2 utomtic strtegy sed on the dependencies: use locl dependencies to determine which ttriutes to compute

More information

How to Design REST API? Written Date : March 23, 2015

How to Design REST API? Written Date : March 23, 2015 Visul Prdigm How Design REST API? Turil How Design REST API? Written Dte : Mrch 23, 2015 REpresenttionl Stte Trnsfer, n rchitecturl style tht cn be used in building networked pplictions, is becoming incresingly

More information

Solving Problems by Searching. CS 486/686: Introduction to Artificial Intelligence

Solving Problems by Searching. CS 486/686: Introduction to Artificial Intelligence Solving Prolems y Serching CS 486/686: Introduction to Artificil Intelligence 1 Introduction Serch ws one of the first topics studied in AI - Newell nd Simon (1961) Generl Prolem Solver Centrl component

More information

Intermediate Information Structures

Intermediate Information Structures CPSC 335 Intermedite Informtion Structures LECTURE 13 Suffix Trees Jon Rokne Computer Science University of Clgry Cnd Modified from CMSC 423 - Todd Trengen UMD upd Preprocessing Strings We will look t

More information

Recognition of Tokens

Recognition of Tokens 42 Recognton o Tokens The queston s how to recognze the tokens? Exmple: ssume the ollowng grmmr rgment to generte specc lnguge: stmt expr expr then stmt expr then stmt else stmt term relop term term term

More information

Virtual Machine (Part I)

Virtual Machine (Part I) Hrvrd University CS Fll 2, Shimon Schocken Virtul Mchine (Prt I) Elements of Computing Systems Virtul Mchine I (Ch. 7) Motivtion clss clss Min Min sttic sttic x; x; function function void void min() min()

More information

If you are at the university, either physically or via the VPN, you can download the chapters of this book as PDFs.

If you are at the university, either physically or via the VPN, you can download the chapters of this book as PDFs. Lecture 5 Wlks, Trils, Pths nd Connectedness Reding: Some of the mteril in this lecture comes from Section 1.2 of Dieter Jungnickel (2008), Grphs, Networks nd Algorithms, 3rd edition, which is ville online

More information

CSEP 501 Compilers. Languages, Automata, Regular Expressions & Scanners Hal Perkins Winter /8/ Hal Perkins & UW CSE B-1

CSEP 501 Compilers. Languages, Automata, Regular Expressions & Scanners Hal Perkins Winter /8/ Hal Perkins & UW CSE B-1 CSEP 501 Compilers Languages, Automata, Regular Expressions & Scanners Hal Perkins Winter 2008 1/8/2008 2002-08 Hal Perkins & UW CSE B-1 Agenda Basic concepts of formal grammars (review) Regular expressions

More information

Algorithm Design (5) Text Search

Algorithm Design (5) Text Search Algorithm Design (5) Text Serch Tkshi Chikym School of Engineering The University of Tokyo Text Serch Find sustring tht mtches the given key string in text dt of lrge mount Key string: chr x[m] Text Dt:

More information

CSEP 573 Artificial Intelligence Winter 2016

CSEP 573 Artificial Intelligence Winter 2016 CSEP 573 Artificil Intelligence Winter 2016 Luke Zettlemoyer Problem Spces nd Serch slides from Dn Klein, Sturt Russell, Andrew Moore, Dn Weld, Pieter Abbeel, Ali Frhdi Outline Agents tht Pln Ahed Serch

More information

Outline. Introduction Suffix Trees (ST) Building STs in linear time: Ukkonen s algorithm Applications of ST

Outline. Introduction Suffix Trees (ST) Building STs in linear time: Ukkonen s algorithm Applications of ST Suffi Trees Outline Introduction Suffi Trees (ST) Building STs in liner time: Ukkonen s lgorithm Applictions of ST 2 3 Introduction Sustrings String is ny sequence of chrcters. Sustring of string S is

More information

Alignment of Long Sequences. BMI/CS Spring 2012 Colin Dewey

Alignment of Long Sequences. BMI/CS Spring 2012 Colin Dewey Alignment of Long Sequences BMI/CS 776 www.biostt.wisc.edu/bmi776/ Spring 2012 Colin Dewey cdewey@biostt.wisc.edu Gols for Lecture the key concepts to understnd re the following how lrge-scle lignment

More information

Dynamic Programming. Andreas Klappenecker. [partially based on slides by Prof. Welch] Monday, September 24, 2012

Dynamic Programming. Andreas Klappenecker. [partially based on slides by Prof. Welch] Monday, September 24, 2012 Dynmic Progrmming Andres Klppenecker [prtilly bsed on slides by Prof. Welch] 1 Dynmic Progrmming Optiml substructure An optiml solution to the problem contins within it optiml solutions to subproblems.

More information

ON THE DEHN COMPLEX OF VIRTUAL LINKS

ON THE DEHN COMPLEX OF VIRTUAL LINKS ON THE DEHN COMPLEX OF VIRTUAL LINKS RACHEL BYRD, JENS HARLANDER Astrct. A virtul link comes with vriety of link complements. This rticle is concerned with the Dehn spce, pseudo mnifold with oundry, nd

More information