Winter Compiler Construction Who. Mailing list and forum

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

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

IC Language Specification

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

Functional Programming. Introduction To Cool

Introduction to Programming Using Java (98-388)

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

A Short Summary of Javali

Winter Compiler Construction T11 Activation records + Introduction to x86 assembly. Today. Tips for PA4. Today:

The SPL Programming Language Reference Manual

The Decaf Language. 1 Lexical considerations

SEMANTIC ANALYSIS TYPES AND DECLARATIONS

Lexical Considerations

The Decaf language 1

Operational Semantics. One-Slide Summary. Lecture Outline

CS143 Handout 03 Summer 2012 June 27, 2012 Decaf Specification

The Compiler So Far. CSC 4181 Compiler Construction. Semantic Analysis. Beyond Syntax. Goals of a Semantic Analyzer.

Operational Semantics of Cool

Functional Programming. Introduction To Cool

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

CS164: Programming Assignment 5 Decaf Semantic Analysis and Code Generation

1 Lexical Considerations

CS558 Programming Languages

CS4120/4121/5120/5121 Spring 2016 Xi Language Specification Cornell University Version of May 11, 2016

Introduction to Computer Science Midterm 3 Fall, Points

CS558 Programming Languages

Lexical Considerations

Programming Languages Third Edition. Chapter 7 Basic Semantics

Derived and abstract data types. TDT4205 Lecture 15

Lecture 14. No in-class files today. Homework 7 (due on Wednesday) and Project 3 (due in 10 days) posted. Questions?

CSE115 / CSE503 Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall Office hours:

Class Information ANNOUCEMENTS

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

Reference Grammar Meta-notation: hfooi means foo is a nonterminal. foo (in bold font) means that foo is a terminal i.e., a token or a part of a token.

Names, Scope, and Bindings

11. a b c d e. 12. a b c d e. 13. a b c d e. 14. a b c d e. 15. a b c d e

Static Semantics. Winter /3/ Hal Perkins & UW CSE I-1

The PCAT Programming Language Reference Manual

Lectures 5-6: Introduction to C

Functional Programming. Introduction To Cool

Zhifu Pei CSCI5448 Spring 2011 Prof. Kenneth M. Anderson

Names, Scope, and Bindings

Operational Semantics of Cool

Today Winter Compiler Construction T5 AST Mooly Sagiv and Roman Manevich School of Computer Science Tel-Aviv University

CSE 307: Principles of Programming Languages

(Not Quite) Minijava

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

Decaf Language Reference

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

Winter Compiler Construction T10 IR part 3 + Activation records. Today. LIR language

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

Short Notes of CS201

Decaf Language Reference Manual

A brief introduction to C programming for Java programmers

CS201 - Introduction to Programming Glossary By

Lecture 7: Type Systems and Symbol Tables. CS 540 George Mason University

Program Representations

CS558 Programming Languages

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

Project 5 Due 11:59:59pm Tuesday, April 25, 2017

KU Compilerbau - Programming Assignment

Introduction & Java Review. EE 564 Lecture 1

COMP 250: Java Programming I. Carlos G. Oliver, Jérôme Waldispühl January 17-18, 2018 Slides adapted from M. Blanchette

Operators and Expressions

Compilers. Type checking. Yannis Smaragdakis, U. Athens (original slides by Sam

Project 5 Due 11:59:59pm Wed, Nov 25, 2015 (no late submissions)

Compiler Passes. Semantic Analysis. Semantic Analysis/Checking. Symbol Tables. An Example

Java Application Development

Java Basic Programming Constructs

Types. What is a type?

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

CS 415 Midterm Exam Fall 2003

COMP 181. Agenda. Midterm topics. Today: type checking. Purpose of types. Type errors. Type checking

CS 231 Data Structures and Algorithms, Fall 2016

Assumptions. History

Weiss Chapter 1 terminology (parenthesized numbers are page numbers)

COP 3330 Final Exam Review

Names, Scope, and Bindings

blur Melissa Kaufman-Gomez Team Leader Timothy Goodwin System Architect Dexter Callender Language Guru Daniel Hong Test Wizard

COP4020 Programming Languages. Compilers and Interpreters Robert van Engelen & Chris Lacher

Compilers Project 3: Semantic Analyzer

C11: Garbage Collection and Constructors

UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division. P. N. Hilfinger

Introduction to Java

CS558 Programming Languages

Motivation was to facilitate development of systems software, especially OS development.

Lecture 1: Overview of Java

Computer Science II (20082) Week 1: Review and Inheritance

Compiling and Interpreting Programming. Overview of Compilers and Interpreters

Semantic Analysis. Lecture 9. February 7, 2018

Programming Languages and Techniques (CIS120)

Introduction to C. Sean Ogden. Cornell CS 4411, August 30, Geared toward programmers

Intermediate Code Generation

Motivation was to facilitate development of systems software, especially OS development.

CS453 Compiler Construction

Please refer to the turn-in procedure document on the website for instructions on the turn-in procedure.

Class, Variable, Constructor, Object, Method Questions

Pace University. Fundamental Concepts of CS121 1

Introduction to C. Zhiyuan Teo. Cornell CS 4411, August 26, Geared toward programmers

CSE 431S Type Checking. Washington University Spring 2013

Transcription:

Winter 2006-2007 Compiler Construction 0368-3133 Mooly Sagiv and Roman Manevich School of Computer Science Tel-Aviv University Who Roman Manevich Schreiber Open-space (basement) Tel: 640-5358 rumster@post.tau.ac.il Wednesday 16:00-17:00 http://www.cs.tau.ac.il/~rumster/wcc06/ 2 Mailing list and forum Mailing list web interface: http://listserv.tau.ac.il/archives/cs0368-3133-02.html http://listserv.tau.ac.il/archives/cs0368-3133-03.html http://listserv.tau.ac.il/archives/cs0368-3133-04.html Activate e-mail by going to: https://www.tau.ac.il/newuser/ Forwarding, changing email address: https://www.tau.ac.il/forward/ http://www.ims.tau.ac.il/tal/ Not registered? Mail to listserv@listserv.tau.ac.il with the line: subscribe CS0368-3133-0X Real Name where X is your recitation course number (2/3/4) Forum: http://www.cs.tau.ac.il/system/forums/viewforum.php?f=46 3 1

2 4 Generic compiler structure Executable code exe Source text txt Semantic Representation Backend (synthesis) Compiler Frontend (analysis) 5 Executable code exe Source text txt Semantic Representation Backend (synthesis) Compiler Frontend (analysis) IC Program ic x86 executable exe Lexical Analysis Syntax Analysis Parsing AST Symbol Table etc. Inter. Rep. (IR) Code Generation IC compiler 6 How Lexical Analysis Syntax Analysis Parsing AST Symbol Table etc. Inter. Rep. (IR) Code Generation JFlex JavaCup Java IC Program prog.ic x86 assembly prog.s x86 assembly prog.s libic.a (libic + gc) GNU assembler prog.o GNU linker prog.exe script / Ant

Grading and schedule 45% exam 5% theoretical assignment 50% project 5 assignments different weights code checked both automatically and manually teams TA1 tentative schedule PA1 PA2 PA3 PA4 PA5 25/11/11 8/11 15/11 22/11 29/11 6/12 13/12 20/12 27/12 3/01 10/01 17/01 24/01 31/01 7/02 14/02 21/02 today semester ends exam 7 Project guidelines Teams of 2 or 3 students Email me before next recitation Subject: Compilation - new project team List of members (first name, last name, id, username on nova) Team-account user name In case of doubt ask questions in the forum There is adequate time to complete assignments Start early and please follow directions 8 Today IC Language ic Lexical Syntax AST Symbol Analysis Analysis Table etc. Parsing Goals: IC language overview See language specification Inter. Code Rep. Generation (IR) exe Executable code Understand the scope of the project 9 3

IC language - main features Strongly-typed Primitive types for int, boolean, string Reference types Object oriented Objects, virtual method calls Inheritance Memory management Dynamic heap allocation of obejcts and arrays Automatic deallocation (garbage collection) Runtime safety checks Null dereference Division by 0 Array access out of bounds Many things are left out Short implementation time Adapted with permission from Prof. Radu Rugina (Cornell University) 10 Unsupported features Access control Everything is public Interfaces Downcasting Method overloading (but still allow overriding) Exceptions Packages Multiple source files 11 IC program structure Program is sequence of class definitions Class is sequence of fields and methods Static methods and virtual methods Exactly one main method static void main(string[] args) {... Variables can be declared anywhere in a method Check initialization before use Strings are primitive types Arrays T[], T[][] 12 4

IC types Every class is a type Primitive types: int : 1,-1,2,-2, boolean : true, false string : hello References : null Arrays : int [] x = new int[5]; x.length==5; All variables must be declared compiler infers types for expressions Type-safety Well-typed programs do not result in runtime type errors 13 Subtyping Inheritance induces subtyping relation Type hierarchy gives acyclic graph (forest) Subtyping rules: A extends B { A B A A A B A C B C null A Subtyping does not extend to array types A subtype of B then A[] is not a subtype of B[] 14 Expressions Expression language Every expression has a type and a value Loops: while (expr) {stmt Conditionals: if (expr) stmt else stmt Arithmetic operators: + - * / % Relational compatison: < > == <= >= Logical operators: && Unary operators:! - Assignment: x = expr 15 5

Objects Instances of classes are objects class Point { int x; // initialized to 0 int y; new Point() allocates object of class Point on heap and initializes fields No arguments An object can be thought of as a struct (record) with a slot for each field 16 Methods class Point { int x; int y; Point movepoint(int newx, int newy) { x = newx; y = newy; return this; -- close method -- close class A class can also define methods to manipulate fields Methods can refer to the current object using this 17 Example class TestPoint { Point p; Point q; boolean test() { p = new Point(); q = p.movepoint(1,2); return p==q; class Point { int x; int y; Point movepoint(int newx, int newy) { x = newx; y = newy; return this; p p q p this 1 2 1 2 18 6

Method implementation Each object knows how to access method code As if object contains slot pointing to the code * movepoint In reality implementations save space by sharing these pointers among instances of the same class methods * movepoint 19 Inheritance example We can extend points to colored points: class ColoredPoint extends Point { int color; Point movepoint(int newx, int newy) { color = 0; x = newx; y = newy; return this; 0 x y color * movepoint 20 Method invocation and inheritance Methods are invoked by dispatch Understanding dispatch in the presence of inheritance is a subtle aspect of OO languages Point p; p = new ColoredPoint(); p.movepoint(1,2); p has static type Point p has dynamic type ColoredPoint p.movepoint invokes ColoredPoint implementation 21 7

Method invocation Example: invoke method p.movepoint(a+b,20/2) 1. Evaluate p 2. Find class of p 3. Find code of movepoint 4. Evaluate arguments a+b,20/2 5. Bind p to this 6. Bind actual arguments to formal arguments 7. Run method code 22 IC memory management Memory allocated every time new is used Memory deallocated automatically by reclaiming unreachable objects Done by a garbage collector (GC) Use off-the-shelf GC a = b a b 1 2 unreachable object b a 1 2 23 Library functions libic provides: I/O operations datatype conversions system level-operations class Library { static void println(string s); // prints string s followed by a newline. static void print(string s); // prints string s. static void printi(int i); // prints integer i. static void printb(boolean b); // prints boolean b. static int readi(); // reads one character from the input. static string readln(); // reads one line from the input. static boolean eof(); // checks end-of-file on standard input. static int stoi(string s, int n); // returns the integer that s represents // or n of s is not an integer. static string itos(int i); // returns a string representation of i. static int[] stoa(string s); // an array with the ascii codes of chars in s. static string atos(int[] a); // builds a string from the ascii codes in a. static int random(int i); // returns a random number between 0 and n-1. static int time(); // number of milliseconds since program start. static void exit(int i); // terminates the program with exit code n. 24 8

For next week Split into teams Send me email with team members and representative account Read IC language specification http://www.cs.tau.ac.il/~rumster/wcc06/icspec.pdf Get acquainted with Java J2SE 1.5 Eclipse IDE More helpful links on web-site 25 See you next week 26 9