Contextual Analysis. Overview of Lecture 3. Ch 4 Syntactic Analysis. Mededelingen

Size: px
Start display at page:

Download "Contextual Analysis. Overview of Lecture 3. Ch 4 Syntactic Analysis. Mededelingen"

Transcription

1 Overview of Lecture 3 otextual Aalysis Mededelige h 4 Sytactic Aalysis Abstract Sytax Trees VB H3 Vertalerbouw H3 h 5 otextual Aalysis 5.1 Idetificatio 5.2 Type heckig 5.3 otextual Aalysis algorithm 5.4 ase study: otextual Aalysis for Triagle Theo Ruys Uiversity of Twete epartmet of omputer Sciece Formal Methods & Tools Michael Weber!! kamer: Zi 5037" telefoo: 3716" michaelw@utwete.l! 2 Mededelige h 4 Sytactic Aalysis Opgaveserie 1 komt z.s.m. beschikbaar op de Vertalerbouwwebsite! deadlie: woesdag 18 mei 2011 om uur! wees precies: slordighede zij meestal fout 4.1 Subphrases of sytactic aalysis 4.2 Grammars revisited 4.3 Parsig 4.4 Abstract Sytax Trees 4.5 Scaig 4.6 ase study: Triagle compiler 3 4

2 Recursive-escet Parsig H2 Recursive-escet Parsig H2 Systematic developmet of a recursive-descet parser: 1. Express the grammar i EBNF. 2. Grammar trasformatios:! elimiate left recursio! left-factorizatio 3. reate a Java Parser class with! protected variable currettoke! methods to call the scaer: accept ad acceptit! public method parse which gets the first toke from the scaer, ad calls the parse method of the root o-termial of the grammar 4. Implemet protected parsig methods! add protected methods parsen for each o-termial N public class MicroEglishParser { protected Toke currettoke; public void parse() { currettoke = first toke; parsesetece(); check that o toke follows the setece protected void accept(toke expected) { protected void parsesetece() { protected void parsesubject() { protected void parseobject() { protected void parsenou() { protected void parseverb() { iterface with the scaer which provides the tokes I Watt & Brow, the parse methods are declared private. This is ufortuate as it does ot allow customizatio of the parser through iheritace. 5 6 Abstract Sytax Trees (1) Abstract Sytax Trees (2) A recursive-descet parser builds the sytax tree implicitly by the call graph of the parse methods.! I a oe-pass compiler this is OK.! I a multi-pass compiler we eed a explicit represetatio of the (abstract) sytax tree. Remember that each otermial XYZ is coverted to a parse method parsexyz: protected void parsexyz( ) { Istead of returig othig, the method could retur somethig iterestig. What about a AST ode? Furthermore, other parse methods that call this method could pass useful iformatio to this method usig parameters. 7 Program ::= ommad Program ommad ::= ommad ; ommad Sequetialmd V-ame := Expressio Assigmd Idetifier ( Expressio ) allmd Grammar for Mii-Triagle s abstract sytax. if Expressio Ifmd the ommad else ommad while Expressio do ommad Whilemd let eclaratio i ommad Letmd Expressio ::= Iteger-Literal ItegerExpr V-ame VameExpr Operator Expressio UaryExpr Expressio Operator Expressio BiaryExpr V-ame ::= Idetifier SimpleVame eclaratio ::= eclaratio ; eclaratio Seqecl cost Idetifier ~ Expressio ostecl var Idetifier : Type-deoter Type-deoter ::= Idetifier AST odes of Mii-Triagle ypee 8

3 Abstract Sytax Trees (3) Abstract Sytax Trees (4) ommad ::= ommad ; ommad Sequetialmd V-ame := Expressio Assigmd Idetifier ( Expressio ) allmd if Expressio the sigle-ommad Ifmd else sigle-ommad while Expressio do sigle-ommad Whilemd let eclaratio i sigle-ommad Letmd We eed to defie Java classes to capture the structure of Mii- Triagle ASTs. We itroduce the abstract class AST. public abstract class AST { Sequetialmd Assigmd allmd Every ode i the AST will be a object of a subclass of AST. Each subclass has istace variables for the childre odes. 1 2 Ifmd V E Whilemd Idet E Letmd public class Program exts AST { public ommad ; ommad is the abstract base class for all ommad AST odes. E 1 2 E public abstract class ommad exts AST { 9 10 ASTs (5) abstract class ommad exts AST { ommad ::= ommad ; ommad Sequetialmd V-ame := Expressio Assigmd Idetifier ( Expressio ) allmd if Expressio the sigle-ommad Ifmd else sigle-ommad while Expressio do sigle-ommad Whilemd let eclaratio i sigle-ommad Letmd public class Sequetialmd exts ommad { public ommad 1, 2; Sequetialmd public class Assigmd exts ommad { 1 2 public Vame V; public Expressio E; Assigmd V E public class allmd exts ommad { allmd public Idetifier I; public Expressio E; Idet E Ifmd public class Ifmd exts ommad { public Expressio E; public ommad 1, 2; E 1 2 etc. The AST subclasses should have costructors to build a object of these classes. 11 Abstract Sytax Trees (6) It is straightforward to make a recursive-descet parser costruct a AST to represet the phrase structure.! We make each method parsen (as well as parsig a N-phrase), retur the N-phrase s AST.! We let the body of a method parsen costruct the N-phrase AST by combiig the ASTs of ay subphrases. Thus, for productio rule N::=X protected AST N parsen() { AST N itsast; parse X, at the same time costructig itsast retur itsast; 12

4 Abstract Sytax Trees (7) h 5 otextual Aalysis EBNF ommad ::= sigle-ommad (; sigle-ommad)* AST ommad ::= ommad ; ommad Sequetialmd protected ommad parseommad() { ommad c1ast = parsesigleommad(); while (currettoke.kid == Toke.SEMIOLON) { acceptit(); ommad c2ast = parsesigleommad(); c1ast = ew Sequetialmd(c1AST, c2ast); retur c1ast; Seqmd 5.1 Idetificatio 5.2 Type checkig 5.3 otextual Aalysis algorithm 5.4 ase study: Triagle compiler Seqmd md 3 md 1 md ompiler Phases otext ostraits scope rules H1 Source Program Scope rule - examples sometimes referred to as sematic aalysis. h. 8: Iterpreter Sytax Aalysis AST otextual Aalysis ecorated AST AST ode Geeratio Object ode (Abstract) Machie h. 4 h. 5 h. 7 heckig the laguage s cotextual costraits. h. 6: Ru-Time Orgaizatio?? let cost m ~ 2; var : Iteger := m*2; declaratio of : bidig occurrece use of : applied occurrece let If there is o eclosig scope var : Iteger; (i.e. letmd) where m is declared, the bidig occurece of m is missig: scope error! := m*2; applied occurrece 15 16

5 otext ostraits type rules H1 Sytax Aalysis Source Program Sytax Aalysis H2 Errors Type rule - example let var : Iteger while > 0 do := -1; Type rule for E 1 > E 2 (GreaterOp): If E 1 ad E 2 are both of type it, the the result is of type bool. Type rule for while E do (Whilemd): E must be a boolea. let var : Iteger; var c: har c := & ; := +1 Sequetialecl Program Abstract Sytax Tree Letmd Sequetialmd Assigmd Assigmd BiaryExpr harexpr VameExpr Type rule for V:=E (Assigmd): The types of V ad E must be equivalet. Type rule for E 1 -E 2 (SubOp): If E 1 ad E 2 are both of type it, the the result is of type it. Idet har-lit Idet Idet Op ItExpr It-Lit Iteger c har c & otextual Aalysis Abstract Sytax Tree otext Aalysis H2 Errors Thigs to check Two sub phases: scope rules are checked i the idetificatio phase type rules are checked i the type checkig phase Sequetialecl Program Letmd Assigmd Iteger c har c & ecorated Abstract Sytax Tree Sequetialmd BiaryExpr harexpr :char VameExpr ItExpr :char Idet har-lit Idet Idet Op It-Lit Assigmd + 1 A applied occurrece of a idetifier must have a matchig defiig occurrece. The relatio betwee applied ad defiig occurrece might be added to the AST. Fuctio calls must refer to defied fuctios. I a assigmet, the idetifier o the left-had side should refer to a variable. The expressio of a if or while should be boolea. Whe callig procedures, the umber ad types of the actual parameters (argumets) should match the umber ad types of the formal parameters. etc. All follow from the cotext costraits defied for the (programmig) laguage

6 Symbol Table (1) See exercise 1.3 of the laboratory sessio of week 1. Block Symbol table (called idetificatio table i W&B)! ictioary-style data structure i which idetifiers are stored together with their attributes.! Attributes type: it, char, boolea, record, array, poiter, etc. kid: costat, variable, procedure, fuctio, value-parameter, referece-parameter, etc. visibility: public, private, protected other importat characteristics! Typical operatios eter a idetifier ad its attributes ito symbol table retrieve the attributes for a idetifier other operatios dep o the block structure of the laguage. scope of a declaratio: area of the program over which the declaratio takes effect. block: area of program text that delimits the scope of declaratios withi it.! Triagle s block commads let eclaratios i ommads proc P(formal-parameters) ~ ommads! I Java: A block is a sequece of statemets, local class declaratios ad local variable declaratio statemets withi braces. for (it i=0; i<a.legth; i++) { Strig s = a[i]; System.out.pritl(s); Both i ad s caot be used outside the for-loop Moolithic block structure Flat block structure program eclaratios sequece of declaratios sequece of commads begi ommads haracteristics! Oly oe block: etire program! All declaratios are global i scope. Scope rules! No idetifier may be declared more tha oce.! No idetifier may be used uless declared. Symbol table! For every idetifier there is a sigle etry i the symbol table.! Retrieval should be fast (e.g. biary search tree or hash table). BASI, OBOL,! 23 program procedure P begi procedure Q begi begi haracteristics! program has several disjoit blocks! two scope levels: global ad local Scope rules! No globally declared idetifier may be redeclared globally.! No locally declared idetifier may be redeclared i the same block.! No idetifier may be used uless declared (globally or locally) Symbol table! Symbol table should cotai etries for both global ad local declaratios.! After aalysis of a block has completed, its local declaratios ca be discarded. Fortra, 24

7 Nested block structure (1) Nested block structure (2) program procedure P procedure PP proc PPP begi begi procedure Q begi begi haracteristics! blocks ca be ested withi each other! may scope levels Scope rules! No idetifier may be declared more tha oce i the same block.! No idetifier may be used uless declared (i local or eclosed blocks). Symbol table! Several etries for each idetifier.! But, at most oe etry for each (scope level, idetifier) combiatio.! Highest-level etry of a idetifier should be retrieved (fast). Pascal, Modula, Ada, Java, etc. 25 let!level 1 var a, b, c ; let!level 2 var a, b ; let!level 3 var a, c ; a := b + c ; ; a := b + c ; ; a := b + c ; Scope ad visibility a ad b of level 1 get redefied ad are ot visible o level 2 a of level 2 ad c of level 1 get redefied ad are ot visible o level 3 26 Scope structure Symbol Table (2) Example For a statically scoped laguage with ested block structure, the structure of the scopes ca be see as a tree. Global P Q P1 P2 P3 * P Global P1 P2 P3 Q Lookup path for a applied occurrece withi P3 At ay time (whe aalysig the program), oly a sigle path i the tree is visible. let!level 1 (1) var a: Iteger; var b: Boolea (2) let!level 2 (3) var b: Iteger; var c: Boolea (4) let!level 3 (5) cost x ~ 3 i let!level 2 (6) var d: Boolea; (7) var e: Iteger level id Attr. 1 a (1) 1 level b (2) id Attr. 1 a (1) 1 b (2) 2 b (3) 2 level c (4) id Attr. 1 a (1) 1 b (2) 2 b (3) 2 c (4) 3 x (5) level id Attr. 1 a (1) 1 b (2) 2 d (6) 2 e (7) 27 28

8 Symbol Table (3) Symbol Table (4) Symbol table additioal operatios! ope a ew scope level! close the highest scope level public class SymbolTable { /** Ope a ew scope. */ public void opescope() Attribute: holds all importat iformatio o a defied occurrece (type, kid, level, visibility, etc.) differs for differet laguages /** losest the highest (curret) scope. */ public void closescope() /** Eters a id together with its Attribute. */ public void eter(strig id, Attribute attr); /** Returs the Attribute of id, defied o the * highest level. Retur ull if ot i table. */ public Attribute retrieve(strig id) /** Returs the curret scope level. */ public it curretlevel() Would have bee better OO-practice if we had declared the SymbolTable to be a iterface or a abstract class. 29 Possible implemetatio: public class SymbolTable { private Map<Strig,Stack<Attribute>> symtab; private Stack<List<Strig>> scopestack; Oly used to optimize the closig of a scope. The symtab is a Map from Strigs to Stack-objects. The keys are the Strig represetatios of the idetifiers. The value of a idetifier s Strig is a Stack of Attributes; the Attributes of the idetifier declared o the highest scope level is always o top. The scopestack is a Stack of List-objects (cotaiig Strigs). Whe a scope is opeed, a empty List is pushed o the scopestack; the Strig-represetatio of each idetifier foud i this curret scope will be added to this list. Whe a scope is closed, the idetifiers of this old scope (which are all i the top List of scopestack) are removed from symtab. The List of the old scope is popped from scopestack. 30 Symbol Table (5) Previous example usig a map of <Strig, Stack<Attribute>>. Attributes (1) let!level 1 (1) var a: Iteger; var b: Boolea (2) let!level 2 (3) var b: Iteger; var c: Boolea; (4) let!level 3 (5) cost x ~ 3 i let!level 2 (6) var d: Boolea (7) var e: Iteger id a b c x level id Attr. 1 a (1) 1 level b (2) id Attr. 1 a (1) 1 b (2) 2 b (3) 2 level c (4) id Attr. 1 (1) 1 a (1) 1 b (2) 2 (3) 2 b (3) 1 (2) 2 c (4) 2 (4) 3 x (5) 3 (5) Attributes should (at least) cotai iformatio for! checkig the scope rules Successful retrieval of a applied occurrece i the symbol table is eough: it meas that there is a bidig occurece.! checkig the type rules The type of a idetifier has to be stored.! (code geeratio) address of the variable Possible approaches! Store the attribute completely ito the symbol table.! As the AST ode of the bidig occurrece should have access to all ecessary iformatio, we could also store refereces (poiters) to these odes i the symbol table

9 Attributes (2) Imperative approach for storig attributes explicitly. public class Attribute { public static fial byte // kid ONST = 0, VAR = 1, PRO = 2, ; public static fial byte // type BOOL = 0, HAR = 1, INT = 2, ARRAY = 3, ; Attributes (3) OO approach for storig attributes explicitly. public class Attribute { public Kid kid; public Type type; Kid ostkid VarKid ProcKid FucKid... Type Works, but for a realistic laguage this ca become quite tedious ad complex. public byte kid; public byte type; suitable for little laguages BoolType hartype ItType ArrayType Attributes (4) Usig refereces to the AST. x Sequetialecl Iteger y Program Letmd har... Letmd z... Boolea let var x: Iteger; var y: har let var z: Boolea i level id Attr. 1 x 1 y 2 z Very coveiet whe we eed to decorate the AST. Types What is a type?! A restrictio o the possible iterpretatios of a segmet of memory or other program costruct.! A set of values. Why use types?! error avoidace: prevet programmer from makig type errors (e.g. roud peg i square hole).! rutime optimizatio: earlier bidig leads to fewer rutime decisios (e.g. ). Are types really eeded?! No, may laguages ca operate (fie) without them assembly laguages, script laguages (e.g. Pytho, Tcl) 35 36

10 Type heckig (1) I a statically typed laguage every expressio E is either (i) ill-typed, or (ii) has a static type that ca be computed without actually evaluatig E. Whe a expressio E has static type T this meas that whe E is evaluated the the retured value will always have type T. Most moder laguages have a large emphasis o static typecheckig. But object-orieted programmig laguages (e.g. Java) require some rutime type checkig. Type heckig (2) Type checkig ivolves (i) calculatig or iferrig the types of expressios (by usig iformatio about the types of their compoets) ad (ii) checkig that these types are what they should be (e.g. the coditio of ifstatemet must have type Boolea). Bottom-up type checkig algorithm for statically typed programmig laguages:! The types of expressio AST leaves are kow: literals: deotatio (true/false, 2, 3, a ) variables: retrieve from symbol table costats: retrieve from symbol table! Types of iteral odes are iferred from the type of the childre ad the type rule for that kid of expressio Type heckig (3) otextual Aalysis Algorithm x Type rule for biary expr: If op is a operatio of type T 1 xt 2!R the E 1 op E 2 is type correct ad of type R if E 1 ad E 2 are type correct ad have types compatible with T 1 ad T 2 respectively. type ItegerExpr it 2 SimpleVame type x BiaryExpr bool Operator ItegerExpr it x it! bool it < 7 Idetificatio ad type checkig could be doe by two separate passes over the AST.! However, this is ot eeded. Both passes ca be iterleaved, as log as the declaratio of a idetifier is before its use (ad hece its type is available for type checkig to proceed). Possible algorithm! Oe depth-first left-to-right traversal of the AST, doig both idetificatio ad type checkig.! Results of the aalysis are recorded i the AST by decoratig it

11 Abstract Sytax Trees AST lass Hierarchy See W&B.2 Program ::= ommad Program ommad ::= ommad ; ommad Sequetialmd V-ame := Expressio Assigmd Idetifier ( Expressio ) allmd Grammar for Mii-Triagle s abstract sytax. if Expressio Ifmd the ommad else ommad while Expressio do ommad Whilemd let eclaratio i ommad Letmd Expressio ::= Iteger-Literal ItegerExpr V-ame VameExpr Operator Expressio UaryExpr Expressio Operator Expressio BiaryExpr V-ame ::= Idetifier SimpleVame eclaratio ::= eclaratio ; eclaratio Seqecl cost Idetifier ~ Expressio ostecl var Idetifier : Type-deoter Type-deoter ::= Idetifier AST odes of Mii-Triagle ypee 41 AST eclaratio ommad Seqecl ostecl... Expressio ItegerExpr VameExpr UaryExpr BiaryExpr 42 AST Hierarchy i Java otextual Aalysis Abstract Sytax Tree otext Aalysis H2 Errors Expressio ::= Iteger-Literal ItegerExpr V-ame VameExpr Operator Expressio UaryExpr Expressio Operator Expressio BiaryExpr public class BiaryExpr exts Expressio { public Expressio E1, E2; public Operator O; public class UaryExpr exts Expressio { public Expressio E; public Operator O; Two sub phases: scope rules are checked i the idetificatio phase type rules are checked i the type checkig phase Sequetialecl Program Letmd Assigmd Iteger c har c & ecorated Abstract Sytax Tree Sequetialmd BiaryExpr harexpr :char VameExpr ItExpr :char Idet har-lit Idet Idet Op It-Lit Assigmd

12 ecoratio Straightforward OO-approach (1) ecoratio is doe by addig some istace variables to some of the AST classes. public abstract class Expressio exts AST { // Every expressio has a type public Type type; public class Idetifier exts Toke { // Bidig occurrece of this idetifier public eclaratio decl; Add to each AST class methods for type checkig (or code-geeratio, pretty pritig, etc.). I each AST ode class, the methods traverse their childre. public abstract AST() { public abstract Object check(object arg); public abstract Object ecode(object arg); public abstract Object prettyprit(object arg); Program program; program.check(ull); Retur value ca be used to pass iformatio up the AST tree. Extra arg ca be used to pass iformatio dow the AST tree. advatage: OO-idea is easy to uderstad ad implemet disadvatage: checkig (ad ecodig) methods are spread over all AST classes: ot very modular Straightforward OO-approach (2) public abstract class Expressio Program exts AST { public Type type; Letmd public class BiaryExpr exts Expressio Sequetialmd { public Expressio E1, E2; public Operator O; Assigmd Assigmd Example public Object check(object arg) { Sequetialecl BiaryExpr Type t1 = (Type) E1.check(ull); Type t2 = (Type) E2.check(ull); harexpr Op op = (Op) O.check(ull); :char VameExpr Type result = op.compatible(t1,t2); ItExpr if (result == ull) report type error :char retur result; Idet har-lit Idet Idet Op It-Lit or Object[] tmp = ew Object[2]; Iteger tmp[0] c = har t1; tmp[1] c = t2; & + 1 Type result = (Type) O.check(tmp); Visitor patter (1) The Visitor patter from the famous esig Patters book by Gamma et. al. (1994) lets you defie a ew operatio o the elemets of a object (e.g. the odes i a AST) without chagig the classes of the elemets o which it operates. This patter is particular useful if may distict ad urelated operatios eed to be performed o objects i a object structure, ad you wat to avoid pollutig their classes with these operatios. Some characteristics:! Visitors makes addig ew operatios easy.! A visitor gathers related operatios ad separates urelated oes.! Visitor patter breaks ecapsulatio

13 Usig a Visitor (1) Idea: use a extra level of idirectio! defie a special Visitor class to visit the odes i the tree.! add (oly-oe) visit method to the AST classes, which lets the visitor actually visit the AST ode. public abstract class AST { public abstract Object visit(visitor v, Object arg); public class Assigmd exts ommad { public Object visit(visitor v, Object arg) { retur v.visitassigmd(this, arg); public class XYZ exts { public Object visit(visitor v, Object arg) { retur v.visitxyz(this, arg); Geeral template for all AST ode classes. I literature o software patters the method visit is usually amed accept. So istead of several methods like check, ecode, etc, oly a sigle visit method. (a implemetatio of) this method will do the type-checkig (or code geeratio, pritig, etc.). 49 Usig a Visitor (2) public class XYZ exts { Object visit(visitor v, Object arg) { retur v.visitxyz(this, arg); public iterface Visitor { public Object visitprogram (Program prog, Object arg); public Object visitassigmd (Assigmd cmd, Object arg); public Object visitsequetialmd (Sequetialmd cmd, Object arg); public Object visitvameexpressio (VameExpressio e, Object arg); public Object visitbiaryexpressio (BiaryExpressio e, Object arg); The Visitor iterface defies visitxyz methods for all AST classes! public Object visitxyz (XYZ x, Object arg); 50 hecker as a Visitor (1) Ay implemetatio of Visitor ca traverse the AST. public class hecker implemets Visitor { private SymbolTable symtab; public void check(program prog) { symtab = ew SymbolTable(); prog.visit(this, ull); + implemetatios of all methods of Visitor All methods for a specific pass over the AST up i the same class, i.e. the same file! Root ode of the AST. hecker as a Visitor (2) public Object visitassigmd (Assigmd com, Object arg) { Type vtype = (Type) com.v.visit(this, ull); Type etype = (Type) com.e.visit(this, ull); if (! com.v.isvariable()) error: left side is ot a variable if (! etype.equals(vtype)) error: types are ot equivalet retur ull; public class XYZ exts { Object visit(visitor v, Object arg) { retur v.visitxyz(this, arg); Assigmd public Object visitletmd (Letmd com, Object arg) { Letmd symtab.opescope(); com..visit(this, ull); com..visit(this, ull); symtab.closescope(); retur ull; Note that the letmd opes (ad closes) the scope of the Symbol Table. V E 51 52

14 hecker as a Visitor (3) public Object visitifmd (Ifmd com, Object arg) { Type etype = (Type)com.E.visit(this, ull); if (! etype.equals(type.bool)) error: coditio is ot a boolea com.1.visit(this, ull); com.2.visit(this, ull); retur ull; public Object visititegerexpr (ItegerExpr expr, Object arg) { expr.type = Type.it; retur expr.type; decoratig the ItegerExpr ode i the AST public class XYZ exts { Object visit(visitor v, Object arg) { retur v.visitxyz(this, arg); Ifmd E 1 2 ItegerExpr IL o eed to visit the Termial leaf hecker as a Visitor (4) public Object visitbiaryexpr (BiaryExpr expr, Object arg) { BiaryExpr Type e1type = (Type) expr.e1.visit(this, ull); Type e2type = (Type) expr.e2.visit(this, ull); Operatoreclaratio opdecl = E 1 (Operatoreclaratio) expr.o.visit(this, ull); if (opdecl == ull) { error: o such operator expr.type = Type.error; else if (opdecl istaceof BiaryOperatoreclaratio) { BiaryOperatoreclaratio bopdecl = (BiaryOperatoreclaratio) opdecl; if (! e1type.equals(bopdecl.operad1type)) error: left operad has the wrog type if (! e2type.equals(bopdecl.operad2type)) error: right operad has the wrog type expr.type = bopdecl.resulttype; else { error: operator is ot a biary operator expr.type = Type.error; O E 2 retur expr.type; See W&B for the other visitor methods Summary of visitig methods Table 5.1 Visitor patter (2) Program visitprogram retur ull ommad visit..md retur ull Expressio visit..expr decorate it with its type retur that type Vame visitsimplevame decorate it with its type set a flag idicatig if it is variable retur the type. eclaratio visit..ecl eter all declared idetifiers ito symbol table retur ull Typeeoter visit..typeeoter decorate it with its type retur that type All compoud ASTs also check for well-formedess. Idetifier visitidetifier check that the idetifier is declared set a referece to its bidig declaratio retur that declaratio Operator visitoperator check that the operator is declared set a referece to its bidig declaratio retur that declaratio The iterface Visitor declares for each AST class XYZ the method visitxyz(xyz x, Object arg). It is possible to reame all visitxyz methods to plai visit ad rely o Java s overloadig mechaism to select the correct visitor method. Not much is gaied by this reamig, though.! Still all AST classes should have a visit method, callig aother overloaded visit method with the this argumet (otherwise the overloadig will ot work).! As i geeral the visit methods for the AST classes are all differet, you will ot profit from iheritig visit methods of superclasses

15 Visitor patter (3) Nice (1) The Visitor patter has some drawbacks.! Argumets ad retur types of the visitig methods have to be kow i advace. For ew type of visitig methods, these methods have to be added to each AST class.! Visitor patter requires (substatial) preparatio: Visitor iterface with a abstract method for each AST ode; Each AST class should have a visit method; ode itself is tedious to write.! Visitor patter should be there from the start.! Visitor code withi the visit methods i the AST classes look obscure: they are meat for visitig, ot for checkig. Furthermore, the visitor patter should ot be used whe the object structure (i.e. AST hierarchy) o which it works is still chagig. Nice = Object-Orieted Programmig Laguage! research project: adds features from fuctioal laguages to Java! implemeted o top of Java, geerates bytecode! additioal features: Java 5 " parametric/geeric fuctios (like templates i ++) aoymous fuctios (istead of the heavy aoymous classes of Java) multi-methods (see below) tuples (to retur several values from fuctio; type-safe) Java 5 " optioal parameters to methods! Nice compiler is writte i Java ad i Nice Nice (2) With Nice the stadard OO-approach ad the Visitor-patter ca be combied quite icely usig multi-methods. Multi-methods (or multiple dispatch )! Allow to defie methods outside classes.! Istead of usig (oly) the receiver class to dispatch the method (usig overridig), oe ca use the argumets of the method to dispatch the method. Object check(ast ode); Object check(ode@biaryexpr) { Object check(ode@ifmd) { Object check(ode@assigmd) { No preparatio eeded (as for the Visitor patter) ode is shorter ad more atural. Withi this method you ca access ode as beig a Assigmd. The Nice project is ot very active (uderstatemet!). The MultiJava project is aother multiple dispatch attempt for Java. 59

CS 11 C track: lecture 1

CS 11 C track: lecture 1 CS 11 C track: lecture 1 Prelimiaries Need a CMS cluster accout http://acctreq.cms.caltech.edu/cgi-bi/request.cgi Need to kow UNIX IMSS tutorial liked from track home page Track home page: http://courses.cms.caltech.edu/courses/cs11/material

More information

COP4020 Programming Languages. Compilers and Interpreters Prof. Robert van Engelen

COP4020 Programming Languages. Compilers and Interpreters Prof. Robert van Engelen COP4020 mig Laguages Compilers ad Iterpreters Prof. Robert va Egele Overview Commo compiler ad iterpreter cofiguratios Virtual machies Itegrated developmet eviromets Compiler phases Lexical aalysis Sytax

More information

Chapter 11. Friends, Overloaded Operators, and Arrays in Classes. Copyright 2014 Pearson Addison-Wesley. All rights reserved.

Chapter 11. Friends, Overloaded Operators, and Arrays in Classes. Copyright 2014 Pearson Addison-Wesley. All rights reserved. Chapter 11 Frieds, Overloaded Operators, ad Arrays i Classes Copyright 2014 Pearso Addiso-Wesley. All rights reserved. Overview 11.1 Fried Fuctios 11.2 Overloadig Operators 11.3 Arrays ad Classes 11.4

More information

Today s objectives. CSE401: Introduction to Compiler Construction. What is a compiler? Administrative Details. Why study compilers?

Today s objectives. CSE401: Introduction to Compiler Construction. What is a compiler? Administrative Details. Why study compilers? CSE401: Itroductio to Compiler Costructio Larry Ruzzo Sprig 2004 Today s objectives Admiistrative details Defie compilers ad why we study them Defie the high-level structure of compilers Associate specific

More information

Abstract Syntax Trees. AST Data Structure. Visitor Interface. Accept methods. Visitor Methodology for AST Traversal CS412/CS413

Abstract Syntax Trees. AST Data Structure. Visitor Interface. Accept methods. Visitor Methodology for AST Traversal CS412/CS413 Abstract Syta Trees CS412/CS413 Itroductio to Copilers Ti Teitelbau Lecture 12: Visitors; Sybol Tables February 18, 2005 Separate AST costructio fro seatic checkig phase Traverse the AST ad perfor seatic

More information

From last week. Lecture 5. Outline. Principles of programming languages

From last week. Lecture 5. Outline. Principles of programming languages Priciples of programmig laguages From last week Lecture 5 http://few.vu.l/~silvis/ppl/2007 Natalia Silvis-Cividjia e-mail: silvis@few.vu.l ML has o assigmet. Explai how to access a old bidig? Is & for

More information

COP4020 Programming Languages. Functional Programming Prof. Robert van Engelen

COP4020 Programming Languages. Functional Programming Prof. Robert van Engelen COP4020 Programmig Laguages Fuctioal Programmig Prof. Robert va Egele Overview What is fuctioal programmig? Historical origis of fuctioal programmig Fuctioal programmig today Cocepts of fuctioal programmig

More information

Chapter 9. Pointers and Dynamic Arrays. Copyright 2015 Pearson Education, Ltd.. All rights reserved.

Chapter 9. Pointers and Dynamic Arrays. Copyright 2015 Pearson Education, Ltd.. All rights reserved. Chapter 9 Poiters ad Dyamic Arrays Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Overview 9.1 Poiters 9.2 Dyamic Arrays Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Slide 9-3

More information

Chapter 10. Defining Classes. Copyright 2015 Pearson Education, Ltd.. All rights reserved.

Chapter 10. Defining Classes. Copyright 2015 Pearson Education, Ltd.. All rights reserved. Chapter 10 Defiig Classes Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Overview 10.1 Structures 10.2 Classes 10.3 Abstract Data Types 10.4 Itroductio to Iheritace Copyright 2015 Pearso Educatio,

More information

Chapter 4. Procedural Abstraction and Functions That Return a Value. Copyright 2015 Pearson Education, Ltd.. All rights reserved.

Chapter 4. Procedural Abstraction and Functions That Return a Value. Copyright 2015 Pearson Education, Ltd.. All rights reserved. Chapter 4 Procedural Abstractio ad Fuctios That Retur a Value Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Overview 4.1 Top-Dow Desig 4.2 Predefied Fuctios 4.3 Programmer-Defied Fuctios 4.4

More information

Solutions to Final COMS W4115 Programming Languages and Translators Monday, May 4, :10-5:25pm, 309 Havemeyer

Solutions to Final COMS W4115 Programming Languages and Translators Monday, May 4, :10-5:25pm, 309 Havemeyer Departmet of Computer ciece Columbia Uiversity olutios to Fial COM W45 Programmig Laguages ad Traslators Moday, May 4, 2009 4:0-5:25pm, 309 Havemeyer Closed book, o aids. Do questios 5. Each questio is

More information

Last class. n Scheme. n Equality testing. n eq? vs. equal? n Higher-order functions. n map, foldr, foldl. n Tail recursion

Last class. n Scheme. n Equality testing. n eq? vs. equal? n Higher-order functions. n map, foldr, foldl. n Tail recursion Aoucemets HW6 due today HW7 is out A team assigmet Submitty page will be up toight Fuctioal correctess: 75%, Commets : 25% Last class Equality testig eq? vs. equal? Higher-order fuctios map, foldr, foldl

More information

Recursion. Computer Science S-111 Harvard University David G. Sullivan, Ph.D. Review: Method Frames

Recursion. Computer Science S-111 Harvard University David G. Sullivan, Ph.D. Review: Method Frames Uit 4, Part 3 Recursio Computer Sciece S-111 Harvard Uiversity David G. Sulliva, Ph.D. Review: Method Frames Whe you make a method call, the Java rutime sets aside a block of memory kow as the frame of

More information

n Haskell n Syntax n Lazy evaluation n Static typing and type inference n Algebraic data types n Pattern matching n Type classes

n Haskell n Syntax n Lazy evaluation n Static typing and type inference n Algebraic data types n Pattern matching n Type classes Aoucemets Quiz 7 HW 9 is due o Friday Raibow grades HW 1-6 plus 8. Please, read our commets o 8! Exam 1-2 Quiz 1-6 Ay questios/cocers, let us kow ASAP Last Class Haskell Sytax Lazy evaluatio Static typig

More information

University of Waterloo Department of Electrical and Computer Engineering ECE 250 Algorithms and Data Structures

University of Waterloo Department of Electrical and Computer Engineering ECE 250 Algorithms and Data Structures Uiversity of Waterloo Departmet of Electrical ad Computer Egieerig ECE 250 Algorithms ad Data Structures Midterm Examiatio ( pages) Istructor: Douglas Harder February 7, 2004 7:30-9:00 Name (last, first)

More information

top() Applications of Stacks

top() Applications of Stacks CS22 Algorithms ad Data Structures MW :00 am - 2: pm, MSEC 0 Istructor: Xiao Qi Lecture 6: Stacks ad Queues Aoucemets Quiz results Homework 2 is available Due o September 29 th, 2004 www.cs.mt.edu~xqicoursescs22

More information

Copyright 2016 Ramez Elmasri and Shamkant B. Navathe

Copyright 2016 Ramez Elmasri and Shamkant B. Navathe Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe CHAPTER 18 Strategies for Query Processig Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Itroductio DBMS techiques to process a query Scaer idetifies

More information

CS211 Fall 2003 Prelim 2 Solutions and Grading Guide

CS211 Fall 2003 Prelim 2 Solutions and Grading Guide CS11 Fall 003 Prelim Solutios ad Gradig Guide Problem 1: (a) obj = obj1; ILLEGAL because type of referece must always be a supertype of type of object (b) obj3 = obj1; ILLEGAL because type of referece

More information

Chapter 1. Introduction to Computers and C++ Programming. Copyright 2015 Pearson Education, Ltd.. All rights reserved.

Chapter 1. Introduction to Computers and C++ Programming. Copyright 2015 Pearson Education, Ltd.. All rights reserved. Chapter 1 Itroductio to Computers ad C++ Programmig Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Overview 1.1 Computer Systems 1.2 Programmig ad Problem Solvig 1.3 Itroductio to C++ 1.4 Testig

More information

Code Review Defects. Authors: Mika V. Mäntylä and Casper Lassenius Original version: 4 Sep, 2007 Made available online: 24 April, 2013

Code Review Defects. Authors: Mika V. Mäntylä and Casper Lassenius Original version: 4 Sep, 2007 Made available online: 24 April, 2013 Code Review s Authors: Mika V. Mätylä ad Casper Lasseius Origial versio: 4 Sep, 2007 Made available olie: 24 April, 2013 This documet cotais further details of the code review defects preseted i [1]. of

More information

n Haskell n Covered syntax, lazy evaluation, static typing n Algebraic data types and pattern matching n Type classes n Monads and more n Types

n Haskell n Covered syntax, lazy evaluation, static typing n Algebraic data types and pattern matching n Type classes n Monads and more n Types Aoucemets Exam 2 is graded, but I will eed some time to go over it I ll release grades this eveig (figers crossed!) Raibow grades: HW1-6, Exam 1-2, Quiz 1-5 Will post aswer key Still gradig: Quiz 6, HW7

More information

Python Programming: An Introduction to Computer Science

Python Programming: An Introduction to Computer Science Pytho Programmig: A Itroductio to Computer Sciece Chapter 1 Computers ad Programs 1 Objectives To uderstad the respective roles of hardware ad software i a computig system. To lear what computer scietists

More information

. Written in factored form it is easy to see that the roots are 2, 2, i,

. Written in factored form it is easy to see that the roots are 2, 2, i, CMPS A Itroductio to Programmig Programmig Assigmet 4 I this assigmet you will write a java program that determies the real roots of a polyomial that lie withi a specified rage. Recall that the roots (or

More information

implement language system

implement language system Outlie Priciples of programmig laguages Lecture 3 http://few.vu.l/~silvis/ppl/2007 Part I. Laguage systems Part II. Fuctioal programmig. First look at ML. Natalia Silvis-Cividjia e-mail: silvis@few.vu.l

More information

Abstract. Chapter 4 Computation. Overview 8/13/18. Bjarne Stroustrup Note:

Abstract. Chapter 4 Computation. Overview 8/13/18. Bjarne Stroustrup   Note: Chapter 4 Computatio Bjare Stroustrup www.stroustrup.com/programmig Abstract Today, I ll preset the basics of computatio. I particular, we ll discuss expressios, how to iterate over a series of values

More information

CIS 121. Introduction to Trees

CIS 121. Introduction to Trees CIS 121 Itroductio to Trees 1 Tree ADT Tree defiitio q A tree is a set of odes which may be empty q If ot empty, the there is a distiguished ode r, called root ad zero or more o-empty subtrees T 1, T 2,

More information

Classes and Objects. Again: Distance between points within the first quadrant. José Valente de Oliveira 4-1

Classes and Objects. Again: Distance between points within the first quadrant. José Valente de Oliveira 4-1 Classes ad Objects jvo@ualg.pt José Valete de Oliveira 4-1 Agai: Distace betwee poits withi the first quadrat Sample iput Sample output 1 1 3 4 2 jvo@ualg.pt José Valete de Oliveira 4-2 1 The simplest

More information

Computers and Scientific Thinking

Computers and Scientific Thinking Computers ad Scietific Thikig David Reed, Creighto Uiversity Chapter 15 JavaScript Strigs 1 Strigs as Objects so far, your iteractive Web pages have maipulated strigs i simple ways use text box to iput

More information

n Some thoughts on software development n The idea of a calculator n Using a grammar n Expression evaluation n Program organization n Analysis

n Some thoughts on software development n The idea of a calculator n Using a grammar n Expression evaluation n Program organization n Analysis Overview Chapter 6 Writig a Program Bjare Stroustrup Some thoughts o software developmet The idea of a calculator Usig a grammar Expressio evaluatio Program orgaizatio www.stroustrup.com/programmig 3 Buildig

More information

CSC 220: Computer Organization Unit 11 Basic Computer Organization and Design

CSC 220: Computer Organization Unit 11 Basic Computer Organization and Design College of Computer ad Iformatio Scieces Departmet of Computer Sciece CSC 220: Computer Orgaizatio Uit 11 Basic Computer Orgaizatio ad Desig 1 For the rest of the semester, we ll focus o computer architecture:

More information

Threads and Concurrency in Java: Part 1

Threads and Concurrency in Java: Part 1 Cocurrecy Threads ad Cocurrecy i Java: Part 1 What every computer egieer eeds to kow about cocurrecy: Cocurrecy is to utraied programmers as matches are to small childre. It is all too easy to get bured.

More information

COSC 1P03. Ch 7 Recursion. Introduction to Data Structures 8.1

COSC 1P03. Ch 7 Recursion. Introduction to Data Structures 8.1 COSC 1P03 Ch 7 Recursio Itroductio to Data Structures 8.1 COSC 1P03 Recursio Recursio I Mathematics factorial Fiboacci umbers defie ifiite set with fiite defiitio I Computer Sciece sytax rules fiite defiitio,

More information

Overview. Chapter 18 Vectors and Arrays. Reminder. vector. Bjarne Stroustrup

Overview. Chapter 18 Vectors and Arrays. Reminder. vector. Bjarne Stroustrup Chapter 18 Vectors ad Arrays Bjare Stroustrup Vector revisited How are they implemeted? Poiters ad free store Destructors Iitializatio Copy ad move Arrays Array ad poiter problems Chagig size Templates

More information

Threads and Concurrency in Java: Part 1

Threads and Concurrency in Java: Part 1 Threads ad Cocurrecy i Java: Part 1 1 Cocurrecy What every computer egieer eeds to kow about cocurrecy: Cocurrecy is to utraied programmers as matches are to small childre. It is all too easy to get bured.

More information

The Magma Database file formats

The Magma Database file formats The Magma Database file formats Adrew Gaylard, Bret Pikey, ad Mart-Mari Breedt Johaesburg, South Africa 15th May 2006 1 Summary Magma is a ope-source object database created by Chris Muller, of Kasas City,

More information

n We have discussed classes in previous lectures n Here, we discuss design of classes n Library design considerations

n We have discussed classes in previous lectures n Here, we discuss design of classes n Library design considerations Chapter 14 Graph class desig Bjare Stroustrup Abstract We have discussed classes i previous lectures Here, we discuss desig of classes Library desig cosideratios Class hierarchies (object-orieted programmig)

More information

Copyright 2016 Ramez Elmasri and Shamkant B. Navathe

Copyright 2016 Ramez Elmasri and Shamkant B. Navathe Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe CHAPTER 19 Query Optimizatio Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Itroductio Query optimizatio Coducted by a query optimizer i a DBMS Goal:

More information

condition w i B i S maximum u i

condition w i B i S maximum u i ecture 10 Dyamic Programmig 10.1 Kapsack Problem November 1, 2004 ecturer: Kamal Jai Notes: Tobias Holgers We are give a set of items U = {a 1, a 2,..., a }. Each item has a weight w i Z + ad a utility

More information

CIS 121 Data Structures and Algorithms with Java Spring Stacks, Queues, and Heaps Monday, February 18 / Tuesday, February 19

CIS 121 Data Structures and Algorithms with Java Spring Stacks, Queues, and Heaps Monday, February 18 / Tuesday, February 19 CIS Data Structures ad Algorithms with Java Sprig 09 Stacks, Queues, ad Heaps Moday, February 8 / Tuesday, February 9 Stacks ad Queues Recall the stack ad queue ADTs (abstract data types from lecture.

More information

How do we evaluate algorithms?

How do we evaluate algorithms? F2 Readig referece: chapter 2 + slides Algorithm complexity Big O ad big Ω To calculate ruig time Aalysis of recursive Algorithms Next time: Litterature: slides mostly The first Algorithm desig methods:

More information

Chapter 5. Functions for All Subtasks. Copyright 2015 Pearson Education, Ltd.. All rights reserved.

Chapter 5. Functions for All Subtasks. Copyright 2015 Pearson Education, Ltd.. All rights reserved. Chapter 5 Fuctios for All Subtasks Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Overview 5.1 void Fuctios 5.2 Call-By-Referece Parameters 5.3 Usig Procedural Abstractio 5.4 Testig ad Debuggig

More information

CIS 121 Data Structures and Algorithms with Java Spring Stacks and Queues Monday, February 12 / Tuesday, February 13

CIS 121 Data Structures and Algorithms with Java Spring Stacks and Queues Monday, February 12 / Tuesday, February 13 CIS Data Structures ad Algorithms with Java Sprig 08 Stacks ad Queues Moday, February / Tuesday, February Learig Goals Durig this lab, you will: Review stacks ad queues. Lear amortized ruig time aalysis

More information

Linked Lists 11/16/18. Preliminaries. Java References. Objects and references. Self references. Linking self-referential nodes

Linked Lists 11/16/18. Preliminaries. Java References. Objects and references. Self references. Linking self-referential nodes Prelimiaries Liked Lists public class StrageObject { Strig ame; StrageObject other; Arrays are ot always the optimal data structure: A array has fixed size eeds to be copied to expad its capacity Addig

More information

COP4020 Programming Languages. Subroutines and Parameter Passing Prof. Robert van Engelen

COP4020 Programming Languages. Subroutines and Parameter Passing Prof. Robert van Engelen COP4020 Programmig Laguages Subrouties ad Parameter Passig Prof. Robert va Egele Overview Parameter passig modes Subroutie closures as parameters Special-purpose parameters Fuctio returs COP4020 Fall 2016

More information

Basic allocator mechanisms The course that gives CMU its Zip! Memory Management II: Dynamic Storage Allocation Mar 6, 2000.

Basic allocator mechanisms The course that gives CMU its Zip! Memory Management II: Dynamic Storage Allocation Mar 6, 2000. 5-23 The course that gives CM its Zip Memory Maagemet II: Dyamic Storage Allocatio Mar 6, 2000 Topics Segregated lists Buddy system Garbage collectio Mark ad Sweep Copyig eferece coutig Basic allocator

More information

Package RcppRoll. December 22, 2014

Package RcppRoll. December 22, 2014 Type Package Package RcppRoll December 22, 2014 Title Fast rollig fuctios through Rcpp ad RcppArmadillo Versio 0.1.0 Date 2013-01-10 Author Kevi Ushey Maitaier Kevi Ushey RcppRoll

More information

Behavioral Modeling in Verilog

Behavioral Modeling in Verilog Behavioral Modelig i Verilog COE 202 Digital Logic Desig Dr. Muhamed Mudawar Kig Fahd Uiversity of Petroleum ad Mierals Presetatio Outlie Itroductio to Dataflow ad Behavioral Modelig Verilog Operators

More information

A SOFTWARE MODEL FOR THE MULTILAYER PERCEPTRON

A SOFTWARE MODEL FOR THE MULTILAYER PERCEPTRON A SOFTWARE MODEL FOR THE MULTILAYER PERCEPTRON Roberto Lopez ad Eugeio Oñate Iteratioal Ceter for Numerical Methods i Egieerig (CIMNE) Edificio C1, Gra Capitá s/, 08034 Barceloa, Spai ABSTRACT I this work

More information

CS 111: Program Design I Lecture 16: Module Review, Encodings, Lists

CS 111: Program Design I Lecture 16: Module Review, Encodings, Lists CS 111: Program Desig I Lecture 16: Module Review, Ecodigs, Lists Robert H. Sloa & Richard Warer Uiversity of Illiois at Chicago October 18, 2016 Last time Dot otatio ad methods Padas: user maual poit

More information

Chapter 2. C++ Basics. Copyright 2015 Pearson Education, Ltd.. All rights reserved.

Chapter 2. C++ Basics. Copyright 2015 Pearson Education, Ltd.. All rights reserved. Chapter 2 C++ Basics Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Overview 2.1 Variables ad Assigmets 2.2 Iput ad Output 2.3 Data Types ad Expressios 2.4 Simple Flow of Cotrol 2.5 Program

More information

1.2 Binomial Coefficients and Subsets

1.2 Binomial Coefficients and Subsets 1.2. BINOMIAL COEFFICIENTS AND SUBSETS 13 1.2 Biomial Coefficiets ad Subsets 1.2-1 The loop below is part of a program to determie the umber of triagles formed by poits i the plae. for i =1 to for j =

More information

Location Steps and Paths

Location Steps and Paths Locatio Steps ad Paths 3 INTHIS CHAPTER Uderstadig Locatio Steps ad Paths How do locatio paths work? We took a look at locatio paths i the overview i Chapter 1, where we saw that locatio paths look much

More information

CS : Programming for Non-Majors, Summer 2007 Programming Project #3: Two Little Calculations Due by 12:00pm (noon) Wednesday June

CS : Programming for Non-Majors, Summer 2007 Programming Project #3: Two Little Calculations Due by 12:00pm (noon) Wednesday June CS 1313 010: Programmig for No-Majors, Summer 2007 Programmig Project #3: Two Little Calculatios Due by 12:00pm (oo) Wedesday Jue 27 2007 This third assigmet will give you experiece writig programs that

More information

Exceptions. Your computer takes exception. The Exception Class. Causes of Exceptions

Exceptions. Your computer takes exception. The Exception Class. Causes of Exceptions Your computer takes exceptio s s are errors i the logic of a program (ru-time errors). Examples: i thread mai java.io.filenotfoud: studet.txt (The system caot fid the file specified.) i thread mai java.lag.nullpoiter:

More information

Python Programming: An Introduction to Computer Science

Python Programming: An Introduction to Computer Science Pytho Programmig: A Itroductio to Computer Sciece Chapter 6 Defiig Fuctios Pytho Programmig, 2/e 1 Objectives To uderstad why programmers divide programs up ito sets of cooperatig fuctios. To be able to

More information

Getting Started. Getting Started - 1

Getting Started. Getting Started - 1 Gettig Started Gettig Started - 1 Issue 1 Overview of Gettig Started Overview of Gettig Started This sectio explais the basic operatios of the AUDIX system. It describes how to: Log i ad log out of the

More information

Elementary Educational Computer

Elementary Educational Computer Chapter 5 Elemetary Educatioal Computer. Geeral structure of the Elemetary Educatioal Computer (EEC) The EEC coforms to the 5 uits structure defied by vo Neuma's model (.) All uits are preseted i a simplified

More information

Last Class. Announcements. Lecture Outline. Types. Structural Equivalence. Type Equivalence. Read: Scott, Chapters 7 and 8. T2 y; x = y; n Types

Last Class. Announcements. Lecture Outline. Types. Structural Equivalence. Type Equivalence. Read: Scott, Chapters 7 and 8. T2 y; x = y; n Types Aoucemets HW9 due today HW10 comig up, will post after class Team assigmet Data abstractio (types) ad cotrol abstractio (parameter passig) Due o Tuesday, November 27 th Last Class Types Type systems Type

More information

Lecture 1: Introduction and Strassen s Algorithm

Lecture 1: Introduction and Strassen s Algorithm 5-750: Graduate Algorithms Jauary 7, 08 Lecture : Itroductio ad Strasse s Algorithm Lecturer: Gary Miller Scribe: Robert Parker Itroductio Machie models I this class, we will primarily use the Radom Access

More information

Structuring Redundancy for Fault Tolerance. CSE 598D: Fault Tolerant Software

Structuring Redundancy for Fault Tolerance. CSE 598D: Fault Tolerant Software Structurig Redudacy for Fault Tolerace CSE 598D: Fault Tolerat Software What do we wat to achieve? Versios Damage Assessmet Versio 1 Error Detectio Iputs Versio 2 Voter Outputs State Restoratio Cotiued

More information

EE 459/500 HDL Based Digital Design with Programmable Logic. Lecture 13 Control and Sequencing: Hardwired and Microprogrammed Control

EE 459/500 HDL Based Digital Design with Programmable Logic. Lecture 13 Control and Sequencing: Hardwired and Microprogrammed Control EE 459/500 HDL Based Digital Desig with Programmable Logic Lecture 13 Cotrol ad Sequecig: Hardwired ad Microprogrammed Cotrol Refereces: Chapter s 4,5 from textbook Chapter 7 of M.M. Mao ad C.R. Kime,

More information

Chapter 3. More Flow of Control. Copyright 2015 Pearson Education, Ltd.. All rights reserved.

Chapter 3. More Flow of Control. Copyright 2015 Pearson Education, Ltd.. All rights reserved. Chapter 3 More Flow of Cotrol Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Overview 3.1 Usig Boolea Expressios 3.2 Multiway Braches 3.3 More about C++ Loop Statemets 3.4 Desigig Loops Copyright

More information

Chapter 4 The Datapath

Chapter 4 The Datapath The Ageda Chapter 4 The Datapath Based o slides McGraw-Hill Additioal material 24/25/26 Lewis/Marti Additioal material 28 Roth Additioal material 2 Taylor Additioal material 2 Farmer Tae the elemets that

More information

Chapter 8. Strings and Vectors. Copyright 2014 Pearson Addison-Wesley. All rights reserved.

Chapter 8. Strings and Vectors. Copyright 2014 Pearson Addison-Wesley. All rights reserved. Chapter 8 Strigs ad Vectors Overview 8.1 A Array Type for Strigs 8.2 The Stadard strig Class 8.3 Vectors Slide 8-3 8.1 A Array Type for Strigs A Array Type for Strigs C-strigs ca be used to represet strigs

More information

Announcements TREES II. Comparing Data Structures. Binary Search Trees. Red-Black Trees. Red-Black Trees 3/13/18

Announcements TREES II. Comparing Data Structures. Binary Search Trees. Red-Black Trees. Red-Black Trees 3/13/18 //8 Aoucemets Prelim is Toight, brig your studet ID :PM EXAM OLH: etids startig aa to dh OLH: etids startig di to ji PHL: etids startig jj to ks (Plus studets who switched from the 7: exam) TREES II Lecture

More information

Analysis Metrics. Intro to Algorithm Analysis. Slides. 12. Alg Analysis. 12. Alg Analysis

Analysis Metrics. Intro to Algorithm Analysis. Slides. 12. Alg Analysis. 12. Alg Analysis Itro to Algorithm Aalysis Aalysis Metrics Slides. Table of Cotets. Aalysis Metrics 3. Exact Aalysis Rules 4. Simple Summatio 5. Summatio Formulas 6. Order of Magitude 7. Big-O otatio 8. Big-O Theorems

More information

! Given the following Structure: ! We can define a pointer to a structure. ! Now studentptr points to the s1 structure.

! Given the following Structure: ! We can define a pointer to a structure. ! Now studentptr points to the s1 structure. Liked Lists Uit 5 Sectios 11.9 & 18.1-2 CS 2308 Fall 2018 Jill Seama 11.9: Poiters to Structures! Give the followig Structure: struct Studet { strig ame; // Studet s ame it idnum; // Studet ID umber it

More information

10/23/18. File class in Java. Scanner reminder. Files. Opening a file for reading. Scanner reminder. File Input and Output

10/23/18. File class in Java. Scanner reminder. Files. Opening a file for reading. Scanner reminder. File Input and Output File class i Java File Iput ad Output TOPICS File Iput Exceptio Hadlig File Output Programmers refer to iput/output as "I/O". The File class represets files as objects. The class is defied i the java.io

More information

Priority Queues. Binary Heaps

Priority Queues. Binary Heaps Priority Queues Biary Heaps Priority Queues Priority: some property of a object that allows it to be prioritized with respect to other objects of the same type Mi Priority Queue: homogeeous collectio of

More information

Pseudocode ( 1.1) Analysis of Algorithms. Primitive Operations. Pseudocode Details. Running Time ( 1.1) Estimating performance

Pseudocode ( 1.1) Analysis of Algorithms. Primitive Operations. Pseudocode Details. Running Time ( 1.1) Estimating performance Aalysis of Algorithms Iput Algorithm Output A algorithm is a step-by-step procedure for solvig a problem i a fiite amout of time. Pseudocode ( 1.1) High-level descriptio of a algorithm More structured

More information

Hash Tables. Presentation for use with the textbook Algorithm Design and Applications, by M. T. Goodrich and R. Tamassia, Wiley, 2015.

Hash Tables. Presentation for use with the textbook Algorithm Design and Applications, by M. T. Goodrich and R. Tamassia, Wiley, 2015. Presetatio for use with the textbook Algorithm Desig ad Applicatios, by M. T. Goodrich ad R. Tamassia, Wiley, 2015 Hash Tables xkcd. http://xkcd.com/221/. Radom Number. Used with permissio uder Creative

More information

What are we going to learn? CSC Data Structures Analysis of Algorithms. Overview. Algorithm, and Inputs

What are we going to learn? CSC Data Structures Analysis of Algorithms. Overview. Algorithm, and Inputs What are we goig to lear? CSC316-003 Data Structures Aalysis of Algorithms Computer Sciece North Carolia State Uiversity Need to say that some algorithms are better tha others Criteria for evaluatio Structure

More information

Chapter 8. Strings and Vectors. Copyright 2015 Pearson Education, Ltd.. All rights reserved.

Chapter 8. Strings and Vectors. Copyright 2015 Pearson Education, Ltd.. All rights reserved. Chapter 8 Strigs ad Vectors Copyright 2015 Pearso Educatio, Ltd.. All rights reserved. Overview 8.1 A Array Type for Strigs 8.2 The Stadard strig Class 8.3 Vectors Copyright 2015 Pearso Educatio, Ltd..

More information

Introduction to Computing Systems: From Bits and Gates to C and Beyond 2 nd Edition

Introduction to Computing Systems: From Bits and Gates to C and Beyond 2 nd Edition Lecture Goals Itroductio to Computig Systems: From Bits ad Gates to C ad Beyod 2 d Editio Yale N. Patt Sajay J. Patel Origial slides from Gregory Byrd, North Carolia State Uiversity Modified slides by

More information

CS 111: Program Design I Lecture 20: Web crawling, HTML, Copyright

CS 111: Program Design I Lecture 20: Web crawling, HTML, Copyright CS 111: Program Desig I Lecture 20: Web crawlig, HTML, Copyright Robert H. Sloa & Richard Warer Uiversity of Illiois at Chicago November 8, 2016 WEB CRAWLER AGAIN Two bits of useful Pytho sytax Do't eed

More information

EE260: Digital Design, Spring /16/18. n Example: m 0 (=x 1 x 2 ) is adjacent to m 1 (=x 1 x 2 ) and m 2 (=x 1 x 2 ) but NOT m 3 (=x 1 x 2 )

EE260: Digital Design, Spring /16/18. n Example: m 0 (=x 1 x 2 ) is adjacent to m 1 (=x 1 x 2 ) and m 2 (=x 1 x 2 ) but NOT m 3 (=x 1 x 2 ) EE26: Digital Desig, Sprig 28 3/6/8 EE 26: Itroductio to Digital Desig Combiatioal Datapath Yao Zheg Departmet of Electrical Egieerig Uiversity of Hawaiʻi at Māoa Combiatioal Logic Blocks Multiplexer Ecoders/Decoders

More information

Data Structures and Algorithms. Analysis of Algorithms

Data Structures and Algorithms. Analysis of Algorithms Data Structures ad Algorithms Aalysis of Algorithms Outlie Ruig time Pseudo-code Big-oh otatio Big-theta otatio Big-omega otatio Asymptotic algorithm aalysis Aalysis of Algorithms Iput Algorithm Output

More information

COP4020 Programming Languages. Names, Scopes, and Bindings Prof. Robert van Engelen

COP4020 Programming Languages. Names, Scopes, and Bindings Prof. Robert van Engelen COP4020 Programmig Laguages Names, Scopes, ad Bidigs Prof. Robert va Egele Overview Abstractios ad ames Bidig time Object lifetime Object storage maagemet Static allocatio Stack allocatio Heap allocatio

More information

Outline and Reading. Analysis of Algorithms. Running Time. Experimental Studies. Limitations of Experiments. Theoretical Analysis

Outline and Reading. Analysis of Algorithms. Running Time. Experimental Studies. Limitations of Experiments. Theoretical Analysis Outlie ad Readig Aalysis of Algorithms Iput Algorithm Output Ruig time ( 3.) Pseudo-code ( 3.2) Coutig primitive operatios ( 3.3-3.) Asymptotic otatio ( 3.6) Asymptotic aalysis ( 3.7) Case study Aalysis

More information

Running Time. Analysis of Algorithms. Experimental Studies. Limitations of Experiments

Running Time. Analysis of Algorithms. Experimental Studies. Limitations of Experiments Ruig Time Aalysis of Algorithms Iput Algorithm Output A algorithm is a step-by-step procedure for solvig a problem i a fiite amout of time. Most algorithms trasform iput objects ito output objects. The

More information

Ones Assignment Method for Solving Traveling Salesman Problem

Ones Assignment Method for Solving Traveling Salesman Problem Joural of mathematics ad computer sciece 0 (0), 58-65 Oes Assigmet Method for Solvig Travelig Salesma Problem Hadi Basirzadeh Departmet of Mathematics, Shahid Chamra Uiversity, Ahvaz, Ira Article history:

More information

Appendix D. Controller Implementation

Appendix D. Controller Implementation COMPUTER ORGANIZATION AND DESIGN The Hardware/Software Iterface 5 th Editio Appedix D Cotroller Implemetatio Cotroller Implemetatios Combiatioal logic (sigle-cycle); Fiite state machie (multi-cycle, pipelied);

More information

Lower Bounds for Sorting

Lower Bounds for Sorting Liear Sortig Topics Covered: Lower Bouds for Sortig Coutig Sort Radix Sort Bucket Sort Lower Bouds for Sortig Compariso vs. o-compariso sortig Decisio tree model Worst case lower boud Compariso Sortig

More information

Topics. Instance object. Instance object. Fundamentals of OT. Object notation. How do objects collaborate? Pearson Education 2007 Appendix (RASD 3/e)

Topics. Instance object. Instance object. Fundamentals of OT. Object notation. How do objects collaborate? Pearson Education 2007 Appendix (RASD 3/e) Appedix (RASD 3/e) MACIASZEK, L.A. (2007): Requiremets Aalysis ad System Desig, 3 rd ed. Addiso Wesley, Harlow Eglad ISBN 978-0-321-44036-5 Appedix Fudametals of Object Techology Pearso Educatio Limited

More information

Running Time ( 3.1) Analysis of Algorithms. Experimental Studies. Limitations of Experiments

Running Time ( 3.1) Analysis of Algorithms. Experimental Studies. Limitations of Experiments Ruig Time ( 3.1) Aalysis of Algorithms Iput Algorithm Output A algorithm is a step- by- step procedure for solvig a problem i a fiite amout of time. Most algorithms trasform iput objects ito output objects.

More information

Analysis of Algorithms

Analysis of Algorithms Aalysis of Algorithms Iput Algorithm Output A algorithm is a step-by-step procedure for solvig a problem i a fiite amout of time. Ruig Time Most algorithms trasform iput objects ito output objects. The

More information

9.1. Sequences and Series. Sequences. What you should learn. Why you should learn it. Definition of Sequence

9.1. Sequences and Series. Sequences. What you should learn. Why you should learn it. Definition of Sequence _9.qxd // : AM Page Chapter 9 Sequeces, Series, ad Probability 9. Sequeces ad Series What you should lear Use sequece otatio to write the terms of sequeces. Use factorial otatio. Use summatio otatio to

More information

Lecture 5. Counting Sort / Radix Sort

Lecture 5. Counting Sort / Radix Sort Lecture 5. Coutig Sort / Radix Sort T. H. Corme, C. E. Leiserso ad R. L. Rivest Itroductio to Algorithms, 3rd Editio, MIT Press, 2009 Sugkyukwa Uiversity Hyuseug Choo choo@skku.edu Copyright 2000-2018

More information

Analysis of Algorithms

Analysis of Algorithms Aalysis of Algorithms Ruig Time of a algorithm Ruig Time Upper Bouds Lower Bouds Examples Mathematical facts Iput Algorithm Output A algorithm is a step-by-step procedure for solvig a problem i a fiite

More information

Data Structures Week #5. Trees (Ağaçlar)

Data Structures Week #5. Trees (Ağaçlar) Data Structures Week #5 Trees Ağaçlar) Trees Ağaçlar) Toros Gökarı Avrupa Gökarı October 28, 2014 Boraha Tümer, Ph.D. 2 Trees Ağaçlar) October 28, 2014 Boraha Tümer, Ph.D. 3 Outlie Trees Deiitios Implemetatio

More information

CS 111 Green: Program Design I Lecture 27: Speed (cont.); parting thoughts

CS 111 Green: Program Design I Lecture 27: Speed (cont.); parting thoughts CS 111 Gree: Program Desig I Lecture 27: Speed (cot.); partig thoughts By Nascarkig - Ow work, CC BY-SA 4.0, https://commos.wikimedia.org/w/idex.php?curid=38671041 Robert H. Sloa (CS) & Rachel Poretsky

More information

Polynomial Functions and Models. Learning Objectives. Polynomials. P (x) = a n x n + a n 1 x n a 1 x + a 0, a n 0

Polynomial Functions and Models. Learning Objectives. Polynomials. P (x) = a n x n + a n 1 x n a 1 x + a 0, a n 0 Polyomial Fuctios ad Models 1 Learig Objectives 1. Idetify polyomial fuctios ad their degree 2. Graph polyomial fuctios usig trasformatios 3. Idetify the real zeros of a polyomial fuctio ad their multiplicity

More information

Goals of the Lecture Object Constraint Language

Goals of the Lecture Object Constraint Language Goals of the Lecture Object Costrait Laguage Object-Orieted Aalysis ad Desig - Fall 1998 Preset the Object Costrait Laguage Ð As best as possible, with the limited iformatio available from UML i a Nutshell

More information

CYK Algorithm Adapted to the Penttonen Normal Form

CYK Algorithm Adapted to the Penttonen Normal Form http://excel.fit.vutbr.cz CYK Algorithm Adapted to the Pettoe Normal Form Domiika Klobučíková* Abstract This paper deals with the topic of cotext-sesitive grammars as special cases of urestricted grammars,

More information

Data diverse software fault tolerance techniques

Data diverse software fault tolerance techniques Data diverse software fault tolerace techiques Complemets desig diversity by compesatig for desig diversity s s limitatios Ivolves obtaiig a related set of poits i the program data space, executig the

More information

CS 111: Program Design I Lecture 15: Objects, Pandas, Modules. Robert H. Sloan & Richard Warner University of Illinois at Chicago October 13, 2016

CS 111: Program Design I Lecture 15: Objects, Pandas, Modules. Robert H. Sloan & Richard Warner University of Illinois at Chicago October 13, 2016 CS 111: Program Desig I Lecture 15: Objects, Padas, Modules Robert H. Sloa & Richard Warer Uiversity of Illiois at Chicago October 13, 2016 OBJECTS AND DOT NOTATION Objects (Implicit i Chapter 2, Variables,

More information

Workflow model GM AR. Gumpy. Dynagump. At a very high level, this is what gump does. We ll be looking at each of the items described here seperately.

Workflow model GM AR. Gumpy. Dynagump. At a very high level, this is what gump does. We ll be looking at each of the items described here seperately. Workflow model GM AR Gumpy RM Dyagump At a very high level, this is what gump does. We ll be lookig at each of the items described here seperately. User edits project descriptor ad commits s maitai their

More information

The Implementation of Data Structures in Version 5 of Icon* Ralph E. Gr is wo Id TR 85-8

The Implementation of Data Structures in Version 5 of Icon* Ralph E. Gr is wo Id TR 85-8 The Implemetatio of Data Structures i Versio 5 of Ico* Ralph E. Gr is wo Id TR 85-8 April 1, 1985 Departmet of Computer Sciece The Uiversity of Arizoa Tucso. Arizoa 85721 This work was supported by the

More information

Abstract Data Types (ADTs) Stacks. The Stack ADT ( 4.2) Stack Interface in Java

Abstract Data Types (ADTs) Stacks. The Stack ADT ( 4.2) Stack Interface in Java Abstract Data Types (ADTs) tacks A abstract data type (ADT) is a abstractio of a data structure A ADT specifies: Data stored Operatios o the data Error coditios associated with operatios Example: ADT modelig

More information

CMPT 125 Assignment 2 Solutions

CMPT 125 Assignment 2 Solutions CMPT 25 Assigmet 2 Solutios Questio (20 marks total) a) Let s cosider a iteger array of size 0. (0 marks, each part is 2 marks) it a[0]; I. How would you assig a poiter, called pa, to store the address

More information