Your SlideShare is downloading. ×
Modern Compiler Design
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Saving this for later?

Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime - even offline.

Text the download link to your phone

Standard text messaging rates apply

Modern Compiler Design

2,127
views

Published on

Published in: Technology

0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
2,127
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
102
Comments
0
Likes
1
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Mooly Sagiv and Greta Yorsh School of Computer Science Tel-Aviv University [email_address] http://www.cs.tau.ac.il/~gretay Modern Compiler Design T1 - Overview
  • 2. Who
    • Greta Yorsh
    • Schrieber Open-space
    • Tel: 640-5358
    • [email_address]
    • Wednesday 16:00-17:00
    • http://www.cs.tau.ac.il/~gretay
  • 3. What Semantic Representation Backend (synthesis) Compiler Frontend (analysis) Executable code exe Source text txt
  • 4. Say What? Semantic Representation Backend (synthesis) Compiler Frontend (analysis) Lexical Analysis Syntax Analysis Parsing AST Symbol Table etc. Inter. Rep. (IR) Code Gen. Executable code exe Source text txt Cool Language txt Executable code exe
  • 5. How Lexical Analysis Syntax Analysis Parsing AST Symbol Table etc. Inter. Rep. (IR) Code Gen. flex bison C++ Cool GC MIPS assembly SPIM Cool Language txt Executable code exe
  • 6. Project - a complete compiler
    • Cool to MIPS assembly language
    • Implemented in C++
    • Split into assignments
  • 7. Grading
    • 50% exam
    • 10% theoretical assignment
    • 40% project
      • 5 assignments – different weights
      • code checked both automatically and manually
    today exam teams PA1 PA2 TA1 PA3 PA4 PA5
  • 8. Project Guidelines
    • Teams of 3 students
      • email me before next practice
      • team account
    • In case of doubt – ask questions in the Forum
    • There is adequate time to complete assignments
    • Start early and please follow directions
    • Submit assignments on schedule
  • 9.
    • Goals:
      • Understand the scope of the project
      • How to write a Cool program
    Today Lexical Analysis Syntax Analysis Parsing AST Symbol Table etc. Inter. Rep. (IR) Code Gen. Cool Language txt Executable code exe
  • 10. Cool Overview
    • Classroom Object Oriented Language
    • Implementation of modern
      • abstraction
      • static typing
      • reuse (inheritance)
      • memory management
      • and more…
  • 11. Good News
    • No arrays
    • No floating point operations
    • No “static” modifier
    • No interfaces
    • No method overloading (but still allow overriding)
    • No exceptions
    • No packages
  • 12. Better News
    • Cool language is still rich enough for doing interesting things
  • 13. A Simple Example
    • class Point {
    • x : Int  0;
    • y : Int  0;
    • };
    • Cool programs are sets of class definitions
    • class = a collection of attributes and methods
      • A special class Main with a special method main
      • No separate notion of subroutine
    • Instance of a class are objects
  • 14. Cool Objects
    • class Point {
    • x : Int  0;
    • y : Int ; (* use default value *)
    • };
    • The expression “new Point” creates a new object of class Point
    • An object can be thought of as a struct (record) with a slot for each attribute
    0 0 x y
  • 15. Methods
    • class Point {
    • x : Int  0;
    • y : Int  0;
    • movePoint (newx : Int, newy : Int) : Point {
    • { x  newx;
    • y  newy;
    • self;
    • } – close block expression
    • }; -- close method
    • }; -- close class
    • A class can also define methods for manipulating the attributes
    • Methods can refer to the current object using self
  • 16. Information Hiding in Cool
    • Methods are global (public)
    • Attributes are local to a class (private)
      • they can only be accessed by the class’s methods
    • Example
    • class Point {
    • getx () : Int { x };
    • setx (newx : Int) : Int { x  newx };
    • };
  • 17. Methods
    • Each object knows how to access the code of a method
    • As if the object contains a slot pointing to the node
    • In reality implementations save space by sharing these pointers among instances of the same class
    0 0 x y * movePoint methods 0 0 x y * movePoint
  • 18. Inheritance
    • We can extend points to colored points using subclass (class hierarchy)
    • class ColorPoint inherits Points {
    • color : Int  0;
    • movePoint(newx : Int, newy : Int) : Point {
    • { color  0;
    • x  newx; y  newy;
    • self;
    • }
    • };
    • };
    0 0 y color * movePoint 0 x
  • 19. Cool Types
    • Every class is a type
    • Base classes:
      • Int
      • Bool (true, false)
      • String
      • Object (root of the class hierarchy)
    • All variables must be declared
      • compiler infers types for expressions
  • 20. Cool Type Checking
    • x : A;
    • x  new B;
    • 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
      • A well-typed program cannot result in runtype type errors
  • 21. Method Invocation and Ingeritance
    • 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
  • 22. Method Invokation
    • Example: invoke one-argument method m
    • e.m(e’)
    • Eval e
    • Find class of e
    • Find code of m
    • Eval argument
    • Bind self and x
    • Run method
  • 23. 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 operations
      • Logical operations
      • Assignment x  E
  • 24. 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
  • 25. Cool Language - Main features
    • Object oriented
      • Objects, virtual method calls, but no overloading
    • Strongly typed
      • Primitives for int, boolean, string
      • Reference types
    • Dynamic allocation and Garbage Collection
      • Heap allocation, automatic deallocation
    • Many things are left out
      • short time implementation
    • Adapted with permission from Prof. Alex Aiken (Berkeley,Standford)