Compiler Design Spring 2017
|
|
- Tiffany Floyd
- 6 years ago
- Views:
Transcription
1 Compiler Design Spring 2017 Patterns (again) Dr. Zoltán Majó Compiler Group Java HotSpot Virtual Machine Oracle Corporation
2 Why? Remember questionnaire (from the beginning of the semester)? Question 7: Please name three design patterns that you encountered in earlier projects/classes. Answers Mention Visitor pattern: 20% Mention other pattern(s): 25% Blank: 55% 2
3 Why some technical reasons Control flow always difficult to deal with Patterns like Strategy or Iterator raise the level of programming Hide details Easier to read than explicit control flow statements Simpler to write Easier to extend/understand/maintain 3
4 Trivial example Print date using different formats Option 1: Test at each place in the program P where the date is to be printed switch(format): { case (INTERNATIONAL): // print YEAR-MONTH-DAY break; case (BANK): // print MONTH-DAY-YEAR break;... Option 2: Invoke function/method F passed to P F is defined so that the correct format is chosen 4
5 Auxiliary classes import java.util.calendar; import java.util.gregoriancalendar; import java.util.date; class MyDate { int day; int month; int year; // Won t work in long-lived programs MyDate() { Calendar cal = new GregorianCalendar(); year = cal.get(cal.year); month = cal.get(cal.month); day = cal.get(cal.day_of_month); 5
6 Select format 1 (international) interface Print { void print(); class InternationalFormatPrint implements Print { MyDate d_; InternationalFormatPrint(MyDate d) { d_ = d; public void print() { System.out.println(d_.day + "/" + d_.month + "/" + d_.year ); 6
7 Select format 2 (international) class BankFormatPrint implements Print { MyDate d_; BankFormatPrint (MyDate d) { d_ = d; public void print() { System.out.println(d_.month + "/" + d_.day +"/" + d_.year ); 7
8 Example public static void main(string args[]) { MyDate d = new MyDate(); Print p = selectprinter(d); dotheprinting(p); static Print selectprinter(date d) { if (user.input() == b ) { return new BankFormatPrint(d); else { return new InternationalFormatPrint(d); static void dotheprinting(print service) { service.print(); 8
9 Output Test6> java Test6 30/1/1997 Test6> java Test6 1/30/1997 Not a big deal (This is a simple example after all) But the idea is powerful No need to deal with a possibly complicated switch-statement Only passing the printer instance as parameter is needed 9
10 Other advantage: Extensibility Imagine adding support for a new format, e.g., Japanese With Option 1: Extending switch statement is required switch(format): { case (INTERNATIONAL): // print YEAR-MONTH-DAY break; case (BANK): // print MONTH-DAY-YEAR break; case (JAPANESE): // print YEAR-MONTH-DAY break; At all places where formatting is needed Error-prone High risk of introducing inconsistent behavior 10
11 Other advantage: Extensibility Option 2: Requires only adding a new implementation for the Print interface class JapaneseFormatPrint implements Print { MyDate d_; JapaneseFormatPrint(MyDate d) { d_ = d; public void print() { System.out.println(d_.year + "/" + d_.month +"/" + d_.day ); Where new formatting is needed: Pass a JapaneseFormat-Print instance to existing code 11
12 public static void main(string args[]) { MyDate d = new MyDate(); Print p = selectprinter(d); dotheprinting(p); static Print selectprinter(date d) { if (user.input() == b ) { return new BankFormatPrint(d); else if (user.input() == j ){ return new JapaneseFormatPrint(d); else { return new InternationalFormatPrint(d); static void dotheprinting(print service) { service.print(); 12
13 The Strategy pattern You ve just seen an example of the Strategy pattern Context contextinterface() Strategy algorithminterface() ConcreteStrategy1 algorithminterface() ConcreteStrategy2 algorithminterface() ConcreteStrategy3 algorithminterface() 13
14 The Strategy pattern You ve just seen an example of the Strategy pattern MyDate // direct access to fields Print print() BankFormatPrint print() Int lformatprint print() JapaneseFormatPrint print() 14
15 The Strategy pattern Idea: Encapsulate a set of related algorithms into a class hierarchy Benefit: Simplify control-flow (e.g., reduce the need for conditional statements) Benefit: Algorithm can be changed independently of context Benefit: Decouple implementation of algorithm from data structure(s) in context 15
16 Is Strategy really that great? Should we always use Strategy when our program uses at least two different algorithms on one data structure? It depends A pattern is a solution that works well in some settings But not always You have to weight pros/cons 16
17 Pros/cons A switch-statement is not that bad after all If you have a program with two algorithms and a data structure A program will not be changed/extended Don t forget: Change is rather the norm and not an exception Implementing Strategy (often) requires interface/virtual calls (Some) VM engineers: Don t use virtual calls, they re expensive Good for performance, maintenance cost paid later 17
18 An alternative MyDate print() BankFormatDate print() Int lformatdate print() JapaneseFormatDate print() Advantage: Simpler class structure Disadvantage: Mixes MyDate and algorithms that operate on it Can become a problem if algorithms and/or data structure in MyDate complicated 18
19 Working with data structures MyDate: Only three integer fields Direct access to fields sufficient to print date MyDate // direct access to fields Print print() BankFormatPrint print() Int lformatprint print() JapaneseFormatPrint print() 19
20 Working with complex data structures What should we do if the data structure is complex? We could use an iterator to enumerate all elements Example: list of dates class JapaneseFormatPrint implements Print { List<MyDate> list_; JapaneseFormatPrint(List<MyDate> list) { list_ = list; public void print() { Iterator iter; while (iter.hasnext()) { MyDate d = iter.next() System.out.println(d_.year + "/" + d_.month +"/" + d_.day ); 20
21 What about accessing even more complex data structures? There may not be an iterator The order of processing/invoking a method may matter (Just think of trees) Visitor pattern internalizes the logic of visiting the elements 21
22 Visitor Coupling of data structure and access method(s) Powerful in connection with trees Object must be prepared to accept a visitor Example: arithmetic expressions Sums Constants 23
23 Visitor // Data structure abstract class ArithExpr { abstract int accept(visitor v); // Visitor interface Visitor { int forconst(const c); int forsum(sum s); 24
24 class Const extends ArithExpr { private int value; Const (int v) { value = v; int getvalue() { return value; int accept(visitor v) { return v.forconst(this); class Sum extends ArithExpr { ArithExpr left, right; Sum (ArithExpr l, ArithExpr r) { left = l; right = r; ArithExpr getleft() { return left; ArithExpr getright() { return right; int accept(visitor v) { return v.forsum(this); 25
25 Visitor examples class EvalVisitor implements Visitor { public int forconst(const c) { return c.getvalue(); public int forsum(sum s) { return s.getleft().accept(this) + s.getright().accept(this); class CountVisitor implements Visitor { public int forconst(const c) { return 1; public int forsum(sum s) { return s.getleft().accept(this) + s.getright()).accept(this);
26 Example, continued class ShowArithVisitors { public static void main(string[] args) { ArithExpr c2, c3, s1, s2; c2 = new Const(2); c3 = new Const(3); s1 = new Sum(c2,c3); s2 = new Sum(c2, s1); Visitor v1 = new EvalVisitor(); Visitor v2 = new CountVisitor(); System.out.println(s2.accept(v1)); System.out.println(s2.accept(v2));
27 Discussion Who s responsible for traversing the object structure? In our case: the visitor class EvalVisitor implements Visitor { public int forsum(sum s) { return s.getleft().accept(this) + s.getright().accept(this); Could be the object structure as well class Sum extends ArithExpr { int accept(visitor v) { return getleft().accept(v) + getright().accept(v); 29
28 Discussion (cont d) Should we always use the Visitor pattern for programs operating on tree-like object structures? It depends. Visitor beneficial if: Object structure contains objects with different (unrelated) functionality E.g., Const represents a value via the field value Sum is an arithmetic expression with fields left and right 30
29 Discussion (cont d) Should we always use the Visitor pattern for programs operating on tree-like object structures? It depends. Visitor beneficial if: Object structure contains objects with different (unrelated) functionality E.g., Const represents a value via the field value Sum is an arithmetic expression with fields left and right Object structure changes rarely but new operations are added often E.g., JavaLi compiler: IR changes rarely, various implemented in visitors 32
30 Summary Design pattern: A possible way to design (part of) your program (Some) benefits: Simpler code, extensibility, maintainability Not a general solution: You have to weigh pros/cons Patterns we ve talked about: Strategy, Iterator (briefly), Visitor More to come 33
31 Admin issues Design patterns homework (HWP) Out today, due on April 13 No points awarded You ll get feedback for the code you ve submitted Next recitation session: Thursday, March 30 In the lecture room at lecture time CAB G 10:15 Discussion of Homework 3 Symbol table and semantic checker Out on Thursday More about patterns 34
Compiler Design Spring 2017
Compiler Design Spring 2017 7.5 Method invocation Dr. Zoltán Majó Compiler Group Java HotSpot Virtual Machine Oracle Corporation 1 Admin issues There will be a recitation session today In CAB G 11 @ 15:15
More informationCompiler Design Spring 2017
Compiler Design Spring 2017 8.0 Data-Flow Analysis Dr. Zoltán Majó Compiler Group Java HotSpot Virtual Machine Oracle Corporation Admin issues There will be a code review session next week On Thursday
More informationDesign Patterns: State, Bridge, Visitor
Design Patterns: State, Bridge, Visitor State We ve been talking about bad uses of case statements in programs. What is one example? Another way in which case statements are sometimes used is to implement
More informationThink of drawing/diagramming editors. ECE450 Software Engineering II. The problem. The Composite pattern
Think of drawing/diagramming editors ECE450 Software Engineering II Drawing/diagramming editors let users build complex diagrams out of simple components The user can group components to form larger components......which
More informationNotes - Recursion. A geeky definition of recursion is as follows: Recursion see Recursion.
Notes - Recursion So far we have only learned how to solve problems iteratively using loops. We will now learn how to solve problems recursively by having a method call itself. A geeky definition of recursion
More informationLecture 8: Iterators and More Mutation
Integrated Introduction to Computer Science Fisler, Nelson Contents 1 Traversing Lists 1 2 Motivating Iterators 2 3 Writing an Iterator 3 4 Writing Sum with an Iterator 4 Objectives By the end of this
More informationCSC-140 Assignment 6
CSC-140 Assignment 6 1 Introduction In this assignment we will start out defining our own classes. For now, we will design a class that represents a date, e.g., Tuesday, March 15, 2011, or in short hand
More informationName Return type Argument list. Then the new method is said to override the old one. So, what is the objective of subclass?
1. Overriding Methods A subclass can modify behavior inherited from a parent class. A subclass can create a method with different functionality than the parent s method but with the same: Name Return type
More informationPart VII. Object-Oriented Programming. Philip Blakely (LSC) C++ Introduction 194 / 370
Part VII Object-Oriented Programming Philip Blakely (LSC) C++ Introduction 194 / 370 OOP Outline 24 Object-Oriented Programming 25 Member functions 26 Constructors 27 Destructors 28 More constructors Philip
More informationProject Compiler. CS031 TA Help Session November 28, 2011
Project Compiler CS031 TA Help Session November 28, 2011 Motivation Generally, it s easier to program in higher-level languages than in assembly. Our goal is to automate the conversion from a higher-level
More informationLecture Notes, CSE 232, Fall 2014 Semester
Lecture Notes, CSE 232, Fall 2014 Semester Dr. Brett Olsen Week 11 - Number Theory Number theory is the study of the integers. The most basic concept in number theory is divisibility. We say that b divides
More informationC++ Alexander Baltatzis
C++ Alexander Baltatzis Recap Undefined behaviour int * q1 = new int[2]; delete q1; int * q2 = new int; delete [] q2; Contract with the compiler constructor How would you implement delete [] Classes with
More informationCompiler Design Spring 2018
Compiler Design Spring 2018 Thomas R. Gross Computer Science Department ETH Zurich, Switzerland 1 Logistics Lecture Tuesdays: 10:15 11:55 Thursdays: 10:15 -- 11:55 In ETF E1 Recitation Announced later
More informationProgramming Language Concepts: Lecture 2
Programming Language Concepts: Lecture 2 Madhavan Mukund Chennai Mathematical Institute madhavan@cmi.ac.in http://www.cmi.ac.in/~madhavan/courses/pl2011 PLC 2011, Lecture 2, 6 January 2011 Classes and
More informationCS1004: Intro to CS in Java, Spring 2005
CS1004: Intro to CS in Java, Spring 2005 Lecture #13: Java OO cont d. Janak J Parekh janak@cs.columbia.edu Administrivia Homework due next week Problem #2 revisited Constructors, revisited Remember: a
More informationCOSC 2P91. Introduction Part Deux. Week 1b. Brock University. Brock University (Week 1b) Introduction Part Deux 1 / 14
COSC 2P91 Introduction Part Deux Week 1b Brock University Brock University (Week 1b) Introduction Part Deux 1 / 14 Source Files Like most other compiled languages, we ll be dealing with a few different
More informationLecture 19 CSE August You taught me Language, and my profit on t is I know how to curse. William Shakspere, The Tempest, I, ii.
Lecture 19 CSE 110 5 August 1992 You taught me Language, and my profit on t is I know how to curse. William Shakspere, The Tempest, I, ii. 1 Left-Over Language Features Today was the day we saw the last
More informationLecture 16: HashTables 10:00 AM, Mar 2, 2018
CS18 Integrated Introduction to Computer Science Fisler, Nelson Lecture 16: HashTables 10:00 AM, Mar 2, 2018 Contents 1 Speeding up Lookup 1 2 Hashtables 2 2.1 Java HashMaps.......................................
More informationLab Solutions: Experimenting with Enumerated Types
1 of 5 2/16/2007 11:07 AM Lab Solutions: Experimenting with Enumerated Types 1 Instructions: Omitted. 2 Getting Ready: Omitted. 3 Using Integer Constants Instead of Enumerated Types: It is common practice
More informationSoftware Design and Analysis for Engineers
Software Design and Analysis for Engineers by Dr. Lesley Shannon Email: lshannon@ensc.sfu.ca Course Website: http://www.ensc.sfu.ca/~lshannon/courses/ensc251 Simon Fraser University Slide Set: 2 Date:
More information1001ICT Introduction To Programming Lecture Notes
1001ICT Introduction To Programming Lecture Notes School of Information and Communication Technology Griffith University Semester 2, 2015 1 2 Elements of Java Java is a popular, modern, third generation
More informationLecture Set 4: More About Methods and More About Operators
Lecture Set 4: More About Methods and More About Operators Methods Definitions Invocations More arithmetic operators Operator Side effects Operator Precedence Short-circuiting main method public static
More information} Evaluate the following expressions: 1. int x = 5 / 2 + 2; 2. int x = / 2; 3. int x = 5 / ; 4. double x = 5 / 2.
Class #10: Understanding Primitives and Assignments Software Design I (CS 120): M. Allen, 19 Sep. 18 Java Arithmetic } Evaluate the following expressions: 1. int x = 5 / 2 + 2; 2. int x = 2 + 5 / 2; 3.
More informationCS1622. Semantic Analysis. The Compiler So Far. Lecture 15 Semantic Analysis. How to build symbol tables How to use them to find
CS1622 Lecture 15 Semantic Analysis CS 1622 Lecture 15 1 Semantic Analysis How to build symbol tables How to use them to find multiply-declared and undeclared variables. How to perform type checking CS
More informationThe Environment Model. Nate Foster Spring 2018
The Environment Model Nate Foster Spring 2018 Review Previously in 3110: Interpreters: ASTs, evaluation, parsing Formal syntax: BNF Formal semantics: dynamic: small-step substitution model static semantics
More informationProgramming Language Concepts: Lecture 2
Programming Language Concepts: Lecture 2 Madhavan Mukund Chennai Mathematical Institute madhavan@cmi.ac.in http://www.cmi.ac.in/~madhavan/courses/pl2009 PLC 2009, Lecture 2, 19 January 2009 Classes and
More information1.00 Lecture 8. Using An Existing Class, cont.
.00 Lecture 8 Classes, continued Reading for next time: Big Java: sections 7.9 Using An Existing Class, cont. From last time: is a Java class used by the BusTransfer class BusTransfer uses objects: First
More informationSpring 2003 Instructor: Dr. Shahadat Hossain. Administrative Matters Course Information Introduction to Programming Techniques
1 CPSC2620 Advanced Programming Spring 2003 Instructor: Dr. Shahadat Hossain 2 Today s Agenda Administrative Matters Course Information Introduction to Programming Techniques 3 Course Assessment Lectures:
More informationPRINCIPLES OF SOFTWARE BIM209DESIGN AND DEVELOPMENT 10. PUTTING IT ALL TOGETHER. Are we there yet?
PRINCIPLES OF SOFTWARE BIM209DESIGN AND DEVELOPMENT 10. PUTTING IT ALL TOGETHER Are we there yet? Developing software, OOA&D style You ve got a lot of new tools, techniques, and ideas about how to develop
More informationApplications of Formal Verification
Applications of Formal Verification Model Checking: Introduction to PROMELA Bernhard Beckert Mattias Ulbrich SS 2017 KIT INSTITUT FÜR THEORETISCHE INFORMATIK KIT University of the State of Baden-Württemberg
More informationCS 231 Data Structures and Algorithms Fall Binary Search Trees Lecture 23 October 29, Prof. Zadia Codabux
CS 231 Data Structures and Algorithms Fall 2018 Binary Search Trees Lecture 23 October 29, 2018 Prof. Zadia Codabux 1 Agenda Ternary Operator Binary Search Tree Node based implementation Complexity 2 Administrative
More informationClaremont McKenna College Computer Science
Claremont McKenna College Computer Science CS 51 Handout 4: Problem Set 4 February 10, 2011 This problem set is due 11:50pm on Wednesday, February 16. As usual, you may hand in yours until I make my solutions
More informationLecture Set 4: More About Methods and More About Operators
Lecture Set 4: More About Methods and More About Operators Methods Definitions Invocations More arithmetic operators Operator Side effects Operator Precedence Short-circuiting main method public static
More informationComputer Science E-119 Fall Problem Set 4. Due prior to lecture on Wednesday, November 28
Computer Science E-119 Fall 2012 Due prior to lecture on Wednesday, November 28 Getting Started To get the files that you will need for this problem set, log into nice.harvard.edu and enter the following
More informationPRINCIPLES OF SOFTWARE BIM209DESIGN AND DEVELOPMENT 00. WELCOME TO OBJECTVILLE. Speaking the Language of OO
PRINCIPLES OF SOFTWARE BIM209DESIGN AND DEVELOPMENT 00. WELCOME TO OBJECTVILLE Speaking the Language of OO COURSE INFO Instructor : Alper Bilge TA : Gökhan Çıplak-Ahmet Alkılınç Time : Tuesdays 2-5pm Location
More informationMidterm Reminders. Design Pattern #6: Facade. General Idea. The Situation
Midterm Reminders The midterm is next Tuesday: March 4, 7-9 p.m. If you have a conflict and haven't told us, send e-mail TODAY! (conflicts with other Queens courses or exams) Location: Stirling Hall rooms
More informationSchool of Computer Science CPS109 Course Notes 5 Alexander Ferworn Updated Fall 15
Table of Contents 1 INTRODUCTION... 1 2 IF... 1 2.1 BOOLEAN EXPRESSIONS... 3 2.2 BLOCKS... 3 2.3 IF-ELSE... 4 2.4 NESTING... 5 3 SWITCH (SOMETIMES KNOWN AS CASE )... 6 3.1 A BIT ABOUT BREAK... 7 4 CONDITIONAL
More informationLecture 14: Exceptions 10:00 AM, Feb 26, 2018
CS18 Integrated Introduction to Computer Science Fisler, Nelson Lecture 14: Exceptions 10:00 AM, Feb 26, 2018 Contents 1 Exceptions and How They Work 1 1.1 Update to the Banking Example.............................
More informationThread Safety. Review. Today o Confinement o Threadsafe datatypes Required reading. Concurrency Wrapper Collections
Thread Safety Today o Confinement o Threadsafe datatypes Required reading Concurrency Wrapper Collections Optional reading The material in this lecture and the next lecture is inspired by an excellent
More informationLesson 10: Quiz #1 and Getting User Input (W03D2)
Lesson 10: Quiz #1 and Getting User Input (W03D2) Balboa High School Michael Ferraro September 1, 2015 1 / 13 Do Now: Prep GitHub Repo for PS #1 You ll need to submit the 5.2 solution on the paper form
More informationLecture 5: Methods CS2301
Lecture 5: Methods NADA ALZAHRANI CS2301 1 Opening Problem Find the sum of integers from 1 to 10, from 20 to 30, and from 35 to 45, respectively. 2 Solution public static int sum(int i1, int i2) { int
More informationINTERFACES IN JAVA. Prof. Chris Jermaine
INTERFACES IN JAVA Prof. Chris Jermaine cmj4@cs.rice.edu 1 Before We Begin... Couple more slides on checkers, then a challenge There is also an AIntelligence This encapsulates the idea of a checker-playing
More informationFOR Loops. Last Modified: 01 June / 1
FOR Loops http://people.sc.fsu.edu/ jburkardt/isc/week04 lecture 08.pdf... ISC3313: Introduction to Scientific Computing with C++ Summer Semester 2011... John Burkardt Department of Scientific Computing
More informationClass 26: Linked Lists
Introduction to Computation and Problem Solving Class 26: Linked Lists Prof. Steven R. Lerman and Dr. V. Judson Harward 2 The Java Collection Classes The java.util package contains implementations of many
More informationCSE 303: Concepts and Tools for Software Development
CSE 303: Concepts and Tools for Software Development Dan Grossman Spring 2007 Lecture 19 Profiling (gprof); Linking and Libraries Dan Grossman CSE303 Spring 2007, Lecture 19 1 Where are we Already started
More informationComputer Science 210 Data Structures Siena College Fall Topic Notes: Recursive Methods
Computer Science 210 Data Structures Siena College Fall 2017 Topic Notes: Recursive Methods You have seen in this course and in your previous work that iteration is a fundamental building block that we
More informationLoops. CSE 114, Computer Science 1 Stony Brook University
Loops CSE 114, Computer Science 1 Stony Brook University http://www.cs.stonybrook.edu/~cse114 1 Motivation Suppose that you need to print a string (e.g., "Welcome to Java!") a user-defined times N: N?
More informationApplications of Formal Verification
Applications of Formal Verification Model Checking: Introduction to PROMELA Prof. Dr. Bernhard Beckert Dr. Vladimir Klebanov SS 2012 KIT INSTITUT FÜR THEORETISCHE INFORMATIK KIT University of the State
More informationdrawobject Circle draw
25 THE VISITOR PATTERN The Visitor pattern turns the tables on our object-oriented model and creates an external class to act on data in other classes. This is useful if there are a fair number of instances
More informationIntroduction to Programming in C Department of Computer Science and Engineering. Lecture No. #17. Loops: Break Statement
Introduction to Programming in C Department of Computer Science and Engineering Lecture No. #17 Loops: Break Statement (Refer Slide Time: 00:07) In this session we will see one more feature that is present
More informationCOLLECTIONS & ITERATORS cs2420 Introduction to Algorithms and Data Structures Spring 2015
COLLECTIONS & ITERATORS cs2420 Introduction to Algorithms and Data Structures Spring 2015 1 administrivia 2 -assignment 2 is due tomorrow at midnight (11:59pm) -next assignment goes out today -due Thursday
More informationTREES. Tree Overview 9/28/16. Prelim 1 tonight! Important Announcements. Tree terminology. Binary trees were in A1!
//16 Prelim 1 tonight! :3 prelim is very crowded. You HAVE to follow these directions: 1. Students taking the normal :3 prelim (not the quiet room) and whose last names begin with A through Da MUST go
More informationComputer Science II Lecture 1 Introduction and Background
Computer Science II Lecture 1 Introduction and Background Discussion of Syllabus Instructor, TAs, office hours Course web site, http://www.cs.rpi.edu/courses/fall04/cs2, will be up soon Course emphasis,
More informationSixth lecture; classes, objects, reference operator.
Sixth lecture; classes, objects, reference operator. 1 Some notes on the administration of the class: From here on out, homework assignments should be a bit shorter, and labs a bit longer. My office hours
More informationLast Time. University of British Columbia CPSC 111, Intro to Computation Alan J. Hu. Readings
University of British Columbia CPSC 111, Intro to Computation Alan J. Hu Writing a Simple Java Program Intro to Variables Readings Your textbook is Big Java (3rd Ed). This Week s Reading: Ch 2.1-2.5, Ch
More informationApplications of Formal Verification
Applications of Formal Verification Model Checking: Introduction to PROMELA Prof. Dr. Bernhard Beckert Dr. Vladimir Klebanov SS 2010 KIT INSTITUT FÜR THEORETISCHE INFORMATIK KIT University of the State
More informationCS125 : Introduction to Computer Science. Lecture Notes #4 Type Checking, Input/Output, and Programming Style
CS125 : Introduction to Computer Science Lecture Notes #4 Type Checking, Input/Output, and Programming Style c 2005, 2004, 2002, 2001, 2000 Jason Zych 1 Lecture 4 : Type Checking, Input/Output, and Programming
More informationCS164: Programming Assignment 2 Dlex Lexer Generator and Decaf Lexer
CS164: Programming Assignment 2 Dlex Lexer Generator and Decaf Lexer Assigned: Thursday, September 16, 2004 Due: Tuesday, September 28, 2004, at 11:59pm September 16, 2004 1 Introduction Overview In this
More informationCompiler Design Spring 2018
Compiler Design Spring 2018 2.3 Templates (for code generation) 2.4 Template-based code generator Thomas R. Gross Computer Science Department ETH Zurich, Switzerland 26 2.3 Templates Templates decide how
More informationCmpSci 187: Programming with Data Structures Spring 2015
CmpSci 187: Programming with Data Structures Spring 2015 Lecture #17, Implementing Binary Search Trees John Ridgway April 2, 2015 1 Implementing Binary Search Trees Review: The BST Interface Binary search
More informationCS1004: Intro to CS in Java, Spring 2005
CS1004: Intro to CS in Java, Spring 2005 Lecture #16: Java conditionals/loops, cont d. Janak J Parekh janak@cs.columbia.edu Administrivia Midterms returned now Weird distribution Mean: 35.4 ± 8.4 What
More informationCOSC 243. Data Representation 3. Lecture 3 - Data Representation 3 1. COSC 243 (Computer Architecture)
COSC 243 Data Representation 3 Lecture 3 - Data Representation 3 1 Data Representation Test Material Lectures 1, 2, and 3 Tutorials 1b, 2a, and 2b During Tutorial a Next Week 12 th and 13 th March If you
More informationAbout this exam review
Final Exam Review About this exam review I ve prepared an outline of the material covered in class May not be totally complete! Exam may ask about things that were covered in class but not in this review
More informationCISC-124. Casting. // this would fail because we can t assign a double value to an int // variable
CISC-124 20180122 Today we looked at casting, conditionals and loops. Casting Casting is a simple method for converting one type of number to another, when the original type cannot be simply assigned to
More informationTwo Types of Types. Primitive Types in Java. Using Primitive Variables. Class #07: Java Primitives. Integer types.
Class #07: Java Primitives Software Design I (CS 120): M. Allen, 13 Sep. 2018 Two Types of Types So far, we have mainly been dealing with objects, like DrawingGizmo, Window, Triangle, that are: 1. Specified
More informationIntroduction to Java Unit 1. Using BlueJ to Write Programs
Introduction to Java Unit 1. Using BlueJ to Write Programs 1. Open up BlueJ. Click on the Project menu and select New Project. You should see the window on the right. Navigate to wherever you plan to save
More informationIntro. Scheme Basics. scm> 5 5. scm>
Intro Let s take some time to talk about LISP. It stands for LISt Processing a way of coding using only lists! It sounds pretty radical, and it is. There are lots of cool things to know about LISP; if
More informationAdministration. Conditional Statements. Agenda. Syntax. Flow of control. Lab 2 due now on floppy Lab 3 due tomorrow via FTP
Administration Conditional Statements CS 99 Summer 2000 Michael Clarkson Lecture 4 Lab 2 due now on floppy Lab 3 due tomorrow via FTP need Instruct account password Lab 4 posted this afternoon Prelim 1
More informationCS 231 Data Structures and Algorithms, Fall 2016
CS 231 Data Structures and Algorithms, Fall 2016 Dr. Bruce A. Maxwell Department of Computer Science Colby College Course Description Focuses on the common structures used to store data and the standard
More informationCSSE 220 Day 13. Encapsulation Coupling and Cohesion Scoping. Please download EncapsulationExamples from your SVN
CSSE 220 Day 13 Encapsulation Coupling and Cohesion Scoping Please download EncapsulationExamples from your SVN The plan Learn 3 essential object oriented design terms: Encapsulation Coupling Cohesion
More informationExpressions & Flow Control
Objectives Distinguish between instance and local variables 4 Expressions & Flow Control Describe how instance variables are initialized Identify and correct a Possible reference before assignment compiler
More informationThe Environment Model
The Environment Model Prof. Clarkson Fall 2017 Today s music: Selections from Doctor Who soundtracks by Murray Gold Review Previously in 3110: Interpreters: ASTs, evaluation, parsing Formal syntax: BNF
More informationTREES Lecture 12 CS2110 Fall 2016
TREES Lecture 12 CS2110 Fall 2016 Prelim 1 tonight! 2 5:30 prelim is very crowded. You HAVE to follow these directions: 1. Students taking the normal 5:30 prelim (not the quiet room) and whose last names
More informationAnnouncements. 1. Forms to return today after class:
Announcements Handouts (3) to pick up 1. Forms to return today after class: Pretest (take during class later) Laptop information form (fill out during class later) Academic honesty form (must sign) 2.
More informationOODP Session 4. Web Page: Visiting Hours: Tuesday 17:00 to 19:00
OODP Session 4 Session times PT group 1 Monday 18:00 21:00 room: Malet 403 PT group 2 Thursday 18:00 21:00 room: Malet 407 FT Tuesday 13:30 17:00 room: Malet 404 Email: oded@dcs.bbk.ac.uk Web Page: http://www.dcs.bbk.ac.uk/~oded
More informationAP Computer Science Unit 1. Writing Programs Using BlueJ
AP Computer Science Unit 1. Writing Programs Using BlueJ 1. Open up BlueJ. Click on the Project menu and select New Project. You should see the window on the right. Navigate to wherever you plan to save
More informationCOMP-202. Recursion. COMP Recursion, 2011 Jörg Kienzle and others
COMP-202 Recursion Recursion Recursive Definitions Run-time Stacks Recursive Programming Recursion vs. Iteration Indirect Recursion Lecture Outline 2 Recursive Definitions (1) A recursive definition is
More informationCS 112 Programming 2. Lecture 10. Abstract Classes & Interfaces (1) Chapter 13 Abstract Classes and Interfaces
CS 112 Programming 2 Lecture 10 Abstract Classes & Interfaces (1) Chapter 13 Abstract Classes and Interfaces 2 1 Motivations We have learned how to write simple programs to create and display GUI components.
More informationASYMPTOTIC COMPLEXITY
Simplicity is a great virtue but it requires hard work to achieve it and education to appreciate it. And to make matters worse: complexity sells better. - Edsger Dijkstra ASYMPTOTIC COMPLEXITY Lecture
More informationHOW TO WRITE RECURSIVE FUNCTIONS ON YOUR OWN
HOW TO WRITE RECURSIVE FUNCTIONS ON YOUR OWN In this tutorial, you ll learn - well, you ve already read the title - how to write recursive functions on your own. If you re the person to whom recursive
More informationCSE 410 Computer Systems. Hal Perkins Spring 2010 Lecture 12 More About Caches
CSE 4 Computer Systems Hal Perkins Spring Lecture More About Caches Reading Computer Organization and Design Section 5. Introduction Section 5. Basics of Caches Section 5. Measuring and Improving Cache
More informationProgram to an Interface (a.k.a. - P2I) Not an Implementation
Program to an Interface (a.k.a. - P2I) Not an Implementation Early in the WeatherStation constructor: Barometer bar = new Barometer() ; Why is this problematic: WeatherStation depends on a specific implementation
More informationStarting to Program in C++ (Basics & I/O)
Copyright by Bruce A. Draper. 2017, All Rights Reserved. Starting to Program in C++ (Basics & I/O) On Tuesday of this week, we started learning C++ by example. We gave you both the Complex class code and
More informationCSCI-1200 Data Structures Fall 2018 Lecture 3 Classes I
Review from Lecture 2 CSCI-1200 Data Structures Fall 2018 Lecture 3 Classes I Vectors are dynamically-sized arrays Vectors, strings and other containers should be: passed by reference when they are to
More informationQUIZ Friends class Y;
QUIZ Friends class Y; Is a forward declaration neeed here? QUIZ Friends QUIZ Friends - CONCLUSION Forward (a.k.a. incomplete) declarations are needed only when we declare member functions as friends. They
More informationCS 206 Introduction to Computer Science II
CS 206 Introduction to Computer Science II 03 / 05 / 2018 Instructor: Michael Eckmann Today s Topics Questions? Comments? binary search trees Finish delete method Discuss run times of various methods Michael
More information4. Java Project Design, Input Methods
4-1 4. Java Project Design, Input Methods Review and Preview You should now be fairly comfortable with creating, compiling and running simple Java projects. In this class, we continue learning new Java
More informationJava is an objet-oriented programming language providing features that support
Java Essentials CSCI 136: Spring 2018 Handout 2 February 2 Language Basics Java is an objet-oriented programming language providing features that support Data abstraction Code reuse Modular development
More informationCS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University
CS 112 Introduction to Computing II Wayne Snyder Department Boston University Today: ; public vs private; Object-Oriented Programming; Abstract data types; Stacks as ADTs; Next time: Stacks and Queues
More informationTips from the experts: How to waste a lot of time on this assignment
Com S 227 Spring 2018 Assignment 1 100 points Due Date: Friday, September 14, 11:59 pm (midnight) Late deadline (25% penalty): Monday, September 17, 11:59 pm General information This assignment is to be
More informationCSE 331 Final Exam 12/9/13
Name There are 10 questions worth a total of 100 points. Please budget your time so you get to all of the questions. Keep your answers brief and to the point. The exam is closed book, closed notes, closed
More informationAP Computer Science Unit 1. Writing Programs Using BlueJ
AP Computer Science Unit 1. Writing Programs Using BlueJ 1. Open up BlueJ. Click on the Project menu and select New Project. You should see the window on the right. Navigate to wherever you plan to save
More informationNews and information! Review: Java Programs! Feedback after Lecture 2! Dead-lines for the first two lab assignment have been posted.!
True object-oriented programming: Dynamic Objects Reference Variables D0010E Object-Oriented Programming and Design Lecture 3 Static Object-Oriented Programming UML" knows-about Eckel: 30-31, 41-46, 107-111,
More informationECE 122 Engineering Problem Solving with Java
ECE 122 Engineering Problem Solving with Java Introduction to Programming for ECE Lecture 1 Course Overview Welcome! What is this class about? Java programming somewhat software somewhat Solving engineering
More informationCSCI 102L - Data Structures Midterm Exam #2 Spring 2011
CSCI 102L - Data Structures Midterm Exam #2 Spring 2011 (12:30pm - 1:50pm, Thursday, March 24) Instructor: Bill Cheng ( This exam is closed book, closed notes, closed everything. No cheat sheet allowed.
More informationControls Structure for Repetition
Controls Structure for Repetition So far we have looked at the if statement, a control structure that allows us to execute different pieces of code based on certain conditions. However, the true power
More informationAbsolute C++ Walter Savitch
Absolute C++ sixth edition Walter Savitch Global edition This page intentionally left blank Absolute C++, Global Edition Cover Title Page Copyright Page Preface Acknowledgments Brief Contents Contents
More informationTESTING AND DEBUGGING
TESTING AND DEBUGGING zombie[1] zombie[3] Buuuuugs zombie[4] zombie[2] zombie[5] zombie[0] Fundamentals of Computer Science I Outline Debugging Types of Errors Syntax Errors Semantic Errors Logic Errors
More informationQUIZ on Ch.5. Why is it sometimes not a good idea to place the private part of the interface in a header file?
QUIZ on Ch.5 Why is it sometimes not a good idea to place the private part of the interface in a header file? Example projects where we don t want the implementation visible to the client programmer: The
More informationPhysics 2660: Fundamentals of Scientific Computing. Lecture 3 Instructor: Prof. Chris Neu
Physics 2660: Fundamentals of Scientific Computing Lecture 3 Instructor: Prof. Chris Neu (chris.neu@virginia.edu) Announcements Weekly readings will be assigned and available through the class wiki home
More information