2014 Haskell January Test Regular Expressions and Finite Automata

Size: px
Start display at page:

Download "2014 Haskell January Test Regular Expressions and Finite Automata"

Transcription

1 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 for the best ttempt(s) t Prt IV. Credit will be wrded throughout for clrity, conciseness, useful commenting nd the pproprite use of Hskell s vrious lnguge fetures nd predefined functions. WARNING: The exmples nd test cses here re not gurnteed to exercise ll spects of your code. You my therefore wish to define your own tests to complement the ones provided.

2 Introduction Regulr expressions, or regexes, re used to describe serch ptterns in text processing pplictions. Exmples of their use include Linux s grep filter utility, text editors like vim nd emcs nd lso progrmming lnguges like Ruby, Jv nd, of course, Hskell! This exercise ims to explore some of the lgorithms nd dt structures trditionlly ssocited with regulr expression implementtions. Regulr Expressions For the purposes of this exercise regulr expression is defined recursively to be either:. A terminl chrcter tht defines pttern tht mtches only tht chrcter in given input string. For exmple the expression defines pttern tht mtches only the string "".. A sequence of two juxtposed regulr expressions. For exmple, the regulr expression b comprises two terminls, nd b, in sequence nd this defines pttern tht will mtch only the string "b". Note tht prentheses cn optionlly be used to brcket subterms of regulr expression in the usul wy, nd tht, for exmple, (bc), (b)c nd bc ll represent the sme expression (i.e. sequencing is ssocitive). 3. An lterntive, written (e e ) where e nd e re regulr expressions. For exmple, the expression (b c) defines pttern tht mtches either the string "b" or the string "c". Note tht the opertor is ssocitive nd commuttive, so the expressions ( bb c), (c (bb )) nd (( c) bb) ll define the sme mtching pttern. In this exercise we will lwys enclose lterntive expressions in prentheses.. A repetition ( Kleene str ) of zero or more occurrences of given expression, e sy, written e. For exmple, b c defines pttern tht mtches the chrcter followed by zero or more occurrences of the chrcter b followed by single occurrence of the chrcter c. 5. A repetition (Kleene plus) of one or more occurrences of given expression, e, written e +. For exmple, b + c defines pttern tht mtches the string "bbbc", but not "c", s there must be t lest one b following the initil. 6. An optionl occurrence of given expression, e, written e?. For exmple, (b)?d + defines pttern tht mtches the strings "d", "dd", "bd", "bdd" nd so on. 7. The null expression, which mtches only the empty string (""). For exmple, the expression ( ) defines pttern tht mtches the strings "" nd "" only. A common convention is to denote null expressions explicitly by the specil symbol ɛ, s in ( ɛ) for exmple, nd this ide will feture lter on in Section 3. Some more exmples of regulr expressions nd mtching/non-mtching strings re shown in Tble. If regulr expression e defines pttern tht mtches string s then we sy tht e ccepts s. For exmple, the expression (b c) ccepts the strings "", "c", "bbbccb" etc., s shown in the tble. Nmed fter the Americn mthemticin Stephen Cole Kleene.

3 Regex Mtching string exmples Non-mtching string exmples (x y)( ) "x" "x" "y" "x3" x "x" "y" "x " " " "x " "x x" (b c) "" "d" "c" "c" "bbbccb" "cccb" ( ) "" "b" "" "" (b)?d + "d" "b" "bd" "bd" "bddd" "bbd" Tble : Some regulr expressions nd exmples of mtching/non-mtching strings. Simplifiction Rules The + nd? opertors re, in fct, unnecessry nd cn expressed in terms of the other opertors vi the identities: for ll expressions e.. Representtion e + ee e? (e ) Regulr expressions, s described bove, cn be implemented in Hskell vi the following dt type: dt RE = Null -- Null expression Term Chr -- Terminl Seq RE RE -- Sequence Alt RE RE -- Alterntion Rep RE -- Repetition (*) Plus RE -- Repitition (+) Opt RE -- Optionl expression (?) deriving (Eq, Show) Tble gives some exmples of regulr expressions whose representtions re defined in the templte file for testing purposes. You re now in position to nswer the questions in Prt I. You my wish to complete these before reding on. 3

4 Regex Representtion Templte vrible (x y)( ) Seq (Alt (Term x ) (Term y )) (Alt (Term ) (Term )) re x Seq (Term x ) (Rep (Term )) re (b c) Rep (Alt (Seq (Term ) (Term b )) (Term c )) re3 ( ) Seq (Alt (Term ) Null) (Term ) re (b)?d + Seq (Opt (Seq (Term ) (Term b ))) (Plus (Term d )) re5 Tble : Exmple representtions defined in the templte 3 Non-deterministic Automt A key property of regulr expressions is tht the ptterns they define cn be described by Non- Deterministic (Finite) Automton, or NDA, which is n exmple of lbelled stte trnsition system with finite number of sttes. An exmple NDA for the regulr expression ( b) c (refigure in the templte) is shown in Figure b c Figure : NDA for ( b) c An NDA hs unique strt stte (stte in Figure ) nd unique ccepting stte, which we will lso refer to s the terminl stte, which is shown s double circle (stte in Figure ). The sequence of non- trnsition lbels visited on pth through the NDA from the strt stte to the ccepting stte defines string tht is ccepted by, i.e. cn be mtched by, the regulr expression. There my be mny such pths, indeed possibly infinitely mny, nd these collectively determine the set of strings tht re ccepted by the regulr expression. A trnsition lbelled with the specil symbol corresponds to null regulr expression nd cn be trversed unconditionlly; indeed, if there re multiple -lbelled trnsitions out of stte then ny of them my led to successful mtch, so ech, in principle, must be explored non-deterministiclly. The choice of which pth to tke is clled non-deterministic becuse we don t know in dvnce which one (if ny) will led to successful mtch in the worst cse, we my hve to try them ll. The strings ccepted by the NDA of Figure re precisely those defined by the corresponding regulr expression ( b) c, e.g. "c" (vi the pth Recll from Section tht null expressions re often denoted explicitly by the symbol ɛ, hence the nme used here.

5 ), "bc" (pth ), "c" (pth ) nd so on. Turning things round, we cn sk whether given input string will be ccepted by n NDA by using the individul chrcters of tht string to fire the non- trnsitions in the NDA, beginning from the strt stte. If ll the chrcters of the input string hve been used up nd it is possible to rech the ccepting stte unconditionlly from the current stte then the input string is ccepted by the NDA. If not, or if we rech point where no trnsitions cn fire, then the string is rejected. For exmple, the strings "c", "bc", "c" etc. will ll be ccepted. However, "cc" will be rejected, becuse we will rech the terminl stte with the second c left unused. For the string "d" the will fire the trnsition from 7 to 8 but none of the successor trnsitions (sttes, 7 nd 8) re lbelled with d, so this will lso be rejected. Note tht in regulr expression cretes cycle in the corresponding NDA. For exmple, in Figure the in ( b) c is implemented vi the bckwrd trnsition from stte 6 to 5. Note lso tht the short-circuit trnsition from to 3 llows the NDA to ccept or b zero times, s required. Remrk: The NDAs shown here re not necessrily optiml, but re shown here s generted by the NDA construction lgorithm tht you will be implementing lter on. 3. Representtion An utomton cn be described using the following Hskell dt types: type Stte = Int dt Lbel = C Chr deriving (Eq, Ord, Show) type Trnsition = (Stte, Stte, Lbel) type Automton = (Stte, [Stte], [Trnsition]) Sttes re lbelled with unique integer identifiers. A trnsition comprises source stte, trget stte nd lbel, which is either (unconditionl trnsition) or of the form C c where c is chrcter. An utomton is 3-tuple comprising, in order:. The (unique) strt stte. The list of terminl sttes 3. The list of trnsitions Note: Although n NDA hs only one terminl stte, in generl n utomton cn hve mny, s we shll see in Prt IV. As n exmple, the NDA of Figure (ndfigure in the templte) will be represented by: (,[],[(,3,),(,5,),(3,,),(,,C c ),(5,7,), (5,9,),(6,3,),(6,5,),(7,8,C ),(8,6,), (9,0,C b ),(0,6,)]) nd tht of x (nd in the templte) by: 5

6 (,[],[(,3,C x ),(3,,),(,,),(,5,),(5,6,C \ ), (6,,),(6,5,)]) The order in which the sttes, terminls nd trnsitions re listed is not significnt, lthough we lwys disply ech of them sorted lexicogrphiclly. The NDAs for the exmples given in Tble re shown grphiclly in Tble 3. Note tht the NDA for (b)?d + corresponds to the simplified version of the expression in which the + nd? hve been removed, viz. (b )dd. Wht to do There re four prts to this test nd most of the mrks re for Prts I III. Prt IV is worth only two of the 5 mrks vilble nd is hrd, so you re dvised to ttempt it only when you hve completed Prts I III. The exmple expressions referred to bove, (re, re,...) nd their corresponding NDAs, (nd, nd,...), re included in the templte for testing purposes. There re lso some exmples of so-clled deterministic utomt (d, d,...) ech of which hs the sme structure s non-deterministic utomton, but with possibly more thn one terminl stte. These feture in Prt IV but re still useful elsewhere for testing purposes. A function showre :: RE -> String is lso defined in the templte for testing purposes; this produces compct textul representtion of given RE. For exmple, showre re5, where re5 is Seq (Opt (Seq (Term ) (Term b ))) (Plus (Term d )), produces "(b)?d+".. Prt I: Bsics. Define function: lookup :: Eq => -> [(, b)] -> b tht will look up given item in list of item/vlue pirs, delivering the corresponding vlue. A precondition is tht there is exctly one occurrence of the item in the list. [ mrk]. Define function simplify :: RE -> RE tht will remove ny + or? expressions using the simplifiction rules in Section.. For exmple, showre (simplify re5) should produce "(b )dd*".. Prt II: Functions on NDAs. Define the following three functions for indexing utomt: strtstte :: Automton -> Stte terminlsttes :: Automton -> [Stte] trnsitions :: Automton -> [Trnsition] [3 mrks] tht will return respectively the strt stte, the list of terminl sttes nd the list of trnsitions in given utomton. For exmple, terminlsttes nd should return []. Use these wherever you see fit in the questions tht follow. [ mrk] 6

7 Regex (x y)( ) NDA 5 7 x y x x 3 5 ' 6 (b c) c 8 0 b 6 ( ɛ) (b)?d b 6 3 d 3 d Tble 3: NDAs for the regulr expressions in Tble 7

8 . Define function isterminl :: Stte -> Automton -> Bool tht delivers true iff the given stte is terminl (ccepting) stte in the given utomton. For exmple, isterminl nd nd isterminl 3 d should both return True nd isterminl 5 nd should return Flse. [ mrk] 3. Define function trnsitionsfrom :: Stte -> Automton -> [Trnsition] tht returns the list of trnsitions emnting from given stte in given utomton. For exmple the ppliction trnsitionsfrom 5 ndfigure should return [(5,7,),(5,9,)] nd trnsitionsfrom 0 nd3 should return [(0,6,C b )]. If the stte doesn t pper in the tomton then the result should be []. [ mrks]. Define function lbels :: [Trnsition] -> [Lbel] tht returns the lbels in the given list of trnsitions, with no duplictes. Any trnsitions should be excluded from the result. For exmple, lbels [(,,)] should return [] nd lbels (trnsitions nd3) should return [C,C c,c b ]. Hint: use nub from Dt.List to remove ny duplictes. [ mrk] 5. Define function ccepts :: Automton -> String -> Bool tht returns True iff the given utomton ccepts the given input string using the so-clled bcktrcking pproch, which is described below. Note tht this is not the most efficient wy to solve the problem, but it is the simplest. Acceptnce testing using bcktrcking [6 mrks] The ide is to try to mtch ll possible pths from given stte ginst the given input string. If ny of them succeeds then the string is ccepted. To implement this, define helper function, ccepts :: Stte -> String -> Bool, tht tkes the current stte, s sy, (initilly the unique strt stte) nd the string we re trying to mtch (initilly the input string), nd does the following: If the stte is terminl stte nd the string is null then the string is ccepted, i.e. there re no unmtched chrcters left. Use the isterminl function defined erlier nd the null function from the prelude. Otherwise, you need to use the trnsitionsfrom function to get the list of trnsitions emnting from s nd then try ech of them looking for mtch; this is the non-deterministic bit. The mtch succeeds if ny of these pths leds to the string being ccepted; conversely, it fils if the string is rejected by every pth followed. To implement this prt of the solution it is suggested, lthough not required, tht you define nother helper function try :: String -> Trnsition -> Bool tht tries out one such trnsition using the following rules: If the trnsition is lbelled with n with trget stte t then you simply continue the process from stte t by invoking ccepts recursively; the string is unchnged. 8

9 If the trnsition is lbelled with chrcter, c sy, with trget stte t, then you need to exmine the input string (use pttern mtching!). If the string is empty then the mtch fils t this point nd we bort (return Flse). If it is non-empty then look t the item t the hed, c sy. If c == c then you continue by invoking ccepts on the til of the string strting with stte t; otherwise the mtch hs gin filed t this point nd you return Flse..3 Prt III: Constructing n NDA Define function mkenda :: RE -> Automton tht will generte n NDA from given regulr expression. There is simple lgorithm for doing this which you should try to follow exctly, in order to simplify testing nd mrking. We strt with the top-level function, which is provided in the templte thus: mkenda :: RE -> Automton mkenda re = (, [], sort trnsitions) where (trnsitions, k) = mke (simplify re) 3 Your job is to define the function mke, which hs type mke :: RE -> Int -> Int -> Int -> ([Trnsition], Int) In ddition to the expression we re converting, the function tkes three integers, m, n nd k sy, in tht order. The ide is to construct n NDA which strts in the stte numbered m nd ends in the stte numbered n. The k represents the next vilble identifier tht cn be used to number ny dditionl sttes. The top-level cll defines the strt stte of the finl NDA to be nd the end stte to be, but this is just convention NDAs in generl cn hve rbitrry strt nd terminl sttes. Becuse this is the top level, must therefore be the unique terminting stte for the whole NDA, hence the [] in the resulting 3-tuple. Becuse stte identifiers nd hve been used, the next vilble identifier is 3, hence the fourth prmeter to mke. The trnsitions returned by mke re sorted lexicogrphiclly, using the sort function imported from the module Dt.List, in order to help with testing nd mrking. To mke the NDA for given regulr expression you simply put together nodes nd trnsitions ccording to the rules defined in Figure. The dotted lines indicte where the NDAs for ny subexpressions should be plced; these sub-ndas will be built recursively. As n exmple, given n expression Seq r r you recursively mke the NDA for r with strt nd end sttes m nd k respectively, then do the sme for r with strt nd end sttes k+ nd n respectively. You then dd one dditionl trnsition lbelled between sttes k nd k+ nd you re done. You hve to be creful to mintin the next vilble stte identifier t ech point: mking the NDA for r my consume n rbitrry number of such identifiers, for exmple. However, it tells you which ones it used s prt of its return vlue, whose type is (([Trnsition], Int). The Int here is the next vilble identifier, hving built the entire sub-nda for re, s represented by the list of trnsitions. The ide is then to use this s the k prmeter when mking the NDA for r. Once you see how this works for sequences, very similr rules pply for the other two recursive cses. The bse cses re simple. The result in ech cse is single trnsition ppropritely lbelled nd the next vilble stte identifier is the one we strted with, s no dditionl nodes re required. 9

10 m n m C c n () Null nd terminl cses: nd C c m r goes here k k+ r goes here n (b) Sequence: Seq r r k r goes here k+ m k+ r goes here k+3 n (c) Alterntive: Alt r r r goes here m k k+ n (d) Repetition: Rep r Figure : Rules for constructing n NDA If you follow the stte numbering scheme exctly s described then you should be ble to reproduce the NDAs for ech exmple expression in the templte. For exmple mkenda re should yield, idelly exctly, if not the equivlent of, nd, i.e. (,[],[(,3,C x ),(3,,),(,,),(,5,),(5,6,C \ ), (6,,),(6,5,)]) 0

11 You cn test the bses cses seprtely, e.g. mkenda (Term x ) should yield the 3-tuple (,[],[(,,C x )]), or the equivlent. Note tht n exct reproduction isn t necessry to get the mrks, however; wht mtters is whether the NDA does the right thing. [8 mrks] 5 Prt IV: Deterministic Finite Automt The finl prt of this exercise invites you to remove the trnsitions in the NDAs from Prt III, generting Deterministic Automton, or DA, where the next trnsition, if one is possible, is uniquely determined by the trnsition lbels. To illustrte wht you need to chieve, Tble shows the deterministic equivlents of the NDAs in Tble 3. These DAs re defined in the templte nd cn be used for testing. There re severl wys of building DA from n NDA. The lgorithm below explins the generl ide, together with detils of prticulr pproch, superset construction, tht flls out elegntly in Hskell tht you my wish to follow. Feel free to try different pproch, however, if you think you hve better ide! However you do it, the objective is to define function mkeda :: Automton -> Automton tht converts n NDA into DA. Note tht the representtions of both NDAs nd DAs re the sme. The functions you defined erlier will thus work eqully well on both. Trnslting n NDA into DA The ide is for the sttes of the DA, the so-clled metsttes, to correspond to sets of sttes in the originl NDA. The first objective is to compute the list of metsttes nd trnsitions representing the DA, together with the root (strt) metstte. Then ll you need to do is mp metsttes into ordinry, integer-lbelled, sttes nd determine the set of terminl sttes there my be more thn one. The suggestion is tht you mke the list of new metsttes nd new trnsitions ccumulting prmeters of helper function. The lgorithm then proceeds s follows: We work with input sets of sttes from the originl NDA, represented s lists, beginning with the singleton set contining just the strt stte, e.g. [] if the strt stte is. Now compute the frontier of the NDA, which is the list of non- trnsitions tht cn be reched by following trnsitions s fr s possible, strting from ech stte in the input set. If the frontier reches the terminl stte then the specil phntom trnsition (t, t, ) should be included in the list returned (see below). In order to void the need to do explicit cycle detection we ll ssume precondition tht ny cycle in the NDA must include t lest one non- trnsition it will if the NDA hs been built s described erlier. For exmple, the frontier of the NDA for (b c), i.e. nd3, strting from input stte set [], is [(,,),(5,9,C ),(7,8,C c )]. In generl there my be severl sttes in the input set, so simply conctente the frontiers for ech of them together. The recommendtion is tht you define function getfrontier :: Stte -> Automton -> [Trnsition] for clculting frontiers s described. The type signture for this function is provided in the templte. The set of unique source sttes of ech trnsition in the frontier defines new metstte, which will be ssocited with stte in the DA being constructed. For exmple, the metstte for the frontier bove will be [,5,7]. Note the role of the phntom trnsition: this

12 metstte will (lter) be mrked s terminl stte becuse it contins - the unique terminl stte in this prticulr NDA. Hint: use nub nd sort imported from Dt.List to ensure tht the metstte identifiers re uniquely determined by the originl stte identifiers they contin. If the metstte hs been visited before then return immeditely s we ve reched stte tht we ve seen before: the root is the metstte nd the ccumulted lists of metsttes nd trnsitions re unchnged. Otherwise, group the frontier trnsitions by trnsition lbel there my be severl trnsitions with the sme lbel nd these need to be combined (see below). If the frontier contins the specil phntom trnsition then this should be removed t this point. In the exmple bove the grouped trnsitions will be [(C,[9]),(C c,[8])] s the lbels re unique. However, the frontier of the NDA for ( ) from stte contins two trnsitions, i.e. [(3,7,C ),(5,9,C )], so these will be grouped thus: [(C,[7,9])]. The recommendtion is tht you use the lbels function defined erlier to define function grouptrnsitions :: [Trnsition] -> [(Lbel, [Stte])] to group trnsitions s described, mking sure tht the sttes in the list ([Stte]) re unique. The type signture for this function is provided in the templte. Hints: use list comprehension nd notice tht the lbels function will conveniently remove the phntom trnsition utomticlly, if it is present, becuse it is n trnsition. You now dd the new metstte, m sy, to the ccumulted list of metsttes nd recursively visit ech trget node set, dding one new trnsition to the ccumulted trnsitions list fter ech recursive cll. For exmple, if the grouped trnsitions re [(C,[5,6,7]),(C c,[8,9])] you recurse with the stte sets (lists) [5,6,7] nd [8,9], mintining the list of new metsttes nd trnsitions s you go ( fold?!). If the first of these genertes the root r, nd trnsition nd metstte lists ts nd ms respectively, then you dd one new trnsition of the form (m, r, C ) to ts before recursing gin on the stte list [8,9] nd doing likewise. If you choose to follow the lgorithm s described you my like to use the following function types defined in the templte: type MetStte = [Stte] type MetTrnsition = (MetStte, MetStte, Lbel) mkeda :: Automton -> Automton -- Suggested helper function for mkeda... mkeda :: [Stte] -> [MetStte] -> [MetTrnsition] -> (MetStte, [MetStte], [MetTrnsition]) The second nd third prmeters of mkeda, nd similrly the result tuple, re the ccumulting prmeters suggested. Good luck! [ mrks]

13 Regex (x y)( ) DA x y 3 x ' x (b c) c b ( ɛ) 3 (b)?d + d 3 d b d Tble : DAs for the exmples in Tble 3

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

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

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

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

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

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

ΕΠΛ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

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

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

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

Topic 2: Lexing and Flexing

Topic 2: Lexing and Flexing Topic 2: Lexing nd Flexing COS 320 Compiling Techniques Princeton University Spring 2016 Lennrt Beringer 1 2 The Compiler Lexicl Anlysis Gol: rek strem of ASCII chrcters (source/input) into sequence of

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

Section 3.1: Sequences and Series

Section 3.1: Sequences and Series Section.: Sequences d Series Sequences Let s strt out with the definition of sequence: sequence: ordered list of numbers, often with definite pttern Recll tht in set, order doesn t mtter so this is one

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

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

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

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

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

Mid-term exam. Scores. Fall term 2012 KAIST EE209 Programming Structures for EE. Thursday Oct 25, Student's name: Student ID:

Mid-term exam. Scores. Fall term 2012 KAIST EE209 Programming Structures for EE. Thursday Oct 25, Student's name: Student ID: Fll term 2012 KAIST EE209 Progrmming Structures for EE Mid-term exm Thursdy Oct 25, 2012 Student's nme: Student ID: The exm is closed book nd notes. Red the questions crefully nd focus your nswers on wht

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

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

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

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

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

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

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

Stack. A list whose end points are pointed by top and bottom

Stack. A list whose end points are pointed by top and bottom 4. Stck Stck A list whose end points re pointed by top nd bottom Insertion nd deletion tke plce t the top (cf: Wht is the difference between Stck nd Arry?) Bottom is constnt, but top grows nd shrinks!

More information

COMPUTER SCIENCE 123. Foundations of Computer Science. 6. Tuples

COMPUTER SCIENCE 123. Foundations of Computer Science. 6. Tuples COMPUTER SCIENCE 123 Foundtions of Computer Science 6. Tuples Summry: This lecture introduces tuples in Hskell. Reference: Thompson Sections 5.1 2 R.L. While, 2000 3 Tuples Most dt comes with structure

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

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

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

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

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

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

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

MATH 25 CLASS 5 NOTES, SEP

MATH 25 CLASS 5 NOTES, SEP MATH 25 CLASS 5 NOTES, SEP 30 2011 Contents 1. A brief diversion: reltively prime numbers 1 2. Lest common multiples 3 3. Finding ll solutions to x + by = c 4 Quick links to definitions/theorems Euclid

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

Eliminating left recursion grammar transformation. The transformed expression grammar

Eliminating left recursion grammar transformation. The transformed expression grammar Eliminting left recursion grmmr trnsformtion Originl! rnsformed! 0 0! 0 α β α α α α α α α α β he two grmmrs generte the sme lnguge, but the one on the right genertes the rst, nd then string of s, using

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

Functor (1A) Young Won Lim 8/2/17

Functor (1A) Young Won Lim 8/2/17 Copyright (c) 2016-2017 Young W. Lim. Permission is grnted to copy, distribute nd/or modify this document under the terms of the GNU Free Documenttion License, Version 1.2 or ny lter version published

More information

Midterm 2 Sample solution

Midterm 2 Sample solution Nme: Instructions Midterm 2 Smple solution CMSC 430 Introduction to Compilers Fll 2012 November 28, 2012 This exm contins 9 pges, including this one. Mke sure you hve ll the pges. Write your nme on the

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

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

Homework. Context Free Languages III. Languages. Plan for today. Context Free Languages. CFLs and Regular Languages. Homework #5 (due 10/22)

Homework. Context Free Languages III. Languages. Plan for today. Context Free Languages. CFLs and Regular Languages. Homework #5 (due 10/22) Homework Context Free Lnguges III Prse Trees nd Homework #5 (due 10/22) From textbook 6.4,b 6.5b 6.9b,c 6.13 6.22 Pln for tody Context Free Lnguges Next clss of lnguges in our quest! Lnguges Recll. Wht

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

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

Functor (1A) Young Won Lim 10/5/17

Functor (1A) Young Won Lim 10/5/17 Copyright (c) 2016-2017 Young W. Lim. Permission is grnted to copy, distribute nd/or modify this document under the terms of the GNU Free Documenttion License, Version 1.2 or ny lter version published

More information

MA1008. Calculus and Linear Algebra for Engineers. Course Notes for Section B. Stephen Wills. Department of Mathematics. University College Cork

MA1008. Calculus and Linear Algebra for Engineers. Course Notes for Section B. Stephen Wills. Department of Mathematics. University College Cork MA1008 Clculus nd Liner Algebr for Engineers Course Notes for Section B Stephen Wills Deprtment of Mthemtics University College Cork s.wills@ucc.ie http://euclid.ucc.ie/pges/stff/wills/teching/m1008/ma1008.html

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

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

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

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

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

File Manager Quick Reference Guide. June Prepared for the Mayo Clinic Enterprise Kahua Deployment

File Manager Quick Reference Guide. June Prepared for the Mayo Clinic Enterprise Kahua Deployment File Mnger Quick Reference Guide June 2018 Prepred for the Myo Clinic Enterprise Khu Deployment NVIGTION IN FILE MNGER To nvigte in File Mnger, users will mke use of the left pne to nvigte nd further pnes

More information

Problem Set 2 Fall 16 Due: Wednesday, September 21th, in class, before class begins.

Problem Set 2 Fall 16 Due: Wednesday, September 21th, in class, before class begins. Problem Set 2 Fll 16 Due: Wednesdy, September 21th, in clss, before clss begins. 1. LL Prsing For the following sub-problems, consider the following context-free grmmr: S T$ (1) T A (2) T bbb (3) A T (4)

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

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

12-B FRACTIONS AND DECIMALS

12-B FRACTIONS AND DECIMALS -B Frctions nd Decimls. () If ll four integers were negtive, their product would be positive, nd so could not equl one of them. If ll four integers were positive, their product would be much greter thn

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

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

Unit #9 : Definite Integral Properties, Fundamental Theorem of Calculus

Unit #9 : Definite Integral Properties, Fundamental Theorem of Calculus Unit #9 : Definite Integrl Properties, Fundmentl Theorem of Clculus Gols: Identify properties of definite integrls Define odd nd even functions, nd reltionship to integrl vlues Introduce the Fundmentl

More information

Misrepresentation of Preferences

Misrepresentation of Preferences Misrepresenttion of Preferences Gicomo Bonnno Deprtment of Economics, University of Cliforni, Dvis, USA gfbonnno@ucdvis.edu Socil choice functions Arrow s theorem sys tht it is not possible to extrct from

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

6.2 Volumes of Revolution: The Disk Method

6.2 Volumes of Revolution: The Disk Method mth ppliction: volumes by disks: volume prt ii 6 6 Volumes of Revolution: The Disk Method One of the simplest pplictions of integrtion (Theorem 6) nd the ccumultion process is to determine so-clled volumes

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

Lecture 10 Evolutionary Computation: Evolution strategies and genetic programming

Lecture 10 Evolutionary Computation: Evolution strategies and genetic programming Lecture 10 Evolutionry Computtion: Evolution strtegies nd genetic progrmming Evolution strtegies Genetic progrmming Summry Negnevitsky, Person Eduction, 2011 1 Evolution Strtegies Another pproch to simulting

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

Control-Flow Analysis and Loop Detection

Control-Flow Analysis and Loop Detection ! Control-Flow Anlysis nd Loop Detection!Lst time! PRE!Tody! Control-flow nlysis! Loops! Identifying loops using domintors! Reducibility! Using loop identifiction to identify induction vribles CS553 Lecture

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

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

Epson Projector Content Manager Operation Guide

Epson Projector Content Manager Operation Guide Epson Projector Content Mnger Opertion Guide Contents 2 Introduction to the Epson Projector Content Mnger Softwre 3 Epson Projector Content Mnger Fetures... 4 Setting Up the Softwre for the First Time

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

INTRODUCTION TO SIMPLICIAL COMPLEXES

INTRODUCTION TO SIMPLICIAL COMPLEXES INTRODUCTION TO SIMPLICIAL COMPLEXES CASEY KELLEHER AND ALESSANDRA PANTANO 0.1. Introduction. In this ctivity set we re going to introduce notion from Algebric Topology clled simplicil homology. The min

More information

1 Quad-Edge Construction Operators

1 Quad-Edge Construction Operators CS48: Computer Grphics Hndout # Geometric Modeling Originl Hndout #5 Stnford University Tuesdy, 8 December 99 Originl Lecture #5: 9 November 99 Topics: Mnipultions with Qud-Edge Dt Structures Scribe: Mike

More information

Spring 2018 Midterm Exam 1 March 1, You may not use any books, notes, or electronic devices during this exam.

Spring 2018 Midterm Exam 1 March 1, You may not use any books, notes, or electronic devices during this exam. 15-112 Spring 2018 Midterm Exm 1 Mrch 1, 2018 Nme: Andrew ID: Recittion Section: You my not use ny books, notes, or electronic devices during this exm. You my not sk questions bout the exm except for lnguge

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

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

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

9 4. CISC - Curriculum & Instruction Steering Committee. California County Superintendents Educational Services Association

9 4. CISC - Curriculum & Instruction Steering Committee. California County Superintendents Educational Services Association 9. CISC - Curriculum & Instruction Steering Committee The Winning EQUATION A HIGH QUALITY MATHEMATICS PROFESSIONAL DEVELOPMENT PROGRAM FOR TEACHERS IN GRADES THROUGH ALGEBRA II STRAND: NUMBER SENSE: Rtionl

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

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

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

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

Fall 2018 Midterm 2 November 15, 2018

Fall 2018 Midterm 2 November 15, 2018 Nme: 15-112 Fll 2018 Midterm 2 November 15, 2018 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

Scanning Theory and Practice

Scanning Theory and Practice CHAPTER 3 Scnning Theory nd Prctice 3.1 Overview The primry function of scnner is to red in chrcters from source file nd group them into tokens. A scnner is sometimes clled lexicl nlyzer or lexer. The

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

Slides for Data Mining by I. H. Witten and E. Frank

Slides for Data Mining by I. H. Witten and E. Frank Slides for Dt Mining y I. H. Witten nd E. Frnk Simplicity first Simple lgorithms often work very well! There re mny kinds of simple structure, eg: One ttriute does ll the work All ttriutes contriute eqully

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

such that the S i cover S, or equivalently S

such that the S i cover S, or equivalently S MATH 55 Triple Integrls Fll 16 1. Definition Given solid in spce, prtition of consists of finite set of solis = { 1,, n } such tht the i cover, or equivlently n i. Furthermore, for ech i, intersects i

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

1. SEQUENCES INVOLVING EXPONENTIAL GROWTH (GEOMETRIC SEQUENCES)

1. SEQUENCES INVOLVING EXPONENTIAL GROWTH (GEOMETRIC SEQUENCES) Numbers nd Opertions, Algebr, nd Functions 45. SEQUENCES INVOLVING EXPONENTIAL GROWTH (GEOMETRIC SEQUENCES) In sequence of terms involving eponentil growth, which the testing service lso clls geometric

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

Engineer To Engineer Note

Engineer To Engineer Note Engineer To Engineer Note EE-186 Technicl Notes on using Anlog Devices' DSP components nd development tools Contct our technicl support by phone: (800) ANALOG-D or e-mil: dsp.support@nlog.com Or visit

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

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

Digital Design. Chapter 6: Optimizations and Tradeoffs

Digital Design. Chapter 6: Optimizations and Tradeoffs Digitl Design Chpter 6: Optimiztions nd Trdeoffs Slides to ccompny the tetbook Digitl Design, with RTL Design, VHDL, nd Verilog, 2nd Edition, by Frnk Vhid, John Wiley nd Sons Publishers, 2. http://www.ddvhid.com

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

Lists in Lisp and Scheme

Lists in Lisp and Scheme Lists in Lisp nd Scheme Lists in Lisp nd Scheme Lists re Lisp s fundmentl dt structures, ut there re others Arrys, chrcters, strings, etc. Common Lisp hs moved on from eing merely LISt Processor However,

More information

CSCI 104. Rafael Ferreira da Silva. Slides adapted from: Mark Redekopp and David Kempe

CSCI 104. Rafael Ferreira da Silva. Slides adapted from: Mark Redekopp and David Kempe CSCI 0 fel Ferreir d Silv rfsilv@isi.edu Slides dpted from: Mrk edekopp nd Dvid Kempe LOG STUCTUED MEGE TEES Series Summtion eview Let n = + + + + k $ = #%& #. Wht is n? n = k+ - Wht is log () + log ()

More information

pdfapilot Server 2 Manual

pdfapilot Server 2 Manual pdfpilot Server 2 Mnul 2011 by clls softwre gmbh Schönhuser Allee 6/7 D 10119 Berlin Germny info@cllssoftwre.com www.cllssoftwre.com Mnul clls pdfpilot Server 2 Pge 2 clls pdfpilot Server 2 Mnul Lst modified:

More information