7. Theory of Computation. Regular Expressions. Introduction to Theoretical CS. Why Learn Theory?

Size: px
Start display at page:

Download "7. Theory of Computation. Regular Expressions. Introduction to Theoretical CS. Why Learn Theory?"

Transcription

1 Introduction to Theoreticl CS 7. Theory of Computtion Q. Wht cn computer do? Q. Wht cn computer do with limited resources? Generl pproch. Don't tlk out specific mchines or prolems. Consider miniml strct mchines. Consider generl clsses of prolems. e.g., Intel Core 2 Duo running Linux kernel 2.6 Pioneering work in the 1930s. Princeton == center of universe. Automt, lnguges, computility, universlity, complexity, logic. Introduction to Computer Science Roert Sedgewick nd Kevin Wyne Copyright 2008 * * Dvid Hilert Kurt Gödel Aln Turing Alonzo Church John von eumnn 2 Why Lern Theory? In theory Deeper understnding of wht is computer nd computing. Foundtion of ll modern computers. Pure science. Philosophicl implictions. Regulr Expressions In prctice We serch: theory of pttern mtching. Sequentil circuits: theory of finite stte utomt. Compilers: theory of context free grmmrs. Cryptogrphy: theory of computtionl complexity. Dt compression: theory of informtion. In theory there is no difference etween theory nd prctice. In prctice there is. Yogi Berr 3

2 Descriing Pttern Pttern Mtching Applictions PROSITE. Huge dtse of protein fmilies nd domins. Q. How to descrie protein motif? Ex. [signture of the C 2 H 2 -type zinc finger domin] C Between 2 nd 4 mino cids. C 3 more mino cids. One of the following mino cids: LIVMFYWCX. 8 more mino cids. H Between 3 nd 5 more mino cids. H Test if string mtches some pttern. Process nturl lnguge. Scn for virus signtures. Access informtion in digitl lirries. Serch-nd-replce in word processors. Filter text (spm, etnny, ds, Crnivore, mlwre). Vlidte dt-entry fields (dtes, emil, URL, credit crd). Serch for mrkers in humn genome using PROSITE ptterns. Prse text files. Compile Jv progrm. Crwl nd index the We. Red in dt stored in TOY input file formt. Automticlly crete Jv documenttion from Jvdoc comments. CAASCGGPYACGGWAGYHAGWH 5 6 Regulr Expressions: Bsic Opertions Regulr Expressions: Exmples Regulr expression. ottion to specify set of strings. Regulr expression. ottion is surprisingly expressive. opertion regulr expression mtches does not mtch regulr expression mtches does not mtch conctention every other string.*sp.* contins the trigrph sp rsperry crispred suspce suspecies wildcrd union closure.u.u.u. * cumulus jugulum succuus tumultuous every other string * (****)* multiple of three s.*0... fifth to lst digit is prentheses ( ) ()* every other string gcg(cgg gg)*ctg frgile X syndrome indictor gcgctg gcgcggctg gcgcggggctg gcgcgg cggcggcggctg gcgcggctg 7 8

3 Generlized Regulr Expressions Regulr Expressions in Jv Regulr expressions re stndrd progrmmer's tool. Built in to Jv, Perl, Unix, Python,. Additionl opertions typiclly dded for convenience. Ex: [-e]+ is shorthnd for ( c d e)( c d e)*. opertion regulr expression mtches does not mtch Vlidity checking. Is input in the set descried y the re? pulic clss Vlidte { pulic sttic void min(string[] rgs) { String re = rgs[0]; String input = rgs[1]; StdOut.println(input.mtches(re)); powerful string lirry method one or more chrcter clss (c)+de [A-Z-z][-z]* cde ccde lowercse Cpitlized de cde cmelcse 4illegl C 2 H 2 type zinc finger domin % jv Vlidte "C.{2,4C...[LIVMFYWC].{8H.{3,5H" CAASCGGPYACGGAAGYHAGAH true legl Jv identifier exctly k negtion [0-9]{5-[0-9]{4 [^eiou]{ rhythm decde % jv Vlidte "[$_A-Z-z][$_A-Z-z0-9]*" ident123 true vlid emil ddress (simplified) % jv Vlidte "[-z]+@([-z]+\.)+(edu com)" wyne@cs.princeton.edu true need quotes to "escpe" the shell 9 10 String Serching Methods String Serching Methods pulic clss String (Jv's String lirry) pulic clss String (Jv's String lirry) oolen mtches(string re) does this string mtch the given regulr expression oolen mtches(string re) does this string mtch the given regulr expression String replceall(string re, String str) replce ll occurrences of regulr expression with the replcement string String replceall(string re, String str) replce ll occurrences of regulr expression with the replcement string int indexof(string r, int from) return the index of the first occurrence of the string r fter the index from int indexof(string r, int from) return the index of the first occurrence of the string r fter the index from String[] split(string re) split the string round mtches of the given regulr expression String[] split(string re) split the string round mtches of the given regulr expression String s = StdIn.redAll(); s = s.replceall("\\s+", " "); replce ll sequences of whitespce chrcters with single spce String s = StdIn.redAll(); String[] words = s.split("\\s+"); crete rry of words in document regulr expression tht mtches ny whitespce chrcter 11 12

4 Solving the Pttern Mtch Prolem DFAs Regulr expressions re concise wy to descrie ptterns. How would you implement the method mtches()? Hrdwre: uild deterministic finite stte utomton (DFA). Softwre: simulte DFA. DFA: simple mchine tht solves pttern mtch prolem. Different mchine for ech pttern. Accepts or rejects string specified on input tpe. Focus on true or flse questions for simplicity. 14 Deterministic Finite Stte Automton (DFA) DFA nd RE Dulity Simple mchine with sttes. Begin in strt stte. Red first input symol. Move to new stte, depending on current stte nd input symol. Repet until lst input symol red. Accept input string if lst stte is leled Y. RE. Concise wy to descrie set of strings. DFA. Mchine to recognize whether given string is in given set. Dulity. For ny DFA, there exists RE tht descries the sme set of strings; for ny RE, there exists DFA tht recognizes the sme set. Y * (****)* DFA Y multiple of 3 's multiple of 3 's Input Prcticl consequence of dulity proof: to mtch RE, (i) uild DFA nd (ii) simulte DFA on input string

5 Implementing Pttern Mtcher Appliction: Hrvester Prolem. Given RE, crete progrm tht tests whether given input is in set of strings descried. Step 1. Build the DFA. A compiler! See COS 226 or COS 320. Step 2. Simulte it with given input. Hrvest informtion from input strem. Hrvest ptterns from DA. % jv Hrvester "gcg(cgg gg)*ctg" chromosomex.txt gcgcggcggcggcggcggctg gcgctg gcgctg gcgcggcggcggggcggggcggctg Stte stte = strt; while (!StdIn.isEmpty()) { chr c = StdIn.redChr(); stte = stte.next(c); StdOut.println(stte.ccept()); Hrvest emil ddresses from we for spm cmpign. % jv Hrvester "[-z]+@([-z]+\.)+(edu com)" rs@cs.princeton.edu mi@cs.princeton.edu doug@cs.princeton.edu wyne@cs.princeton.edu Appliction: Hrvester Hrvest informtion from input strem. Use Pttern dt type to compile regulr expression to FA. Use Mtcher dt type to simulte FA. import jv.util.regex.pttern; import jv.util.regex.mtcher; pulic clss Hrvester { pulic sttic void min(string[] rgs) { String re = rgs[0]; In in = new In(rgs[1]); String input = in.redall(); Pttern pttern = Pttern.compile(re); Mtcher mtcher = pttern.mtcher(input); look for next mtch while (mtcher.find()) { StdOut.println(mtcher.group()); the mtch most recently found equivlent, ut more efficient representtion of DFA crete FA from RE crete FA simultor Appliction: Prsing Dt File Ex: prsing n CBI genome dt file. LOCUS AC p DA liner HTG 13-OV-2003 DEFIITIO Ornithorhynchus ntinus clone CLM1-393H9, ACCESSIO AC VERSIO AC GI: KEYWORDS HTG; HTGS_PHASE2; HTGS_DRAFT. SOURCE Ornithorhynchus ntinus (pltypus) ORIGI 1 tgttttct ttgccgtgc tgttttttcc cggtttttc gtcggtgtt ggggccc 61 gtgttctgt ttgtttttg ctgccgt gctgctcgt gtctctgc tgcgct // comment 121 gccgcggg gtgcc gtttgtgtg ctgt gggctgt ttcttct ggtgcg ccccccgct tgtcgc ttctttgt tg line numers spces the DA heder info comments 19 20

6 Appliction: Prsing Dt File Regulr Expressions Ex: prsing n CBI genome dt file. String re = "[ ]*[0-9]+([ctg ]*).*"; Pttern pttern = Pttern.compile(re); In in = new In(filenme); while (!in.isempty()) { String line = in.redline(); Mtcher mtcher = pttern.mtcher(line); if (mtcher.find()) { String s = mtcher.group(1).replceall(" ", ""); // do something with s extrct the prt of mtch in prens LOCUS AC p DA liner HTG 13-OV-2003 DEFIITIO Ornithorhynchus ntinus clone CLM1-393H9, ACCESSIO AC VERSIO AC GI: KEYWORDS HTG; HTGS_PHASE2; HTGS_DRAFT. SOURCE Ornithorhynchus ntinus (pltypus) ORIGI 1 tgttttct ttgccgtgc tgttttttcc cggtttttc gtcggtgtt ggggccc 61 gtgttctgt ttgtttttg ctgccgt gctgctcgt gtctctgc tgcgct // comment 121 gccgcggg gtgcc gtttgtgtg ctgt gggctgt ttcttct ggtgcg ccccccgct tgtcgc ttctttgt tg Summry Fundmentl Questions Progrmmer. Regulr expressions re powerful pttern mtching tool. Implement regulr expressions with finite stte mchines. Theoreticin. RE is compct description of set of strings. DFA is n strct mchine tht solves RE pttern mtch prolem. You. Prcticl ppliction of core CS principles. Q. Are there ptterns tht cnnot e descried y ny RE/DFA? A. Yes. Bit strings with equl numer of 0s nd 1s. Deciml strings tht represent prime numers. DA strings tht re Wtson-Crick complemented plindromes. Q. Cn we extend RE/DFA to descrie richer ptterns? A. Yes. Context free grmmr (e.g., Jv). Turing mchines

Lecture 18: Theory of Computation

Lecture 18: Theory of Computation Introduction to Theoreticl CS ecture 18: Theory of Computtion Two fundmentl questions. Wht cn computer do? Wht cn computer do with limited resources? Generl pproch. Pentium IV running inux kernel.4. Don't

More information

Introduction to Theoretical CS

Introduction to Theoretical CS 3/5/1 7: Theory of Computtion Introduction to Theoreticl CS Two fundmentl questions. Wht cn computer do? (the most fundmentl question) Wht cn computer do with limited resources? (more prcticl) Pentium

More information

Pattern Matching. exact pattern matching Knuth-Morris-Pratt RE pattern matching grep

Pattern Matching. exact pattern matching Knuth-Morris-Pratt RE pattern matching grep Pttern Mtching exct pttern mtching Knuth-Morris-Prtt RE pttern mtching grep exct pttern mtching Knuth-Morris-Prtt RE pttern mtching grep References: Algorithms in C (nd edition), Chpter 9 (pdf online)

More information

7. Theory of Computation

7. Theory of Computation 7. Theory of Computation Introduction to Programming in Java: An Interdisciplinary Approach Robert Sedgewick and Kevin Wayne Copyright 2002 2010 4/11/11 7:44 AM Introduction to Theoretical CS Q. What can

More information

7. Theory of Computation

7. Theory of Computation 7. Theory of Computation 1 Introduction to Theoretical CS Why Learn Theory? Q. What can a computer do? Q. What can a computer do with limited resources? General approach. Don't talk about specific machines

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

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

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

7. Introduction to Theoretical CS. Regular Expressions. Introduction to Theoretical CS. Why Learn Theory?

7. Introduction to Theoretical CS. Regular Expressions. Introduction to Theoretical CS. Why Learn Theory? Introduction to Theoretical CS 7. Introduction to Theoretical CS Q. What can a computer do? Q. What can a computer do with limited resources? General approach. Don't talk about specific machines or problems.

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

Introduction to Theoretical Computer Science

Introduction to Theoretical Computer Science Introduction to Theoretical Computer Science Introduction to Theoretical CS Fundamental questions: Q. What can a computer do? Q. What can a computer do with limited resources? General approach. Don't talk

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

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

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

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

Regular Expressions. Why Learn Theory? !! Fundamental questions: Q. What can a computer do? Q. What can a computer do with limited resources?

Regular Expressions. Why Learn Theory? !! Fundamental questions: Q. What can a computer do? Q. What can a computer do with limited resources? Introduction to Theoretical Computer Science Introduction to Theoretical CS Fundamental questions: Q. What can a computer do? Q. What can a computer do with limited resources? General approach. Don't talk

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

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

Introduction to Theoretical CS. Regular Expressions. Why Learn Theory? Why Learn Theory?

Introduction to Theoretical CS. Regular Expressions. Why Learn Theory? Why Learn Theory? Why Learn Theory? Introduction to Theoretical CS Fundamental questions: Q. What can a computer do? Q. What can a computer do with limited resources? General approach. Don't talk about specific machines

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

String Searching. String Search. Applications. Brute Force: Typical Case

String Searching. String Search. Applications. Brute Force: Typical Case String Serch String Serching String serch. Given pttern string p, find first mtch in text t. Model. Cn't fford to preprocess the text. Prmeters. N = length of text, M = length of pttern. typiclly N >>

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

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

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

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

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

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

Systems I. Logic Design I. Topics Digital logic Logic gates Simple combinational logic circuits

Systems I. Logic Design I. Topics Digital logic Logic gates Simple combinational logic circuits Systems I Logic Design I Topics Digitl logic Logic gtes Simple comintionl logic circuits Simple C sttement.. C = + ; Wht pieces of hrdwre do you think you might need? Storge - for vlues,, C Computtion

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Computer Science. 14. Introduction to Theoretical CS. Computer Science. Overview Regular expressions DFAs Applications. Limitations COMPUTER SCIENCE

Computer Science. 14. Introduction to Theoretical CS. Computer Science. Overview Regular expressions DFAs Applications. Limitations COMPUTER SCIENCE PA R T I I : A L G O R I T H M S, M A C H I N E S, a n d T H E O R Y PA R T I I : A L G O R I T H M S, M A C H I N E S, a n d T H E O R Y Computer Science 14. Introduction to Theoretical CS Computer Science

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

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

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

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

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

Computer Science. 14. Introduction to Theoretical CS. Computer Science COMPUTER SCIENCE. Section 7.2.

Computer Science. 14. Introduction to Theoretical CS. Computer Science COMPUTER SCIENCE. Section 7.2. COMPUTER SCIENCE S E D G E W I C K / W A Y N E PA R T I I : A L G O R I T H M S, M A C H I N E S, a n d T H E O R Y Computer Science Computer Science An Interdisciplinary Approach Section 7.2 ROBERT SEDGEWICK

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

CIS 1068 Program Design and Abstraction Spring2015 Midterm Exam 1. Name SOLUTION

CIS 1068 Program Design and Abstraction Spring2015 Midterm Exam 1. Name SOLUTION CIS 1068 Progrm Design nd Astrction Spring2015 Midterm Exm 1 Nme SOLUTION Pge Points Score 2 15 3 8 4 18 5 10 6 7 7 7 8 14 9 11 10 10 Totl 100 1 P ge 1. Progrm Trces (41 points, 50 minutes) Answer the

More information

A Tautology Checker loosely related to Stålmarck s Algorithm by Martin Richards

A Tautology Checker loosely related to Stålmarck s Algorithm by Martin Richards A Tutology Checker loosely relted to Stålmrck s Algorithm y Mrtin Richrds mr@cl.cm.c.uk http://www.cl.cm.c.uk/users/mr/ University Computer Lortory New Museum Site Pemroke Street Cmridge, CB2 3QG Mrtin

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

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

Discussion 1 Recap. COP4600 Discussion 2 OS concepts, System call, and Assignment 1. Questions. Questions. Outline. Outline 10/24/2010

Discussion 1 Recap. COP4600 Discussion 2 OS concepts, System call, and Assignment 1. Questions. Questions. Outline. Outline 10/24/2010 COP4600 Discussion 2 OS concepts, System cll, nd Assignment 1 TA: Hufeng Jin hj0@cise.ufl.edu Discussion 1 Recp Introduction to C C Bsic Types (chr, int, long, flot, doule, ) C Preprocessors (#include,

More information

CS 112 Introduction to Programming

CS 112 Introduction to Programming A Foundtion for Progrmming CS 112 Introduction to Progrmming (Spring 212) ny progrm you might wnt to write Lecture #18: Using Dt Types crete your own dt types objects Zhong Sho functions nd modules Deprtment

More information

Automata Processor. Tobias Markus Computer Architecture Group, University of Heidelberg

Automata Processor. Tobias Markus Computer Architecture Group, University of Heidelberg 1 Automt Processor Tobis Mrkus Computer Architecture Group, University of Heidelberg Abstrct This pper gives brief overview over nondeterministic utomt nd the Automt Processor n rchitecture implemented

More information

The dictionary model allows several consecutive symbols, called phrases

The dictionary model allows several consecutive symbols, called phrases A dptive Huffmn nd rithmetic methods re universl in the sense tht the encoder cn dpt to the sttistics of the source. But, dpttion is computtionlly expensive, prticulrly when k-th order Mrkov pproximtion

More information

Outline. Two combinatorial optimization problems in machine learning. Talk objectives. Grammar induction. DFA induction.

Outline. Two combinatorial optimization problems in machine learning. Talk objectives. Grammar induction. DFA induction. Outline Two comintoril optimiztion prolems in mchine lerning Pierre.Dupont@uclouvin.e 1 Feture selection ICTEAM Institute Université ctholique de Louvin Belgium My 1, 011 P. Dupont (UCL Mchine Lerning

More information

Allocator Basics. Dynamic Memory Allocation in the Heap (malloc and free) Allocator Goals: malloc/free. Internal Fragmentation

Allocator Basics. Dynamic Memory Allocation in the Heap (malloc and free) Allocator Goals: malloc/free. Internal Fragmentation Alloctor Bsics Dynmic Memory Alloction in the Hep (mlloc nd free) Pges too corse-grined for llocting individul objects. Insted: flexible-sized, word-ligned blocks. Allocted block (4 words) Free block (3

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

3.1 Using Data Types. A Foundation for Programming. Objects. Data Type. Object. Holds a data type value; variable name refers to object.

3.1 Using Data Types. A Foundation for Programming. Objects. Data Type. Object. Holds a data type value; variable name refers to object. A Foundtion for Progrmming 3.1 Using Dt Types ny progrm you might wnt to write objects crete your own dt types functions nd modules grphics, sound, nd imge I/O rrys conditionls nd loops Mth primitive dt

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

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

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

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

Compression Outline :Algorithms in the Real World. Lempel-Ziv Algorithms. LZ77: Sliding Window Lempel-Ziv

Compression Outline :Algorithms in the Real World. Lempel-Ziv Algorithms. LZ77: Sliding Window Lempel-Ziv Compression Outline 15-853:Algorithms in the Rel World Dt Compression III Introduction: Lossy vs. Lossless, Benchmrks, Informtion Theory: Entropy, etc. Proility Coding: Huffmn + Arithmetic Coding Applictions

More information