From Dependencies to Evaluation Strategies
|
|
- Ross Shepherd
- 5 years ago
- Views:
Transcription
1 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 f e * n suppose we require n[1] computing n[1] requires f[1] f[1] depends on n ttriute in the child, so descend f e E n compute ttriutes in psses compute dependency grph etween ttriutes (no go if cyclic) trverse AST once for ech ttriute; here three times, once for e, f, n f n compute one ttriute in ech pss e 3 consider fixed strtegy nd only llow n ttriute system tht cn e evluted using this strtegy 174 / 295
2 Liner Order from Dependency Prtil Order Possile utomtic strtegies: 1 demnd-driven evlution strt with the evlution of ny required ttriute if the eqution for this ttriute relies on s-of-yet unevluted ttriutes, compute these recursively visits the nodes of the syntx tree on demnd (following dependency on the prent requires pointer to the prent) 2 evlution in psses minimize the numer of visits to ech node orgnize the evlution of the tree in psses for ech pss, pre-compute strtegy to visit the nodes together with locl strtegy for evlution within ech node type consider exmple for demnd-driven evlution 175 / 295
3 Exmple: Demnd-Driven Evlution Compute next t leves 2, 3 nd 4 in the expression ( ) ( ): : next[1] := next[0] next[2] := next[0] : next[1] := first[2] (empty[2]? next[0]: ) next[2] := next[0]. n *. n 2 n e f n 0 1 e f n e f 3 4 n 176 / 295
4 Demnd-Driven Evlution Oservtions only required ttriutes re evluted the evlution sequence depends in generl on the ctul syntx tree the lgorithm must trck which ttriutes it hs lredy evluted the lgorithm my visit nodes more often thn necessry ech node must contin pointer to its prent the lgorithm is not locl pproch only eneficil in principle: evlution strtegy is dynmic: difficult to deug computtion of ll ttriutes is often cheper usully ll ttriutes in ll nodes re required perform evlution in psses 177 / 295
5 Evlution in Psses Ide: trverse the syntx tree severl times; ech time, evlute ll those equtions [i ] = f([i ],..., z[i z ]) whose rguments [i ],..., z[i z ] re known For strongly cyclic ttriute system: the locl dependencies in D i of the ith production N X 1... X n together the glol dependencies R(X i ) for ech X i define sequence in which ttriutes cn e evluted determine sequence in which the children re visited so tht s mny ttriutes s possile re evluted in ech pss t lest one new ttriute is evluted requires t most n psses for evluting n ttriutes since trversl strtegy exists for evluting one ttriute, it might e possile to find strtegy to evlute more ttriutes optimiztion prolem note: evluting ttriute set {[0],..., z[0]} for rule N... N... my evlute different ttriute set of its children up to 2 k 1 evlution functions for N... in the exmple: empty nd first cn e computed together next must e computed in seprte pss 178 / 295
6 Implementing Stte Prolem: In mny cses some sort of stte is required. Exmple: numering the lefs of syntx tree. * / 295
7 Implementing Numering of Lefs Ide: use helper ttriutes pre nd post in pre we pss the vlue of the lst lef down (inherited ttriute) in post we pss the vlue of the lst lef up (synthetic ttriute) root: pre[0] := 0 pre[1] := pre[0] post[0] := post[1] node: pre[1] := pre[0] pre[2] := post[1] post[0] := post[2] lef: post[0] := pre[0] / 295
8 The Locl Attriute Dependencies pre post pre post pre post pre post the ttriute system is pprently strongly cyclic ech node computes the inherited ttriutes efore descending into child node (corresponding to pre-order trversl) the synthetic ttriutes fter returning from child node (corresponding to post-order trversl) if ll ttriutes cn e computed in single depth-first trversl tht proceeds from left- to right (with pre- nd post-order evlution) then we cll this ttriute system L-ttriuted. 181 / 295
9 L-ttriuted Definition An ttriute system is L-ttriuted, if for ll productions s ::= s 1... s n every inherited ttriute of s j where 1 j n only depends on 1 the ttriutes of s 1, s 2,... s j 1 nd 2 the inherited ttriutes of s. Origin: the ttriutes of n L-ttriuted grmmr cn e evluted during prsing importnt if no syntx tree is required or if error messges should e emitted while prsing exmple: pocket clcultor L-ttriuted grmmrs hve fixed evlution strtegy: single depth-first trversl in generl: prtition ll ttriutes into A = A 1... A n such tht for ll ttriutes in A i the ttriute system is L-ttriuted perform depth-first trversl for ech ttriute set A i crft ttriute system in wy tht they cn e prtitioned into few L-ttriuted sets 182 / 295
10 Prcticl Applictions symol tles, type checking/inference, nd simple code genertion cn ll e specified using L-ttriuted grmmrs most pplictions nnotte syntx trees with dditionl informtion the nodes in syntx tree often hve different types tht depends on the non-terminl tht the node represents the different types of non-terminls re chrcterised y the set of ttriutes with which they re decorted exmple: sttement my hve two ttriutes contining vlid identifiers: one ingoing (inherited) set nd one outgoing (synthesised) set; in contrst, n expression only hs n ingoing set 183 / 295
11 Implementtion of Attriute Systems vi Visitor clss with method for every non-terminl in the grmmr pulic strct clss Regex { pulic strct void ccept(visitor v); } ttriute-evlution works vi pre-order / post-order cllcks pulic interfce Visitor { defult void pre(orex re) {} defult void pre(andex re) {}... defult void post(orex re) {} defult void post(andex re){} } we pre-define depth-first trversl of the syntx tree pulic clss OrEx extends Regex { Regex l,r; pulic void ccept(visitor v) { v.pre(this);l.ccept(v);v.inter(this); r.ccept(v); v.post(this); } } 184 / 295
12 Exmple: Lef Numering pulic strct clss AstrctVisitor implements Visitor { defult void pre(orex re) { pr(re); } defult void pre(andex re) { pr(re); }... defult void post(orex re) { po(re); } defult void post(andex re){ po(re); } strct void po(binex re); strct void in(binex re); strct void pr(binex re); } pulic clss LefNum extends Visitor { pulic LefNum(Regex r) { n.set(r,0);r.ccept(this);} pulic Mp<Regex,Integer> n = new HshMp<>(); pulic void pr(const r) { n.set(r, n.get(r)+1); } pulic void pr(binex r) { n.set(r.l,n.get(r)); } pulic void in(binex r) { n.set(r.r,n.get(r.l)); } pulic void po(binex r) { n.set(r,n.get(r.l)+n.get(r.r)); } } 185 / 295
13 Semntic Anlysis Chpter 2: Symol Tles 186 / 295
14 Symol Tles Consider the following Jv code: void foo() { int A; void r() { doule A; A = 0.5; write(a); } A = 2; r(); write(a); } within the ody of r the definition of A is shdowed y the locl definition ech declrtion of vrile v requires the compiler to set side some memory for v; in order to perform n ccess to v, we need to know to which declrtion the ccess is ound we consider only sttic lloction, where the memory is llocted while vrile is in scope inding is not visile within locl declrtion of the sme nme is in scope 187 / 295
15 Scope of Identifiers void foo() { } int A; void r() { doule A; A = 0.5; write(a); } A = 2; r(); write(a); scope of int A 188 / 295
16 Scope of Identifiers void foo() { int A; void r() { doule A; A = 0.5; write(a); } A = 2; r(); write(a); scope of doule A } dministrtion of identifiers cn e quite complicted / 295
17 Visiility Rules in Oject-Oriented Lnguges 1 pulic clss Foo { 2 int x = 17; 3 protected int y = 5; 4 privte int z = 42; 5 pulic int () { return 1; } 6 } 7 clss Br extends Foo { 8 protected doule y = 0.5; 9 pulic int (int ) 10 { return +x; } 11 } Oservtions: Modifier Clss Pckge Suclss World pulic protected no modifier privte privte memer z is only visile in methods of clss Foo protected memer y is visile in the sme pckge nd in su-clss Br, ut here it is shdowed y doule y Br does not compile if it is not in the sme pckge s Foo methods with the sme nme re different if their rguments differ sttic overloding 189 / 295
18 Dynmic Resolution of Functions 1 pulic clss Foo { 2 protected int foo() { return 1; } 3 } 4 clss Br extends Foo { 5 protected int foo() { return 2; } 6 pulic int test(oolen ) { 7 Foo x = ()? new Foo() : new Br(); 8 return x.foo(); 9 } 10 } Oservtions: the type of x is Foo or Br, depending on the vlue of x.foo() either clls foo in line 2 or in line 5 this decision is mde t run-time nd hs nothing to do with nme resolution 190 / 295
19 Resolving Identifiers Oservtion: ech identifier in the AST must e trnslted into memory ccess Prolem: for ech identifier, find out wht memory needs to e ccessed y providing rpid ccess to its declrtion Ide: 1 rpid ccess: replce every identifier y unique nme, nmely n integer integers s keys: comprisons of integers is fster replcing vrious identifiers with numer sves memory 2 link ech usge of vrile to the declrtion of tht vrile trck dt structures to distinguish declred vriles nd visile vriles for lnguges without explicit declrtions, crete declrtions when vrile is first encountered 191 / 295
20 (1) Replce ech Occurrence with Numer Rther thn hndling strings, we replce ech string with unique numer. Ide for Algorithm: Input: sequence of strings Output: 1 sequence of numers 2 tle tht llows to retrieve the string tht corresponds to numer Apply this lgorithm on ech identifier in the scnner. 192 / 295
21 Exmple for Applying this Algorithm Input: Peter Piper picked peck of pickled peppers If Peter Piper picked peck of pickled peppers wheres the peck of pickled peppers Peter Piper picked Output: nd 0 Peter 1 Piper 2 picked 3 4 peck 5 of 6 pickled 7 peppers 8 If 9 wheres 10 the 193 / 295
22 Implementing the Algorithm: Specifiction Ide: implement prtil mp: S : String int use counter vrile int count = 0; to trck the numer of different identifiers found so fr We thus define function int getindex(string w): int getindex(string w) { if (S (w) undefined) { S = S {w count}; return count++; else return S (w); } 194 / 295
23 Dt Structures for Prtil Mps possile dt structures: list of pirs (w, i) String int : insert: O(1) lookup: O(n) too expensive lnced trees : insert: O(log(n)) lookup: O(log(n)) hsh tles : insert: O(1) lookup: O(1) too expensive on verge cvet: we will see tht the hndling of scoping requires dditionl opertions tht re hrd to implement with hsh tles 195 / 295
24 An Implementtion using Hsh Tles llocted n rry M of sufficient size m choose hsh function H : String [0, m 1] with the following properties: H(w) is chep to compute H distriutes the occurring words eqully over [0, m 1] Possile choices ( x = x 0,... x r 1 ): H 0 ( x) = H 1 ( x) = H 1 ( x) = (x 0 + x r 1 ) % m ( r 1 i=0 x i p i ) % m (x 0 + p (x 1 + p (... + p x r 1 ))) % m for some prime numer p (e.g. 31) We store the pir (w, i) in linked list locted t M[H(w)] 196 / 295
25 Computing Hsh Tle for the Exmple With m = 7 nd H 0 we otin: 0 If 8 the Piper 1 Peter 0 6 pickled 6 peck 4 pickled 2 of 5 wheres 9 peppers 7 3 In order to find the index for the word w, we need to compre w with ll words x for which H(w) = H(x) 197 / 295
26 Resolving Identifiers: (2) Symol Tles Check for the correct usge of vriles: Trverse the syntx tree in suitle sequence, such tht ech definition is visited efore its use the currently visile definition is the lst one visited for ech identifier, we mnge stck of scopes if we visit declrtion of n identifier, we push it onto the stck upon leving the scope, we remove it from the stck if we visit usge of n identifier, we pick the top-most declrtion from its stck if the stck of the identifier is empty, we hve found n error 198 / 295
27 Exmple: A Tle of Stcks 1 { 2 int, ; // V, W 3 = 5; 4 if (>3) { 5 int, c; // X, Y 6 = 3; 7 c = + 1; 8 = c; 9 } else { 10 int c; // Z 11 c = + 1; 12 = c; 13 } 14 = + ; 15 } c c c c V W X, V W Y V W Z V W 199 / 295
28 Resolving: Rewriting the Syntx Tree 0 d int 1 d d declrtion node sic lock ssignment int 1 = 5 1 > 3 if 0 d int 2 d int { int, ; // V, W = 5; if (>3) { int, c; // X, Y = 3; c = + 1; = c; } else { int c; // Z c = + 1; = c; } = + ; } = d int = / 295
29 Resolving: Rewriting the Syntx Tree 0 d int 1 d d declrtion node sic lock ssignment int 1 = 5 1 > 3 if 0 d int 2 d int { int, ; // V, W = 5; if (>3) { int, c; // X, Y = 3; c = + 1; = c; } else { int c; // Z c = + 1; = c; } = + ; } = d int = / 295
30 Alterntive Resolution of Visiility resolving identifiers cn e done using n L-ttriuted grmmr eqution system for sic lock must dd nd remove identifiers when using list to store the symol tle, storing mrker indicting the old hed of the list is sufficient c c in front of if-sttement then-rnch else-rnch insted of lists of symols, it is possile to use list of hsh tles more efficient in lrge, shllow progrms more elegnt solution is to use persistent tree in which n updte returns new tree ut leves ll old references to the tree unchnged persistent tree t cn e pssed down into sic lock where new elements my e dded; fter exmining the sic lock, the nlysis proceeds with the unchnged t 201 / 295
box Boxes and Arrows 3 true 7.59 'X' An object is drawn as a box that contains its data members, for example:
Boxes nd Arrows There re two kinds of vriles in Jv: those tht store primitive vlues nd those tht store references. Primitive vlues re vlues of type long, int, short, chr, yte, oolen, doule, nd flot. References
More informationSymbol Table management
TDDD Compilers nd interpreters TDDB44 Compiler Construction Symol Tles Symol Tles in the Compiler Symol Tle mngement source progrm Leicl nlysis Syntctic nlysis Semntic nlysis nd Intermedite code gen Code
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 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 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 informationCPSC 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 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 informationAgenda & Reading. Class Exercise. COMPSCI 105 SS 2012 Principles of Computer Science. Arrays
COMPSCI 5 SS Principles of Computer Science Arrys & Multidimensionl Arrys Agend & Reding Agend Arrys Creting & Using Primitive & Reference Types Assignments & Equlity Pss y Vlue & Pss y Reference Copying
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 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 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 informationPresentation Martin Randers
Presenttion Mrtin Rnders Outline Introduction Algorithms Implementtion nd experiments Memory consumption Summry Introduction Introduction Evolution of species cn e modelled in trees Trees consist of nodes
More informationASTs, 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 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 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 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 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 informationOutline. Tiling, formally. Expression tile as rule. Statement tiles as rules. Function calls. CS 412 Introduction to Compilers
CS 412 Introduction to Compilers Andrew Myers Cornell University Lectur8 Finishing genertion 9 Mr 01 Outline Tiling s syntx-directed trnsltion Implementing function clls Implementing functions Optimizing
More informationDiscussion 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 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 informationTries. 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 informationVirtual 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 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 informationLab 1 - Counter. Create a project. Add files to the project. Compile design files. Run simulation. Debug results
1 L 1 - Counter A project is collection mechnism for n HDL design under specifiction or test. Projects in ModelSim ese interction nd re useful for orgnizing files nd specifying simultion settings. The
More informationDistributed Systems Principles and Paradigms
Distriuted Systems Principles nd Prdigms Chpter 11 (version April 7, 2008) Mrten vn Steen Vrije Universiteit Amsterdm, Fculty of Science Dept. Mthemtics nd Computer Science Room R4.20. Tel: (020) 598 7784
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 informationScope, Functions, and Storage Management
Scope, Functions, nd Storge Mngement Block-structured lnguges nd stck storge In-le Blocks (previous set of overheds) ctivtion records storge for locl, glol vriles First-order functions (previous set of
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 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 informationOutline CS 412/413. Function calls. Stack layout. Tiling a call. Two translations
CS 412/413 Introduction to Compilers nd Trnsltors Cornell University Andrew Myers Outline Implementing function clls Implementing functions Optimizing wy the pointer Dynmiclly-llocted structures strings
More informationcisc1110 fall 2010 lecture VI.2 call by value function parameters another call by value example:
cisc1110 fll 2010 lecture VI.2 cll y vlue function prmeters more on functions more on cll y vlue nd cll y reference pssing strings to functions returning strings from functions vrile scope glol vriles
More informationA 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 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 informationMa/CS 6b Class 1: Graph Recap
M/CS 6 Clss 1: Grph Recp By Adm Sheffer Course Detils Adm Sheffer. Office hour: Tuesdys 4pm. dmsh@cltech.edu TA: Victor Kstkin. Office hour: Tuesdys 7pm. 1:00 Mondy, Wednesdy, nd Fridy. http://www.mth.cltech.edu/~2014-15/2term/m006/
More informationCSCE 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 informationITEC2620 Introduction to Data Structures
ITEC0 Introduction to Dt Structures Lecture 7 Queues, Priority Queues Queues I A queue is First-In, First-Out = FIFO uffer e.g. line-ups People enter from the ck of the line People re served (exit) from
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 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 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 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 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 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 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 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 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 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 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 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 informationOrthogonal line segment intersection
Computtionl Geometry [csci 3250] Line segment intersection The prolem (wht) Computtionl Geometry [csci 3250] Orthogonl line segment intersection Applictions (why) Algorithms (how) A specil cse: Orthogonl
More informationFunctor (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 informationReference types and their characteristics Class Definition Constructors and Object Creation Special objects: Strings and Arrays
Objects nd Clsses Reference types nd their chrcteristics Clss Definition Constructors nd Object Cretion Specil objects: Strings nd Arrys OOAD 1999/2000 Cludi Niederée, Jochim W. Schmidt Softwre Systems
More information10/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 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 informationSolving 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 informationStack. 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 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 informationbinary trees, expression trees
COMP 250 Lecture 21 binry trees, expression trees Oct. 27, 2017 1 Binry tree: ech node hs t most two children. 2 Mximum number of nodes in binry tree? Height h (e.g. 3) 3 Mximum number of nodes in binry
More informationReducing Costs with Duck Typing. Structural
Reducing Costs with Duck Typing Structurl 1 Duck Typing In computer progrmming with object-oriented progrmming lnguges, duck typing is lyer of progrmming lnguge nd design rules on top of typing. Typing
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 informationSuffix Tries. Slides adapted from the course by Ben Langmead
Suffix Tries Slides dpted from the course y Ben Lngmed en.lngmed@gmil.com Indexing with suffixes Until now, our indexes hve een sed on extrcting sustrings from T A very different pproch is to extrct suffixes
More information10.5 Graphing Quadratic Functions
0.5 Grphing Qudrtic Functions Now tht we cn solve qudrtic equtions, we wnt to lern how to grph the function ssocited with the qudrtic eqution. We cll this the qudrtic function. Grphs of Qudrtic Functions
More informationMidterm 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 information2-3 search trees red-black BSTs B-trees
2-3 serch trees red-lck BTs B-trees 3 2-3 tree llow 1 or 2 keys per node. 2-node: one key, two children. 3-node: two keys, three children. ymmetric order. Inorder trversl yields keys in scending order.
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 informationSlides 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 informationFunctor (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 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 informationPARALLEL AND DISTRIBUTED COMPUTING
PARALLEL AND DISTRIBUTED COMPUTING 2009/2010 1 st Semester Teste Jnury 9, 2010 Durtion: 2h00 - No extr mteril llowed. This includes notes, scrtch pper, clcultor, etc. - Give your nswers in the ville spce
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 informationMid-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 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 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 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 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 informationSolving 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 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 informationMa/CS 6b Class 1: Graph Recap
M/CS 6 Clss 1: Grph Recp By Adm Sheffer Course Detils Instructor: Adm Sheffer. TA: Cosmin Pohot. 1pm Mondys, Wednesdys, nd Fridys. http://mth.cltech.edu/~2015-16/2term/m006/ Min ook: Introduction to Grph
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 informationUT1553B BCRT True Dual-port Memory Interface
UTMC APPICATION NOTE UT553B BCRT True Dul-port Memory Interfce INTRODUCTION The UTMC UT553B BCRT is monolithic CMOS integrted circuit tht provides comprehensive MI-STD- 553B Bus Controller nd Remote Terminl
More informationAI Adjacent Fields. This slide deck courtesy of Dan Klein at UC Berkeley
AI Adjcent Fields Philosophy: Logic, methods of resoning Mind s physicl system Foundtions of lerning, lnguge, rtionlity Mthemtics Forml representtion nd proof Algorithms, computtion, (un)decidility, (in)trctility
More informationSection 10.4 Hyperbolas
66 Section 10.4 Hyperbols Objective : Definition of hyperbol & hyperbols centered t (0, 0). The third type of conic we will study is the hyperbol. It is defined in the sme mnner tht we defined the prbol
More informationPosition Heaps: A Simple and Dynamic Text Indexing Data Structure
Position Heps: A Simple nd Dynmic Text Indexing Dt Structure Andrzej Ehrenfeucht, Ross M. McConnell, Niss Osheim, Sung-Whn Woo Dept. of Computer Science, 40 UCB, University of Colordo t Boulder, Boulder,
More informationCOMPUTER 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 informationStack Manipulation. Other Issues. How about larger constants? Frame Pointer. PowerPC. Alternative Architectures
Other Issues Stck Mnipultion support for procedures (Refer to section 3.6), stcks, frmes, recursion mnipulting strings nd pointers linkers, loders, memory lyout Interrupts, exceptions, system clls nd conventions
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 informationUNIT 11. Query Optimization
UNIT Query Optimiztion Contents Introduction to Query Optimiztion 2 The Optimiztion Process: An Overview 3 Optimiztion in System R 4 Optimiztion in INGRES 5 Implementing the Join Opertors Wei-Png Yng,
More informationMTH 146 Conics Supplement
105- Review of Conics MTH 146 Conics Supplement In this section we review conics If ou ne more detils thn re present in the notes, r through section 105 of the ook Definition: A prol is the set of points
More informationCOMBINATORIAL 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 informationThe Greedy Method. The Greedy Method
Lists nd Itertors /8/26 Presenttion for use with the textook, Algorithm Design nd Applictions, y M. T. Goodrich nd R. Tmssi, Wiley, 25 The Greedy Method The Greedy Method The greedy method is generl lgorithm
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 informationData sharing in OpenMP
Dt shring in OpenMP Polo Burgio polo.burgio@unimore.it Outline Expressing prllelism Understnding prllel threds Memory Dt mngement Dt cluses Synchroniztion Brriers, locks, criticl sections Work prtitioning
More informationCompiler Construction I
TECHNISCHE UNIVERSITÄT MÜNCHEN FAKULTÄT FÜR INFORMATIK Compiler Construction I Dr. Michael Petter, Dr. Axel Simon SoSe 2013 1 / 59 Organizing Master or Bachelor in the 6th Semester with 5 ECTS Prerequisites
More informationSuffix 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 informationFile 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 informationOutline. Introduction Suffix Trees (ST) Building STs in linear time: Ukkonen s algorithm Applications of ST
Suffi Trees Outline Introduction Suffi Trees (ST) Building STs in liner time: Ukkonen s lgorithm Applictions of ST 2 3 Introduction Sustrings String is ny sequence of chrcters. Sustring of string S is
More informationSimrad ES80. Software Release Note Introduction
Simrd ES80 Softwre Relese 1.3.0 Introduction This document descries the chnges introduced with the new softwre version. Product: ES80 Softwre version: 1.3.0 This softwre controls ll functionlity in the
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 information1.1. Interval Notation and Set Notation Essential Question When is it convenient to use set-builder notation to represent a set of numbers?
1.1 TEXAS ESSENTIAL KNOWLEDGE AND SKILLS Prepring for 2A.6.K, 2A.7.I Intervl Nottion nd Set Nottion Essentil Question When is it convenient to use set-uilder nottion to represent set of numers? A collection
More informationCIS 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 informationPointer Analysis. CSE 501 Spring 15
Pointer Anlysis CSE 501 Sring 15 Course Outline St8c nlysis Dtflow nd strct interret8on Alic8ons We re here Beyond generl- urose lnguges Progrm Verific8on Dynmic nlysis New comilers Tody Intro to ointer
More information