Winter Compiler Construction

Slides:



Advertisements
Similar presentations
Overview of programming in C C is a fast, efficient, flexible programming language Paradigm: C is procedural (like Fortran, Pascal), not object oriented.
Advertisements

Intermediate Code Generation
Programming Languages and Paradigms The C Programming Language.
Compiler construction in4020 – lecture 10 Koen Langendoen Delft University of Technology The Netherlands.
1 Mooly Sagiv and Greta Yorsh School of Computer Science Tel-Aviv University Modern Compiler Design.
Winter Compiler Construction T7 – semantic analysis part II type-checking Mooly Sagiv and Roman Manevich School of Computer Science Tel-Aviv.
Chapter 7 User-Defined Methods. Chapter Objectives  Understand how methods are used in Java programming  Learn about standard (predefined) methods and.
Compiler Construction Rina Zviel-Girshin and Ohad Shacham School of Computer Science Tel-Aviv University.
Run time vs. Compile time
CS-341 Dick Steflik Introduction. C++ General purpose programming language A superset of C (except for minor details) provides new flexible ways for defining.
CS-341 Dick Steflik Introduction. C++ General purpose programming language A superset of C (except for minor details) provides new flexible ways for defining.
The environment of the computation Declarations introduce names that denote entities. At execution-time, entities are bound to values or to locations:
Compiler Summary Mooly Sagiv html://
Java Programming: From Problem Analysis to Program Design, 4e Chapter 7 User-Defined Methods.
Compiler Construction Ran Shaham and Ohad Shacham School of Computer Science Tel-Aviv University.
Lecture 1: Overview of Java. What is java? Developed by Sun Microsystems (James Gosling) A general-purpose object-oriented language Based on C/C++ Designed.
OOP Languages: Java vs C++
Programming Languages and Paradigms Object-Oriented Programming.
CSM-Java Programming-I Spring,2005 Introduction to Objects and Classes Lesson - 1.
Imperative Programming
Adapted from Prof. Necula UCB CS 1641 Overview of COOL ICOM 4029 Lecture 2 ICOM 4029 Fall 2008.
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
The string data type String. String (in general) A string is a sequence of characters enclosed between the double quotes "..." Example: Each character.
Geoff Holmes and Bernhard Pfahringer COMP206-08S General Programming 2.
Code Generation III. PAs PA4 5.1 – 7.2 PA5 (bonus) 24.1 –
Basic Semantics Associating meaning with language entities.
CSE 425: Data Types I Data and Data Types Data may be more abstract than their representation –E.g., integer (unbounded) vs. 64-bit int (bounded) A language.
Using Data Within a Program Chapter 2.  Classes  Methods  Statements  Modifiers  Identifiers.
Compiler Construction Dr. Noam Rinetzky and Orr Tamir School of Computer Science Tel Aviv University
Chapter 12: Pointers, Classes, Virtual Functions, and Abstract Classes.
Copyright Curt Hill Variables What are they? Why do we need them?
Semantic Analysis II. Messages Please check lecturer notices in the Moodle Appeals  Legitimate: “I don’t have the bug you mentioned…”  Illegitimate:
SOEN 343 Software Design Section H Fall 2006 Dr Greg Butler
Semantic Analysis II Type Checking EECS 483 – Lecture 12 University of Michigan Wednesday, October 18, 2006.
Winter Compiler Construction Mooly Sagiv and Roman Manevich School of Computer Science Tel-Aviv University.
Boolean expressions, part 1: Compare operators. Compare operators Compare operators compare 2 numerical values and return a Boolean (logical) value A.
Java & C++ Comparisons How important are classes and objects?? What mechanisms exist for input and output?? Are references and pointers the same thing??
Prof. Necula CS 164 Lecture 171 Operational Semantics of Cool ICOM 4029 Lecture 10.
Memory Management in Java Mr. Gerb Computer Science 4.
FASTFAST All rights reserved © MEP Make programming fun again.
 It is a pure oops language and a high level language.  It was developed at sun microsystems by James Gosling.
Sung-Dong Kim, Dept. of Computer Engineering, Hansung University Java - Introduction.
Design issues for Object-Oriented Languages
CS314 – Section 5 Recitation 9
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
Information and Computer Sciences University of Hawaii, Manoa
Principles of programming languages 10: Object oriented languages
Chapter 7 User-Defined Methods.
Names and Attributes Names are a key programming language feature
Semantic Analysis Type Checking
Type Checking Generalizes the concept of operands and operators to include subprograms and assignments Type checking is the activity of ensuring that the.
Chapter 13: Pointers, Classes, Virtual Functions, and Abstract Classes
Chapter No. : 1 Introduction to Java.
Java Primer 1: Types, Classes and Operators
Representation, Syntax, Paradigms, Types
课程名 编译原理 Compiling Techniques
C Basics.
Chapter 12: Pointers, Classes, Virtual Functions, and Abstract Classes
Java Programming Language
An Introduction to Java – Part I, language basics
CSE401 Introduction to Compiler Construction
Representation, Syntax, Paradigms, Types
Representation, Syntax, Paradigms, Types
CISC/CMPE320 - Prof. McLeod
Representation, Syntax, Paradigms, Types
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
Java Basics Data Types in Java.
Programming Languages and Paradigms
ICOM 4029 Fall 2003 Lecture 2 (Adapted from Prof. Necula UCB CS 164)
IS 135 Business Programming
Presentation transcript:

Winter 2007-2008 Compiler Construction 0368-3133 Mooly Sagiv and Roman Manevich School of Computer Science Tel-Aviv University TODO: ensure consistency in displaying the values of instrumentation predicates for concrete heaps

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/wcc07/

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=55

Generic compiler structure Source text txt Executable code exe Frontend (analysis) Semantic Representation Backend (synthesis)

IC compiler Compiler Source text Executable code IC Program txt Executable code exe Frontend (analysis) Semantic Representation Backend (synthesis) IC Program ic Lexical Analysis Syntax Analysis Parsing AST Symbol Table etc. Inter. Rep. (IR) Code Generation x86 executable exe

How IC Program x86 assembly JFlex JavaCup Java x86 assembly prog.ic Lexical Analysis Syntax Analysis Parsing AST Symbol Table etc. Inter. Rep. (IR) Code Generation x86 assembly prog.s JFlex JavaCup Java x86 assembly prog.s GNU assembler prog.o GNU linker prog.exe libic.a (libic + gc) script / Ant

Grading and schedule 45% 50% exam 5% theoretical assignment 50% project 4 assignments + 1 bonus – different weights code checked both automatically and manually teams PA1 PA2 PA3 PA4 PA5 24/10 31/10 23/1 30/1 6/2 13/2 20/2 27/2 5/3 12/3 19/3 26/3 ??/?? tentative schedule today exam semester ends 7/3 14/3 PA1 = lexical analysis PA2 = parsing PA3 = semantic analysis PA4 = IR and IR lowering PA5 = code generation poll

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

Today Goals: IC language overview Understand the scope of the project Lexical Analysis Syntax Analysis Parsing AST Symbol Table etc. Inter. Rep. (IR) Code Generation Executable code exe Goals: IC language overview See language specification Understand the scope of the project

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)

Unsupported features Access control Interfaces Downcasting Everything is public Interfaces Downcasting Method overloading (but still allow overriding) Exceptions Packages Multiple source files

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[][]

IC types Every class is a type Primitive types: References : null 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

Subtyping Inheritance induces subtyping relation Type hierarchy gives acyclic graph (forest) Subtyping rules: A extends B {…} A ≤ B A ≤ A A ≤ B B ≤ C A ≤ C null ≤ A Subtyping does not extend to array types A subtype of B then A[] is not a subtype of B[]

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

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 x y

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

Example x y p 1 2 x y p q 1 2 x y p this 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; x y p 1 2 x y p q 1 2 x y p this

Method implementation Each object knows how to access method code As if object contains slot pointing to the code In reality implementations save space by sharing these pointers among instances of the same class x y * movePoint * x y methods movePoint

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; } y color * movePoint x

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

Method invocation Example: invoke method p.movePoint(a+b,20/2) Evaluate p Find class of p Find code of movePoint Evaluate arguments a+b,20/2 Bind p to this Bind actual arguments to formal arguments Run method code

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 x y x y x y b 1 2 unreachable object a x y

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. }

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

See you next week