CSE 401 Compilers. Agenda. Lecture 4: Implemen:ng Scanners Michael Ringenburg Winter 2013
|
|
- Vernon Flowers
- 5 years ago
- Views:
Transcription
1 CSE 401 Compilers Leture 4: Implemen:ng Snners Mihel Ringenurg Winter 013 Winter 013 UW CSE 401 (Mihel Ringenurg) Agend Lst week we overed regulr expressions nd finite utomt. Tody, we ll finish our finl exmple (NFA to DFA onversion) nd then tlk out how snners re implemented. Wednesdy, we ll egin our disussion of prsing. Winter 013 UW CSE 401 (Mihel Ringenurg) 1
2 Announements Prt 1 of the projet (the snner) will e relesed tomorrow morning. If you or your prtner hven t emiled the ourse stff to let us know your tem, do so TODAY. If you hven t een le to find prtner, emil me nd I ll pir you up with someone else who hsn t. You n lso hek the disussion ord there hve een few posts y people looking for prtners. We urrently hve n even numer of students (54), so everyone should e le to hve prtner. Winter 013 UW CSE 401 (Mihel Ringenurg) 3 Convert NFA to DFA: Exmple Step 1: Find losure of strt stte: {1,,5} Winter 013 UW CSE 401 (Mihel Ringenurg) 4
3 Convert NFA to DFA: Exmple {1,,5} Step : Mke new DFA stte orresponding to this losure. Mrk it s unvisited (yellow in this digrm). Winter 013 UW CSE 401 (Mihel Ringenurg) 5 Convert NFA to DFA: Exmple {1,,5}??? Loop: As long s there re unvisited DFA nodes, pik one. Consider trnsi:ons from its orresponding NFA sttes for every symol in the lphet. Winter 013 UW CSE 401 (Mihel Ringenurg) 6 3
4 Convert NFA to DFA: Exmple {3} {1,,5}?? Only trnsi:on on from 1,, or 5 is to 3. Winter 013 UW CSE 401 (Mihel Ringenurg) 7 Convert NFA to DFA: Exmple {1,,5}? {3}? losure of {3} is just 3 (no trnsi:ons), so {1,,5} trnsi:ons to {3} on. This DFA stte does not exist yet, so mke it nd mrk it unvisited. Winter 013 UW CSE 401 (Mihel Ringenurg) 8 4
5 Convert NFA to DFA: Exmple {3} {1,,5}? No trnsi:ons from 1,, or 5 on symol. Winter 013 UW CSE 401 (Mihel Ringenurg) 9 Convert NFA to DFA: Exmple {1,,5} {3} {6} Only trnsi:on from 1,, or 5 on is to 6. Winter 013 UW CSE 401 (Mihel Ringenurg) 10 5
6 Convert NFA to DFA: Exmple {1,,5} {3} {6,7} Epsilon losure of {6} is {6,7}, so {1,,5} trnsi:ons to {6,7} on. This doesn t exist, so rete nd mrk unvisited. Winter 013 UW CSE 401 (Mihel Ringenurg) 11 Convert NFA to DFA: Exmple {1,,5} {3} {6,7} Done with {1,,5}. Mrk s visited (lk in our digrm). Winter 013 UW CSE 401 (Mihel Ringenurg) 1 6
7 Convert NFA to DFA: Exmple {3} {4,7} {1,,5} {6,7} Repet for nother unvisited node ({3}). Cretes {4,7}. Winter 013 UW CSE 401 (Mihel Ringenurg) 13 Convert NFA to DFA: Exmple {3} {4,7} {1,,5} {6,7} Repet for unvisited node ({4,7}). No trnsi:ons. Winter 013 UW CSE 401 (Mihel Ringenurg) 14 7
8 Convert NFA to DFA: Exmple {3} {4,7} {1,,5} {6,7} Repet for unvisited node {6,7}. No trnsi:ons. Winter 013 UW CSE 401 (Mihel Ringenurg) 15 Convert NFA to DFA: Exmple {3} {4,7} {1,,5} {6,7} No more unvisited nodes. Mrk s finl ll sttes whih inlude n NFA finl stte in their set. Winter 013 UW CSE 401 (Mihel Ringenurg) 16 8
9 Building Snner We ve seen the theory (RE to NFA to DFA), ut how is this onverted to pr:e? A snner needs to tke n input strem nd onvert it to tokens. Following the longest mth priniple i.e., uild the longest legl token str:ng t the urrent input posi:on. Then repet. Generl ide: Crete n RE for every token type. E.g., n RE for +, nd RE for integers, et. Build DFA for the union of the REs Modify DFA implement:on to reognize the longest mthing sustring (rther thn only ep:ng the whole string). This is some:mes free/unneessry for ertin DFAs Repetedly invoke (typilly y the prser to otin next token). Winter 013 UW CSE 401 (Mihel Ringenurg) 17 Snning DFA How does this modified DFA work? Must not just ept, ut ept nd tell us whih RE generted the string (i.e., whih token we found). Iden:fy the token y the finl stte we end in. Wht if our DFA finl stte orresponds to mul:ple REs from the originl? This n hppen if text mthes mul'ple tokens. E.g., for my mth the for keyword RE nd the iden:fier RE. Compiler writer must define priority order (e.g., keywords > IDs). Must lso find longest mth my get this for free If needed, run DFA un:l no more trnsi:ons. If not in finl stte, ktrk to lst seen finl stte. Not lwys neessry. Winter 013 UW CSE 401 (Mihel Ringenurg) 18 9
10 Punng it together A snner is DFA tht finds the next token eh :me it is lled (nd dvnes the input pointer to the token s end). Every finl stte of DFA emits (returns) token. For exmple: == eomes <equl> (not <ssign> <ssign>) ( eomes <leqpren> privte eomes <privte> Compiler writer (you) hoose the token nmes Also, there my e ddi:onl dt ssoited with tokens \r\n might ount lines; ll tokens might inlude line #; integer literls inlude vlue; et. Winter 013 UW CSE 401 (Mihel Ringenurg) 19 DFA => Code, y Hnd Op:on 1: One proedure per DFA stte Reds in hrter, nd uses swith sttement to determine the next stte to ll Finl sttes return token. Op:ons : Single proedure for DFA, swith sed on first hrter We ll see n exmple of this in few slides. Pros Firly strighvorwrd to write. If wriwen well, n e fster thn generted snners (pr:ulrly op:on ). Cn hndle ny weird lnguge orner ses tht don t mp perfetly to the RE/NFA/DFA model. Redle ode (mostly). Cons A lot of tedious work thus, error prone. Winter 013 UW CSE 401 (Mihel Ringenurg) 0 10
11 DFA => ode, utom: Op:on 1: use tool to generte tle driven snner Rows: sttes of DFA Columns: input hrters Entries: :on Go to next stte Aept token, go to strt stte Error Pros Convenient just feed it the token regulr expressions Extly mthes speifi:on you give it, if tool orret Cons Mgi Some:mes lnguge onstruts don t mp perfetly to FA model Not effiient Winter 013 UW CSE 401 (Mihel Ringenurg) 1 DFA => ode, utom: Op:on : use tool to generte diret- oded snner Trnsi:ons emedded in the ode, using ondi:onl sttements, loops, possily goto Pros Convenient just feed it the REs Extly mthes speifi:on you give it, if tool orret More effiient thn tle driven snners Cons Mgi Code is unredle Genertes lots of ode (ut n e firly fst) Winter 013 UW CSE 401 (Mihel Ringenurg) 11
12 The Rel World In ommeril senngs (nd most g front ends) hnd wriwen snners used more oqen thn not. Espeilly for lrger lnguges, e.g., C++/Jv. Cn purhse, e.g., EDG C/C++ front end (used y Cry, Intel, others). Why? Fstest Cn hndle lnguge orner ses C++ espeilly d. Redle/deuggle ode. Winter 013 UW CSE 401 (Mihel Ringenurg) 3 Exmple: A hnd- wriwen DFA nd snner To demonstrte, we ll show hnd- wriwen DFA for some typil progrmming lnguge onstruts Then use to onstrut hnd- wriwen snner Senng: Snner is lled whenever the prser needs new token Snner stores urrent posi:on in input From there, use DFA to reognize the longest possile input sequene tht mkes up token nd return tht token; sve updted posi:on for next :me Dislimer: Exmple for illustr:on only you ll use tools for the ourse projet. Credit: Hl Perkins wrote this DFA nd ode. Winter 013 UW CSE 401 (Mihel Ringenurg) 4 1
13 Snner DFA Exmple (1) 0 whitespe or omments Advne to end of whitespe nd/or omment efore we egin snning the next token. Comments n use DFA or simple proedure. end of input ( ) ; Aept EOF Aept LPAREN Aept RPAREN Aept SCOLON No other tokens strt with ny of these hrters. Thus no trnsi:ons out of these finl sttes. If we do this everywhere, no need for ktrking. Effiient Winter 013 UW CSE 401 (Mihel Ringenurg) 5 Snner DFA Exmple () 5 = 6 Aept NEQ < 8 [other ] = 7 9 Aept NOT, don t dvne input pointer Aept LEQ One gin, no need for trnsi:ons out of finl sttes. [other ] 10 Aept LESS, don t dvne input pointer Winter 013 UW CSE 401 (Mihel Ringenurg) 6 13
14 Snner DFA Exmple (3) [0-9] 11 [0-9] [other ] 1 Aept INT, don t dvne Only integers in this lnguge. Winter 013 UW CSE 401 (Mihel Ringenurg) 7 Snner DFA Exmple (4) [-za-z] 13 [-za-z0-9_] [other ] Aept ID or keyword, don t dvne Strtegies for hndling iden:fiers vs keywords Hnd- wriwen snner: look up iden:fiers in tle of keywords (good ppli:on of perfet hshing i.e., given knowledge of keys hed of :me, n ensure no ollisions.) Mhine- generted snner: generte DFA with pproprite trnsi:ons to reognize keywords (> priority thn IDs). 14 Winter 013 UW CSE 401 (Mihel Ringenurg) 8 14
15 Bktrking As we sw, ktrking is not neessry in our DFA. More effiient In mny ses, token syntx n e hosen (nd DFA onstruted refully) suh tht ktrking is rre (or n e voided en:rely). Esier to ensure this hppens in hnd- wriwen snner Prt of why well- wri3en hnd- wriwen snners re the most effiient. Winter 013 UW CSE 401 (Mihel Ringenurg) 9 Implemen:ng Snner y Hnd Token Represent:on A token is simple, tgged struture (Compilers wriwen in C/C++ oqen use tgged union style struture) puli lss Token { puli int kind; // token s lexil lss puli int intvl;// integer vlue if lss = INT puli String id;// tul identifier if lss = ID // lexil lsses puli stti finl int EOF = 0; // end of file // token puli stti finl int ID = 1; // identifier, // not keyword puli stti finl int INT = ; // integer puli stti finl int LPAREN = 4; // ( puli stti finl int SCOLN = 5; // ; puli stti finl int WHILEK = 6; // ) // et. et. et. Winter 013 UW CSE 401 (Mihel Ringenurg) 30 15
16 Simple Snner Exmple // glol stte nd methods // next unproessed input hrter stti hr nexth; // dvne to next input hr void geth() { } // skip whitespe nd omments void skipwhitespe() { } // input is letter, digit, or _ oolen isidchr(hr ); Winter 013 UW CSE 401 (Mihel Ringenurg) 31 Snner gettoken() method // Clled y prser to retrieve the next input token puli Token gettoken() { Token result; skipwhitespe(); if (/*no more input*/) { result = new Token(Token.EOF); return result; } swith(nexth) { se '(': result = new Token(Token.LPAREN); geth(); return result; se )': result = new Token(Token.RPAREN); geth(); return result; se ;': result = new Token(Token.SCOLON); geth(); return result; // Repet for other single hrter tokens Winter 013 UW CSE 401 (Mihel Ringenurg) 3 16
17 gettoken() () se '': // or = geth(); if (nexth == '=') { result = new Token(Token.NEQ); geth(); return result; } else { result = new Token(Token.NOT); return result; } se '<': // < or <= geth(); if (nexth == '=') { result = new Token(Token.LEQ); geth(); return result; } else { result = new Token(Token.LESS); return result; } Winter 013 UW CSE 401 (Mihel Ringenurg) 33 gettoken() (3) se '0': se '1': se '': se '3': se '4': se '5': se '6': se '7': se '8': se '9': // integer onstnt String num = nexth; geth(); while (Chrter.isdigit(nexth)) { num = num + nexth; geth(); } result = new Token(Token.INT, Integer(num).intVlue()); return result; Winter 013 UW CSE 401 (Mihel Ringenurg) 34 17
18 gettoken() (4) se '': se 'z': se 'A': se 'Z': // id or keyword string s = nexth; geth(); while (isidchr(nexth)) // letter, digit, _ { s = s + nexth; geth(); } if (keywordtle.iskeyword(s)) { result = new Token(keywordTle.getKind(s)); } else { result = new Token(Token.ID, s); } return result; Winter 013 UW CSE 401 (Mihel Ringenurg) 35 MiniJv Snner Gener:on We ll use the JFlex tool to utom:lly rete snner from speifi:on file. We ll use the CUP tool to utom:lly rete prser from speifi:on file. Token lss is shred y jflex nd CUP. Lexil lsses (token kinds) re listed in CUP s input file nd it genertes the token lss defini:on. So you ll need to modify oth speifi:on files for the snner por:on of your projet Prser mods will e smll. Winter 013 UW CSE 401 (Mihel Ringenurg) 36 18
19 JFlex Speifi:on Exmple Open sr/snner/minijv.jflex in your projet strter ode. You ll see tht few tokens hve lredy een done for you, to demonstrte how it works, e.g.: "+" { return symol(sym.plus); } {letter} ({letter} {digit} _)* { return symol(sym.identifier, yytext()); } Formt is Token RE, followed y ode to exeute. Cn define helper revi:ons, e.g.: letter = [-za-z] digit = [0-9] Winter 013 UW CSE 401 (Mihel Ringenurg) 37 Speifying the tokens Tokens re speified in the CUP file sr/prser/minijv.up /* Terminls (tokens returned y the snner) */ /* reserved words: */ terminl DISPLAY; /* opertors: */ terminl PLUS, BECOMES; /* delimiters: */ terminl LPAREN, RPAREN, SEMICOLON; /* tokens with vlues: */ terminl String IDENTIFIER; Winter 013 UW CSE 401 (Mihel Ringenurg) 38 19
20 JFlex Demo Your projet strter ode hs few tokens defined lredy. We ll dd mul:pli:on. Winter 013 UW CSE 401 (Mihel Ringenurg) 39 Coming Awr:ons Str:ng next leture: prsing Will do LR prsing first we need this for the projet, then LL (reursive- desent) prsing, whih you should lso know. My tke the rest of Jnury it s ig topi Se:ons more detils out using JFlex for your projet. The full detils n e found in the JFlex nd CUP doument:on. Winter 013 UW CSE 401 (Mihel Ringenurg) 40 0
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 informationCS 241 Week 4 Tutorial Solutions
CS 4 Week 4 Tutoril Solutions Writing n Assemler, Prt & Regulr Lnguges Prt Winter 8 Assemling instrutions utomtilly. slt $d, $s, $t. Solution: $d, $s, nd $t ll fit in -it signed integers sine they re 5-it
More informationFig.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 informationCS321 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 informationIn 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 informationCSEP 501 Compilers. Languages, Automata, Regular Expressions & Scanners Hal Perkins Winter /8/ Hal Perkins & UW CSE B-1
CSEP 501 Compilers Languages, Automata, Regular Expressions & Scanners Hal Perkins Winter 2008 1/8/2008 2002-08 Hal Perkins & UW CSE B-1 Agenda Basic concepts of formal grammars (review) Regular expressions
More informationCOMP 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 informationLanguages, Automata, Regular Expressions & Scanners. Winter /8/ Hal Perkins & UW CSE B-1
CSE 401 Compilers Languages, Automata, Regular Expressions & Scanners Hal Perkins Winter 2010 1/8/2010 2002-10 Hal Perkins & UW CSE B-1 Agenda Quick review of basic concepts of formal grammars Regular
More informationΕΠΛ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ΕΠΛ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 informationPattern Matching. Pattern Matching. Pattern Matching. Review of Regular Expressions
Pttern Mthing Pttern Mthing Some of these leture slides hve een dpted from: lgorithms in C, Roert Sedgewik. Gol. Generlize string serhing to inompletely speified ptterns. pplitions. Test if string or its
More informationParadigm 5. Data Structure. Suffix trees. What is a suffix tree? Suffix tree. Simple applications. Simple applications. Algorithms
Prdigm. Dt Struture Known exmples: link tble, hep, Our leture: suffix tree Will involve mortize method tht will be stressed shortly in this ourse Suffix trees Wht is suffix tree? Simple pplitions History
More informationTopic 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 informationDefinition 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 informationCS412/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 informationCSE 401/M501 Compilers
CSE 401/M501 Compilers Languages, Automata, Regular Expressions & Scanners Hal Perkins Spring 2018 UW CSE 401/M501 Spring 2018 B-1 Administrivia No sections this week Read: textbook ch. 1 and sec. 2.1-2.4
More informationCompilers 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 informationImplementing 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 informationReducing 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 informationMidterm Exam CSC October 2001
Midterm Exm CSC 173 23 Otoer 2001 Diretions This exm hs 8 questions, severl of whih hve suprts. Eh question indites its point vlue. The totl is 100 points. Questions 5() nd 6() re optionl; they re not
More informationCMPUT101 Introduction to Computing - Summer 2002
CMPUT Introdution to Computing - Summer 22 %XLOGLQJ&RPSXWHU&LUFXLWV Chpter 4.4 3XUSRVH We hve looked t so fr how to uild logi gtes from trnsistors. Next we will look t how to uild iruits from logi gtes,
More informationLexical 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 informationCSE 413 Programming Languages & Implementation. Hal Perkins Autumn 2012 Grammars, Scanners & Regular Expressions
CSE 413 Programming Languages & Implementation Hal Perkins Autumn 2012 Grammars, Scanners & Regular Expressions 1 Agenda Overview of language recognizers Basic concepts of formal grammars Scanner Theory
More informationLexical 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 informationCS 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 informationLanguages. 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 informationCSc 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 informationCSCI 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 informationFinite 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 informationthis 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 informationTo access your mailbox from inside your organization. For assistance, call:
2001 Ative Voie, In. All rights reserved. First edition 2001. Proteted y one or more of the following United Sttes ptents:,070,2;,3,90;,88,0;,33,102;,8,0;,81,0;,2,7;,1,0;,90,88;,01,11. Additionl U.S. nd
More informationType Checking. Roadmap (Where are we?) Last lecture Context-sensitive analysis. This lecture Type checking. Symbol tables
Type Cheking Rodmp (Where re we?) Lst leture Contet-sensitie nlysis Motition Attriute grmmrs Ad ho Synt-direted trnsltion This leture Type heking Type systems Using synt direted trnsltion Symol tles Leil
More informationCS143 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 informationCS 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 informationECE 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 informationDr. 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 informationLexical 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 informationCS 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 informationStructure of a Typical Interpreter. Compiler. Scanning and Parsing. Lexical Analysis (Scanning) Interaction Between Scanning and Parsing
Snning nd Prsing Announements Projet 1 is 5% of totl grde Projet 2 is 10% of totl grde Projet 3 is 15% of totl grde Projet 4 is 10% of totl grde Tody Outline of plnned topis for ourse Overll struture of
More informationCSE 413 Programming Languages & Implementation. Hal Perkins Winter 2019 Grammars, Scanners & Regular Expressions
CSE 413 Programming Languages & Implementation Hal Perkins Winter 2019 Grammars, Scanners & Regular Expressions 1 Agenda Overview of language recognizers Basic concepts of formal grammars Scanner Theory
More informationCSE 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 informationCMSC 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 informationLR 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 informationCSc 453 Compilers and Systems Software. 6 : Top-Down Parsing I
C 45 Compilers n ystems oftwre 6 : op-down Prsing I Christin Collberg Deprtment of Computer iene University of rizon ollberg@gmil.om Copyright 2009 Christin Collberg eptember 14, 2009 1 Overview 2 Compiler
More informationCMPSC 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 informationCSE 401 Compilers. Languages, Automata, Regular Expressions & Scanners Hal Perkins Winter UW CSE 401 Winter 2015 B-1
CSE 401 Compilers Languages, Automata, Regular Expressions & Scanners Hal Perkins Winter 2015 UW CSE 401 Winter 2015 B-1 Administrivia Read: textbook ch. 1 and sec. 2.1-2.4 First homework: out by end of
More informationOutline. Motivation Background ARCH. Experiment Additional usages for Input-Depth. Regular Expression Matching DPI over Compressed HTTP
ARCH This work ws supported y: The Europen Reserh Counil, The Isreli Centers of Reserh Exellene, The Neptune Consortium, nd Ntionl Siene Foundtion wrd CNS-119748 Outline Motivtion Bkground Regulr Expression
More informationLesson 4.4. Euler Circuits and Paths. Explore This
Lesson 4.4 Euler Ciruits nd Pths Now tht you re fmilir with some of the onepts of grphs nd the wy grphs onvey onnetions nd reltionships, it s time to egin exploring how they n e used to model mny different
More informationLecture 8: Graph-theoretic problems (again)
COMP36111: Advned Algorithms I Leture 8: Grph-theoreti prolems (gin) In Prtt-Hrtmnn Room KB2.38: emil: iprtt@s.mn..uk 2017 18 Reding for this leture: Sipser: Chpter 7. A grph is pir G = (V, E), where V
More informationSome 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 informationOperator Precedence. Java CUP. E E + T T T * P P P id id id. Does a+b*c mean (a+b)*c or
Opertor Precedence Most progrmming lnguges hve opertor precedence rules tht stte the order in which opertors re pplied (in the sence of explicit prentheses). Thus in C nd Jv nd CSX, +*c mens compute *c,
More informationDeterministic. 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 informationLecture 12 : Topological Spaces
Leture 12 : Topologil Spes 1 Topologil Spes Topology generlizes notion of distne nd loseness et. Definition 1.1. A topology on set X is olletion T of susets of X hving the following properties. 1. nd X
More informationShould 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 informationGreedy Algorithm. Algorithm Fall Semester
Greey Algorithm Algorithm 0 Fll Semester Optimiztion prolems An optimiztion prolem is one in whih you wnt to fin, not just solution, ut the est solution A greey lgorithm sometimes works well for optimiztion
More informationCS 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 informationExample: 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 informationEnterprise Digital Signage Create a New Sign
Enterprise Digitl Signge Crete New Sign Intended Audiene: Content dministrtors of Enterprise Digitl Signge inluding stff with remote ess to sign.pitt.edu nd the Content Mnger softwre pplition for their
More information2 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 informationJava CUP. Java CUP Specifications. User Code Additions. Package and Import Specifications
Jv CUP Jv CUP is prser-genertion tool, similr to Ycc. CUP uilds Jv prser for LALR(1) grmmrs from production rules nd ssocited Jv code frgments. When prticulr production is recognized, its ssocited code
More informationCS553 Lecture Introduction to Data-flow Analysis 1
! Ide Introdution to Dt-flow nlysis!lst Time! Implementing Mrk nd Sweep GC!Tody! Control flow grphs! Liveness nlysis! Register llotion CS553 Leture Introdution to Dt-flow Anlysis 1 Dt-flow Anlysis! Dt-flow
More informationTroubleshooting. Verify the Cisco Prime Collaboration Provisioning Installation (for Advanced or Standard Mode), page
Trouleshooting This setion explins the following: Verify the Ciso Prime Collortion Provisioning Instlltion (for Advned or Stndrd Mode), pge 1 Upgrde the Ciso Prime Collortion Provisioning from Smll to
More informationCompiler 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 informationINTEGRATED WORKFLOW ART DIRECTOR
ART DIRECTOR Progrm Resoures INTEGRATED WORKFLOW PROGRAM PLANNING PHASE In this workflow phse proess, you ollorte with the Progrm Mnger, the Projet Mnger, nd the Art Speilist/ Imge Led to updte the resoures
More informationAssignment 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 informationFall 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 informationCS 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 informationScanner 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 informationFrom 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 informationIntroduction to Compilers and Language Design Copyright (C) 2017 Douglas Thain. All rights reserved.
Introdution to Compilers nd Lnguge Design Copyright (C) 2017 Dougls Thin. All rights reserved. Anyone is free to downlod nd print the PDF edition of this ook for personl use. Commeril distriution, printing,
More informationPrinciples of Programming Languages
Principles of Progrmming Lnguges h"p://www.di.unipi.it/~ndre/did2c/plp- 14/ Prof. Andre Corrdini Deprtment of Computer Science, Pis Lesson 5! Gener;on of Lexicl Anlyzers Creting Lexicl Anlyzer with Lex
More informationSystems 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 informationCS201 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 informationCS311H: 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 informationClass Overview. Database Design. Database Design Process. Database Design. Introduction to Data Management CSE 414
Introution to Dt Mngement CSE 44 Unit 6: Coneptul Design E/R Digrms Integrity Constrints BCNF Introution to Dt Mngement CSE 44 E/R Digrms ( letures) CSE 44 Autumn 08 Clss Overview Dtse Design Unit : Intro
More informationLecture 13: Graphs I: Breadth First Search
Leture 13 Grphs I: BFS 6.006 Fll 2011 Leture 13: Grphs I: Bredth First Serh Leture Overview Applitions of Grph Serh Grph Representtions Bredth-First Serh Rell: Grph G = (V, E) V = set of verties (ritrry
More informationLecture 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 information6.045J/18.400J: Automata, Computability and Complexity. Quiz 2: Solutions. Please write your name in the upper corner of each page.
6045J/18400J: Automt, Computbility nd Complexity Mrh 30, 2005 Quiz 2: Solutions Prof Nny Lynh Vinod Vikuntnthn Plese write your nme in the upper orner of eh pge Problem Sore 1 2 3 4 5 6 Totl Q2-1 Problem
More informationInternet Routing. IP Packet Format. IP Fragmentation & Reassembly. Principles of Internet Routing. Computer Networks 9/29/2014.
omputer Networks 9/29/2014 IP Pket Formt Internet Routing Ki Shen IP protool version numer heder length (words) for qulity of servie mx numer remining hops (deremented t eh router) upper lyer protool to
More informationAlgorithm 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 informationCompilation
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 information10.2 Graph Terminology and Special Types of Graphs
10.2 Grph Terminology n Speil Types of Grphs Definition 1. Two verties u n v in n unirete grph G re lle jent (or neighors) in G iff u n v re enpoints of n ege e of G. Suh n ege e is lle inient with the
More informationExample: 2:1 Multiplexer
Exmple: 2:1 Multiplexer Exmple #1 reg ; lwys @( or or s) egin if (s == 1') egin = ; else egin = ; 1 s B. Bs 114 Exmple: 2:1 Multiplexer Exmple #2 Normlly lwys include egin nd sttements even though they
More informationQuiz2 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 informationLists 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 informationHomework. 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 informationFall 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 informationTO 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 informationSection 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 informationRegistering as a HPE Reseller. Quick Reference Guide for new Partners in Asia Pacific
Registering s HPE Reseller Quick Reference Guide for new Prtners in Asi Pcific Registering s new Reseller prtner There re five min steps to e new Reseller prtner. Crete your Appliction Copyright 2017 Hewlett
More informationCS453 INTRODUCTION TO DATAFLOW ANALYSIS
CS453 INTRODUCTION TO DATAFLOW ANALYSIS CS453 Leture Register llotion using liveness nlysis 1 Introdution to Dt-flow nlysis Lst Time Register llotion for expression trees nd lol nd prm vrs Tody Register
More informationWhat 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 informationDistributed Systems Principles and Paradigms. Chapter 11: Distributed File Systems
Distriuted Systems Priniples nd Prdigms Mrten vn Steen VU Amsterdm, Dept. Computer Siene steen@s.vu.nl Chpter 11: Distriuted File Systems Version: Deemer 10, 2012 2 / 14 Distriuted File Systems Distriuted
More informationContext-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 informationShared Memory Architectures. Programming and Synchronization. Today s Outline. Page 1. Message passing review Cosmic Cube discussion
Tody s Outline Arhitetures Progrmming nd Synhroniztion Disuss pper on Cosmi Cube (messge pssing) Messge pssing review Cosmi Cube disussion > Messge pssing mhine Shred memory model > Communition > Synhroniztion
More informationTable-driven look-ahead lexical analysis
Tle-riven look-he lexil nlysis WUU YANG Computer n Informtion Siene Deprtment Ntionl Chio-Tung University, HsinChu, Tiwn, R.O.C. Astrt. Moern progrmming lnguges use regulr expressions to efine vli tokens.
More informationToday. CS 188: Artificial Intelligence Fall Recap: Search. Example: Pancake Problem. Example: Pancake Problem. General Tree Search.
CS 88: Artificil Intelligence Fll 00 Lecture : A* Serch 9//00 A* Serch rph Serch Tody Heuristic Design Dn Klein UC Berkeley Multiple slides from Sturt Russell or Andrew Moore Recp: Serch Exmple: Pncke
More information12 <= 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 informationCompilers. Topic 4. The Symbol Table and Block Structure PART II. Mick O Donnell: Alfonso Ortega:
Compilers Topi 4 The ol Tle nd Blok Struture PART II Mik O Donnell: mihel.odonnell@um.es Alfonso Orteg: lfonso.orteg@um.es Topi 2: Blok Struture 2 1 ol tles with lok strutures Blok Struture Progrmming
More informationRegular 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