Grade Weights. Language Design and Overview of COOL. CS143 Lecture 2. Programming Language Economics 101. Lecture Outline

Similar documents
Cunning Plan. One-Slide Summary. Functional Programming. Functional Programming. Introduction to COOL #1. Classroom Object-Oriented Language

Introduction to Programming Languages and Compilers. CS164 11:00-12:30 TT 10 Evans. UPRM ICOM 4029 (Adapted from: Prof. Necula UCB CS 164)

Functional Programming. Introduction To Cool

Compiler Design 1. Introduction to Programming Language Design and to Compilation

1DL321: Kompilatorteknik I (Compiler Design 1) Introduction to Programming Language Design and to Compilation

1DL321: Kompilatorteknik I (Compiler Design 1) Introduction to Programming Language Design and to Compilation

1DL321: Kompilatorteknik I (Compiler Design 1)

Winter Compiler Construction Who. Mailing list and forum

Functional Programming. Introduction To Cool

Functional Programming. Introduction To Cool

CS 565: Programming Languages. Spring 2008 Tu, Th: 16:30-17:45 Room LWSN 1106

Who. Winter Compiler Construction Generic compiler structure. Mailing list and forum. IC compiler. How

Lecture Outline. COOL operational semantics. Operational Semantics of Cool. Motivation. Lecture 13. Notation. The rules. Evaluation Rules So Far

Principles of Programming Languages. Lecture Outline

CS558 Programming Languages

Operational Semantics. One-Slide Summary. Lecture Outline

Lecture Outline. Type systems and their expressiveness. Type Checking in COOL (II) Type checking with SELF_TYPE in COOL

Lecture Outline. COOL operational semantics. Operational Semantics of Cool. Motivation. Notation. The rules. Evaluation Rules So Far.

CS558 Programming Languages

NOTE: Answer ANY FOUR of the following 6 sections:

Lecture Outline. Type systems and their expressiveness. Type Checking in COOL (II) Type checking with SELF_TYPE in COOL

Question No: 1 ( Marks: 1 ) - Please choose one One difference LISP and PROLOG is. AI Puzzle Game All f the given

G Programming Languages - Fall 2012

Operational Semantics of Cool

Scoping rules match identifier uses with identifier definitions. A type is a set of values coupled with a set of operations on those values.

Design Issues. Subroutines and Control Abstraction. Subroutines and Control Abstraction. CSC 4101: Programming Languages 1. Textbook, Chapter 8

Introduction. Compilers and Interpreters

Chapter 1. Preliminaries

CS 3360 Design and Implementation of Programming Languages. Exam 1

Lecture Overview. [Scott, chapter 7] [Sebesta, chapter 6]

Passing Out Review Forms

Names, Scope, and Bindings

CS1622. Semantic Analysis. The Compiler So Far. Lecture 15 Semantic Analysis. How to build symbol tables How to use them to find

Naming in OOLs and Storage Layout Comp 412

CS 330 Lecture 18. Symbol table. C scope rules. Declarations. Chapter 5 Louden Outline

Types. What is a type?

Programming Languages FILS Andrei Vasilateanu

2. The object-oriented paradigm!

More Static Semantics. Static. One-Slide Summary. Lecture Outline. Typing Rules. Dispatch Rules SELF_TYPE

Zhifu Pei CSCI5448 Spring 2011 Prof. Kenneth M. Anderson

Review: Object Diagrams for Inheritance. Type Conformance. Inheritance Structures. Car. Vehicle. Truck. Vehicle. conforms to Object

CS 415 Midterm Exam Spring 2002

Programmiersprachen (Programming Languages)

Structure of Programming Languages Lecture 10

Outline. Java Models for variables Types and type checking, type safety Interpretation vs. compilation. Reasoning about code. CSCI 2600 Spring

What are the characteristics of Object Oriented programming language?

CS164: Programming Assignment 5 Decaf Semantic Analysis and Code Generation

2. The object-oriented paradigm

Names, Scope, and Bindings

Special Topics: Programming Languages

Object-Oriented Languages and Object-Oriented Design. Ghezzi&Jazayeri: OO Languages 1

CPS 506 Comparative Programming Languages. Programming Language

Programming Languages 2nd edition Tucker and Noonan"

Chapter 6 Introduction to Defining Classes

Announcements. Working on requirements this week Work on design, implementation. Types. Lecture 17 CS 169. Outline. Java Types

Lecture Outline. Topic 1: Basic Code Generation. Code Generation. Lecture 12. Topic 2: Code Generation for Objects. Simulating a Stack Machine

Chapter 1 Preliminaries

TYPES, VALUES AND DECLARATIONS

What about Object-Oriented Languages?

Classes, subclasses, subtyping

Compiler construction 2009

Programming Assignment IV Due Thursday, November 18th, 2010 at 11:59 PM

CS-XXX: Graduate Programming Languages. Lecture 9 Simply Typed Lambda Calculus. Dan Grossman 2012

Runtime Support for OOLs Object Records, Code Vectors, Inheritance Comp 412

CSC 533: Organization of Programming Languages. Spring 2005

OBJECT ORİENTATİON ENCAPSULATİON

A brief introduction to C programming for Java programmers

Course Text. Course Description. Course Objectives. StraighterLine Introduction to Programming in C++

G Programming Languages Spring 2010 Lecture 6. Robert Grimm, New York University

Lecture 7: Data Abstractions

Introduction to Programming Using Java (98-388)

Anatomy of a Compiler. Overview of Semantic Analysis. The Compiler So Far. Why a Separate Semantic Analysis?

Concepts of Programming Languages

Names, Bindings, Scopes

One-Slide Summary. Lecture Outine. Automatic Memory Management #1. Why Automatic Memory Management? Garbage Collection.

Semantic Analysis. How to Ensure Type-Safety. What Are Types? Static vs. Dynamic Typing. Type Checking. Last time: CS412/CS413

Continuations provide a novel way to suspend and reexecute

MIDTERM EXAMINATION - CS130 - Spring 2005

Programming Languages, Summary CSC419; Odelia Schwartz

Programming Project 4: COOL Code Generation

Comp 311 Principles of Programming Languages Lecture 21 Semantics of OO Languages. Corky Cartwright Mathias Ricken October 20, 2010

Type Checking in COOL (II) Lecture 10

CS412/CS413. Introduction to Compilers Tim Teitelbaum. Lecture 17: Types and Type-Checking 25 Feb 08

Topics Covered Thus Far. CMSC 330: Organization of Programming Languages. Language Features Covered Thus Far. Programming Languages Revisited

Types and Type Inference

CS 536 Introduction to Programming Languages and Compilers Charles N. Fischer Lecture 11

CS 430 Spring Mike Lam, Professor. Data Types and Type Checking

Names, Scope, and Bindings

CSE 504. Expression evaluation. Expression Evaluation, Runtime Environments. One possible semantics: Problem:

Short Notes of CS201

Derived and abstract data types. TDT4205 Lecture 15

Types. Type checking. Why Do We Need Type Systems? Types and Operations. What is a type? Consensus

CSE 307: Principles of Programming Languages

CS201 - Introduction to Programming Glossary By

Type Checking and Type Equality

G Programming Languages - Fall 2012

Chapter 5. Names, Bindings, and Scopes

Compiler Construction

Compaq Interview Questions And Answers

Introduction to Software Testing Chapter 2.4 Graph Coverage for Design Elements Paul Ammann & Jeff Offutt

Transcription:

Grade Weights Language Design and Overview of COOL CS143 Lecture 2 Project 0% I, II 10% each III, IV 1% each Midterm 1% Final 2% Written Assignments 10% 2.% each Prof. Aiken CS 143 Lecture 2 1 Prof. Aiken CS 143 Lecture 2 2 Lecture Outline Today s topic: language design Why are there new languages? Good-language criteria History of ideas: Abstraction Types Reuse Cool The Course Project Prof. Aiken CS 143 Lecture 2 3 Programming Language Economics 101 Languages are adopted to fill a void Enable a previously difficult/impossible application Orthogonal to language design quality (almost) Programmer training is the dominant cost Languages with many users are replaced rarely Popular languages become ossified But easy to start in a new niche... Prof. Aiken CS 143 Lecture 2 4 Why So Many Languages? Application domains have distinctive and conflicting needs Examples: Scientific Computing: high performance Business: report generation Artificial intelligence: symbolic computation Systems programming: low-level access Special purpose languages Topic: Language Design No universally accepted metrics for design A good language is one people use? NO! Visual Basic and COBOL are the best languages? Good language design is hard Prof. Aiken CS 143 Lecture 2 Prof. Aiken CS 143 Lecture 2 6 1

Language Evaluation Criteria History of Ideas: Abstraction Characteristic Criteria Abstraction = detached from concrete details Simplicity Readability Writeability Reliability Abstraction necessary to build software systems Data types Syntax design Abstraction Expressivity Type checking Exception handling Modes of abstraction Via languages/compilers: Higher-level code, few machine dependencies Via subroutines Abstract interface to behavior Via modules Export interfaces; hide implementation Via abstract data types Bundle data with its operations Prof. Aiken CS 143 Lecture 2 7 Prof. Aiken CS 143 Lecture 2 8 History of Ideas: Types Originally, few types FORTRAN: scalars, arrays LISP: no static type distinctions Realization: Types help Allow the programmer to express abstraction Allow the compiler to check against many frequent errors Sometimes to the point that programs are guaranteed safe More recently Lots of interest in types Experiments with various forms of parameterization Best developed in functional programming Prof. Aiken CS 143 Lecture 2 9 History of Ideas: Reuse Reuse = exploit common patterns in software systems Goal: mass-produced software components Reuse is difficult Two popular approaches Type parameterization (List(int), List(double)) Classes and inheritance: C++ derived classes Combined in C++, Java Inheritance allows Specialization of existing abstraction Extension, modification, hiding behavior Prof. Aiken CS 143 Lecture 2 10 Trends Language design Many new special-purpose languages Popular languages to stay Compilers More needed and more complex Driven by increasing gap between new languages new architectures Venerable and healthy area Prof. Aiken CS 143 Lecture 2 11 Why Study Languages and Compilers?. Increase capacity of expression 4. Improve understanding of program behavior 3. Increase ability to learn new languages 2. Learn to build a large and reliable system 1. See many basic CS concepts at work Prof. Aiken CS 143 Lecture 2 12 2

Cool Overview Classroom Object Oriented Language Designed to Be implementable in a short time Give a taste of implementation of modern Abstraction Static typing Reuse (inheritance) Memory management And more But many things are left out Prof. Aiken CS 143 Lecture 2 13 A Simple Example y : Int 0; Cool programs are sets of class definitions A special class Main with a special method main No separate notion of subroutine class = a collection of attributes and methods Instances of a class are objects Prof. Aiken CS 143 Lecture 2 14 Cool Objects y : Int; ( use default value ) The expression new Point creates a new object of class Point An object can be thought of as a record with a slot for each attribute Prof. Aiken CS 143 Lecture 2 1 Methods A class can also define methods for manipulating the attributes y : Int 0; movepoint(newx : Int, newy : Int): Point { { x newx; y newy; self; } -- close block expression -- close method -- close class Methods can refer to the current object using self Prof. Aiken CS 143 Lecture 2 16 Information Hiding in Cool Methods Methods are global Attributes are local to a class They can only be accessed by the class s methods Example:... x () : Int { x setx (newx : Int) : Int { x newx Prof. Aiken CS 143 Lecture 2 17 Each object knows how to access the code of a method As if the object contains a slot pointing to the code movepoint In reality implementations save space by sharing these pointers among instances of the same class methods movepoint Prof. Aiken CS 143 Lecture 2 18 3

Inheritance Cool Types We can extend points to colored points using subclassing => class hierarchy class ColorPoint inherits Point { color : Int 0; movepoint(newx : Int, newy : Int): Point { { color 0; x newx; y newy; self; } color movepoint 0 Prof. Aiken CS 143 Lecture 2 19 Every class is a type Base classes: Int for integers Bool for boolean values: true, false String for strings Object root of the class hierarchy All variables must be declared compiler infers types for expressions Prof. Aiken CS 143 Lecture 2 20 Cool Type Checking Is well typed if A is an ancestor of B in the class hierarchy Anywhere an A is expected a B can be used Type safety: x : A; x new B; A well-typed program cannot result in runtime type errors Method Invocation and Inheritance Methods are invoked by dispatch Understanding dispatch in the presence of inheritance is a subtle aspect of OO languages p : Point; p new ColorPoint; p.movepoint(1,2); p has static type Point p has dynamic type ColorPoint p.movepoint must invoke the ColorPoint version Prof. Aiken CS 143 Lecture 2 21 Prof. Aiken CS 143 Lecture 2 22 Method Invocation Example: invoke one-argument method m 2 3 m: self method table 6 1 e.m(e ) x <method code> 4 1. Eval. e 2. Find class of e 3. Find code of m 4. Eval. argum.. Bind self and x 6. Run method Other Expressions Expression language every expression has a type and a value Loops: while E loop E pool Conditionals if E then E else E fi Case statement case E of x : Type E; esac Arithmetic, logical operations Assignment x E Primitive I/O out_string(s), in_string(), Missing features: arrays, floating point operations, exceptions, Prof. Aiken CS 143 Lecture 2 23 Prof. Aiken CS 143 Lecture 2 24 4

Cool Memory Management Memory is allocated every time new is invoked Memory is deallocated automatically when an object is not reachable anymore Done by the garbage collector (GC) There is a Cool GC Course Project A complete compiler Cool ==> MIPS assembly language No optimizations Split in 4 programming assignments (PAs) There is adequate time to complete assignments But start early and please follow directions Individual or team max. 2 students Prof. Aiken CS 143 Lecture 2 2 Prof. Aiken CS 143 Lecture 2 26