CS 153: Concepts of Compiler Design August 25 Class Meeting Department of Computer Science San Jose State University Fall 2014 Instructor: Ron Mak www.cs.sjsu.edu/~mak.

Slides:



Advertisements
Similar presentations
Introduction to Compiler Construction
Advertisements

1 Pass Compiler 1. 1.Introduction 1.1 Types of compilers 2.Stages of 1 Pass Compiler 2.1 Lexical analysis 2.2. syntactical analyzer 2.3. Code generation.
Compiler Construction
1.3 Executing Programs. How is Computer Code Transformed into an Executable? Interpreters Compilers Hybrid systems.
Invitation to Computer Science 5th Edition
CS 153: Concepts of Compiler Design August 24 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
Chapter 1 Introduction Dr. Frank Lee. 1.1 Why Study Compiler? To write more efficient code in a high-level language To provide solid foundation in parsing.
CS 235: User Interface Design August 25 Class Meeting Department of Computer Science San Jose State University Fall 2014 Instructor: Ron Mak
Chapter 10: Compilers and Language Translation Invitation to Computer Science, Java Version, Third Edition.
CSC 338: Compiler design and implementation
Compiler course 1. Introduction. Outline Scope of the course Disciplines involved in it Abstract view for a compiler Front-end and back-end tasks Modules.
CS 326 Programming Languages, Concepts and Implementation Instructor: Mircea Nicolescu Lecture 2.
1 COMP 3438 – Part II-Lecture 1: Overview of Compiler Design Dr. Zili Shao Department of Computing The Hong Kong Polytechnic Univ.
CS 153: Concepts of Compiler Design October 5 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
Unit-1 Introduction Prepared by: Prof. Harish I Rathod
1.  10% Assignments/ class participation  10% Pop Quizzes  05% Attendance  25% Mid Term  50% Final Term 2.
CS 152: Programming Language Paradigms April 2 Class Meeting Department of Computer Science San Jose State University Spring 2014 Instructor: Ron Mak
CS453 LectureIntroduction1 CS453 Compiler Construction Instructor:Wim Bohm Computer Science Building 470 TA: tba
CS 153: Concepts of Compiler Design August 26 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
CS 153: Concepts of Compiler Design September 16 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
1 Chapter 1 Introduction. 2 Outlines 1.1 Overview and History 1.2 What Do Compilers Do? 1.3 The Structure of a Compiler 1.4 The Syntax and Semantics of.
Compiler design Lecture 1: Compiler Overview Sulaimany University 2 Oct
Chapter 1 Introduction. Chapter 1 - Introduction 2 The Goal of Chapter 1 Introduce different forms of language translators Give a high level overview.
1. 2 Preface In the time since the 1986 edition of this book, the world of compiler design has changed significantly 3.
CS 460/660 Compiler Construction. Class 01 2 Why Study Compilers? Compilers are important – –Responsible for many aspects of system performance Compilers.
CS 153: Concepts of Compiler Design September 21 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
Overview of Previous Lesson(s) Over View  A program must be translated into a form in which it can be executed by a computer.  The software systems.
1 Compiler Design (40-414)  Main Text Book: Compilers: Principles, Techniques & Tools, 2 nd ed., Aho, Lam, Sethi, and Ullman, 2007  Evaluation:  Midterm.
CS 153: Concepts of Compiler Design October 10 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
Chapter 1 Introduction Major Data Structures in Compiler
CS 153: Concepts of Compiler Design October 21 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
1 Compiler & its Phases Krishan Kumar Asstt. Prof. (CSE) BPRCE, Gohana.
CS453 LectureIntroduction1 CS453 Compiler Construction Original Design: Michelle Strout Instructor:Wim Bohm
Compiler Construction CPCS302 Dr. Manal Abdulaziz.
CSC 4181 Compiler Construction
CS 152: Programming Language Paradigms April 7 Class Meeting Department of Computer Science San Jose State University Spring 2014 Instructor: Ron Mak
1 Asstt. Prof Navjot Kaur Computer Dept PRESENTED BY.
CS 153: Concepts of Compiler Design October 12 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
ICS312 Introduction to Compilers Set 23. What is a Compiler? A compiler is software (a program) that translates a high-level programming language to machine.
Overview of Compilation Prepared by Manuel E. Bermúdez, Ph.D. Associate Professor University of Florida Programming Language Principles Lecture 2.
1 Compiler Construction Vana Doufexi office CS dept.
Software Engineering Algorithms, Compilers, & Lifecycle.
CS 153: Concepts of Compiler Design September 28 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
CS 432: Compiler Construction Lecture 1
Advanced Computer Systems
CS 153: Concepts of Compiler Design September 14 Class Meeting
Compiler Design (40-414) Main Text Book:
CS 153: Concepts of Compiler Design August 24 Class Meeting
Introduction to Compiler Construction
CS 153: Concepts of Compiler Design August 29 Class Meeting
Overview of Compilation The Compiler Front End
CS 153: Concepts of Compiler Design November 30 Class Meeting
Compiler Lecture 1 CS510.
CMPE 152: Compiler Design December 5 Class Meeting
CMPE 152: Compiler Design January 25 Class Meeting
Compiler Construction
Course supervisor: Lubna Siddiqui
Compiler Construction
CMPE 152: Compiler Design October 4 Class Meeting
CMPE 152: Compiler Design August 21 Class Meeting
CMPE 152: Compiler Design September 11/13 Lab
CMPE 152: Compiler Design August 23 Class Meeting
CMPE 152: Compiler Design August 21/23 Lab
CMPE 152: Compiler Design January 24 Class Meeting
Introduction to Compiler Construction
CMPE 152: Compiler Design January 29 Class Meeting
CMPE 152: Compiler Design February 21/26 Lab
Introduction to Compiler Construction
CMPE 152: Compiler Design August 22 Class Meeting
CMPE 152: Compiler Design August 27 Class Meeting
Presentation transcript:

CS 153: Concepts of Compiler Design August 25 Class Meeting Department of Computer Science San Jose State University Fall 2014 Instructor: Ron Mak 1

Computer Science Dept. Fall 2014: August 25 CS 153: Concepts of Compiler Design © R. Mak 2 Goals of the Course  Understand the concepts of compilers and interpreters. Parser, scanner, tokens Symbol tables, intermediate code Executors, code generators Compiler-compilers _

Computer Science Dept. Fall 2014: August 25 CS 153: Concepts of Compiler Design © R. Mak 3 Goals of the Course, cont’d  Learn important job skills that employers want. Work as a member of a small programming team. Understand and modify a Big Hairy Legacy Application. Use modern software engineering practices to develop a complex application. _

Computer Science Dept. Fall 2014: August 25 CS 153: Concepts of Compiler Design © R. Mak 4 Course Notes  Class website Green sheet Lecture notes and handouts Assignments _

Computer Science Dept. Fall 2014: August 25 CS 153: Concepts of Compiler Design © R. Mak 5 Required Textbooks  Java source code from the compiler textbook: Writing Compilers and Interpreters, 3 rd edition  Second required textbook: Generating Parsers with JavaCC, 2 nd edition (PDF) _

Computer Science Dept. Fall 2014: August 25 CS 153: Concepts of Compiler Design © R. Mak Compiler Magic? 6 Demo C compiler: int main() { printf("Hello, C world!\n"); } Java compiler: public class Hello { public static void main(String args[]) { System.out.println("Hello, Java world!"); } Pascal compiler: PROGRAM hello; BEGIN writeln('Hello, Pascal world!'); END.

Computer Science Dept. Fall 2014: August 25 CS 153: Concepts of Compiler Design © R. Mak 7 Overview of the Compilation Process hello.pas Pascal compiler (you will write this in Java) hello.j Jasmin assembler (provided for you) hello.class Java linker & loader (provided for you) Java Virtual Machine (provided for you) Translation: Execution: Hello.java Java compiler Hello.class Java linker & loaderJava Virtual Machine javac Hello.java... java Hello... What’s in this box? assembly language object program Translation: binary object program

Computer Science Dept. Fall 2014: August 25 CS 153: Concepts of Compiler Design © R. Mak 8 What is a Compiler?  A software utility that is extremely important for developing applications …  … usually overlooked and taken for granted...  UNLESS you can’t get your program to compile! _

Computer Science Dept. Fall 2014: August 25 CS 153: Concepts of Compiler Design © R. Mak 9 A Compiler is a Translator  A compiler translates a program that you’ve written ... in a high-level language C, C++, Java, Pascal, etc. ... into a low-level language assembly language or machine language ... that a computer can understand and eventually execute.

Computer Science Dept. Fall 2014: August 25 CS 153: Concepts of Compiler Design © R. Mak 10 Take roll!

Computer Science Dept. Fall 2014: August 25 CS 153: Concepts of Compiler Design © R. Mak Assignment #1  Posted to the class web page:  Write a simple Pascal program.  An individual (not team) assignment.  Due Wednesday, September 3. _ 11

Computer Science Dept. Fall 2014: August 25 CS 153: Concepts of Compiler Design © R. Mak 12 More Definitions  source program: the program (application) that you write in a high-level language which the compiler will translate Usually stored in a source file.  source language: the high-level language in which you write your source program Pascal _

Computer Science Dept. Fall 2014: August 25 CS 153: Concepts of Compiler Design © R. Mak 13 More Definitions, cont’d  object language: the low-level language (AKA target language) into which the compiler translates the source program Do not confuse object language with object-oriented language. Jasmin assembly language  object program: your program after it has been translated into the object language _

Computer Science Dept. Fall 2014: August 25 CS 153: Concepts of Compiler Design © R. Mak 14 More Definitions, cont’d  target machine: the computer that will eventually execute the object program Java Virtual Machine (JVM) The JVM runs on your workstation or laptop (any computer that supports Java)  implementation language: the language that the compiler itself is written in Java _

Computer Science Dept. Fall 2014: August 25 CS 153: Concepts of Compiler Design © R. Mak 15 Conceptual Design (Version 1)  Parser Controls the translation process. Repeatedly asks the scanner for the next token.  Scanner Repeatedly reads characters from the source to construct tokens for the parser.  Token A source language element  identifier (name)  number  special symbol (+ - * / = etc.)  reserved word Also reads from the source  Source The source program

Computer Science Dept. Fall 2014: August 25 CS 153: Concepts of Compiler Design © R. Mak 16 Token  A low-level element of the source language. AKA lexeme  Pascal language tokens Identifiers  names of variables, types, procedures, functions, enumeration values, etc. Numbers  integer and real (floating-point) Reserved words  BEGIN END IF THEN ELSE AND OR NOT etc. Special symbols  + - * / := = >.,.. : ( ) [ ] { } ′

Computer Science Dept. Fall 2014: August 25 CS 153: Concepts of Compiler Design © R. Mak 17 Parser  Controls the translation process. Repeatedly asks the scanner for the next token.  Knows the syntax (“grammar”) of the source language’s statements and expressions. Analyzes the sequence of tokens to determine what kind of statement or expression it is translating. Verifies that what it’s seeing is syntactically correct. Flags any syntax errors that it finds and attempts to recover from them. _

Computer Science Dept. Fall 2014: August 25 CS 153: Concepts of Compiler Design © R. Mak 18 Parser, cont’d  What the parser does is called parsing. It parses the source program in order to translate it. AKA syntax analyzer _

Computer Science Dept. Fall 2014: August 25 CS 153: Concepts of Compiler Design © R. Mak 19 Scanner  Reads characters sequentially from the source in order to construct and return the next token whenever requested by the parser. Knows the syntax of the source language’s tokens.  What the scanner does is called scanning. It scans the source program in order to extract tokens. AKA lexical analyzer _

Computer Science Dept. Fall 2014: August 25 CS 153: Concepts of Compiler Design © R. Mak 20 Conceptual Design (Version 2)  We can architect a compiler with three major parts:

Computer Science Dept. Fall 2014: August 25 CS 153: Concepts of Compiler Design © R. Mak 21 Major Parts of a Compiler  Front end Parser, Scanner, Source, Token  Intermediate tier Intermediate code (icode)  “Predigested” form of the source code that the back end can process efficiently.  Example: parse trees  AKA intermediate representation (IR) Symbol table (symtab)  Stores information about the symbols (such as the identifiers) contained in the source program.  Back end Code generator  Processes the icode and the symtab in order to generate the object code. Only the front end needs to be source language-specific. The intermediate tier and the back end can be language-independent!

Computer Science Dept. Fall 2014: August 25 CS 153: Concepts of Compiler Design © R. Mak 22 What Else Can Compilers Do?  Compilers allow you to program in a high-level language and think about your algorithms, not about machine architecture.  Compilers provide language portability. You can run your C++ and Java programs on different machines because their compilers enforce language standards. _

Computer Science Dept. Fall 2014: August 25 CS 153: Concepts of Compiler Design © R. Mak 23 What Else Can Compilers Do? cont’d  Compilers can optimize and improve the execution of your programs. Optimize the object code for speed. Optimize the object code for size. Optimize the object code for power consumption. _

Computer Science Dept. Fall 2014: August 25 CS 153: Concepts of Compiler Design © R. Mak 24 Course Overview  First half: Modify a Pascal interpreter. The interpreter is written in Java (the implementation language). The source programs are written in Pascal (the source language). The implementation code for the interpreter will be presented to you incrementally.  Midterm _

Computer Science Dept. Fall 2014: August 25 CS 153: Concepts of Compiler Design © R. Mak 25 Course Overview, cont’d  Second half: Your compiler project. JavaCC compiler-compiler Java Virtual Machine (JVM) architecture Jasmin assembly language Back end code generator  Final _

Computer Science Dept. Fall 2014: August 25 CS 153: Concepts of Compiler Design © R. Mak 26 Project Teams  Projects will be done by small project teams. Projects may be broken up into assignments.  Form your own teams of 4 members each.  Choose your team members wisely! Be sure you’ll be able to meet and communicate with each other and work together well. No moving from team to team.  Each team member will receive the same score on each team assignment and team project.

Computer Science Dept. Fall 2014: August 25 CS 153: Concepts of Compiler Design © R. Mak Project Teams, cont’d  Each team to by Friday, August Your team name A list of team members and addresses  Subject: CS 153 Team Team Name Example: CS 153 Team Super Coders _ 27

Computer Science Dept. Fall 2014: August 25 CS 153: Concepts of Compiler Design © R. Mak 28 Individual Responsibilities You are personally responsible for participating and contributing to your team’s work, and for understanding each part of the work for every assignment whether or not you worked on that part.