CPSC 388 – Compiler Design and Construction Lecture: MWF 11:00am-12:20pm, Room 106 Colton.

Slides:



Advertisements
Similar presentations
Introduction to Compiler Construction
Advertisements

CPSC 388 – Compiler Design and Construction
Course Outline Traditional Static Program Analysis Software Testing
1 Foundations of Software Design Lecture 24: Compilers, Lexers, and Parsers; Intro to Graphs Marti Hearst Fall 2002.
Compiler Chang Chi-Chung Textbook Compilers: Principles, Techniques, and Tools, 2/E.  Alfred V. Aho, Columbia University  Monica S. Lam,
Compiler Construction
Overview of Compiler Design CIS 631, CSE 691, CIS400, CSE 400 Compiler Design Dr. Nancy McCracken January 15, 2008.
Compiler Construction1 A Compulsory Module for Students in Computer Science Department Faculty of IT / Al – Al Bayt University First Semester 2009/2010.
BİL744 Derleyici Gerçekleştirimi (Compiler Design)1.
1.3 Executing Programs. How is Computer Code Transformed into an Executable? Interpreters Compilers Hybrid systems.
CPSC 388 – Compiler Design and Construction Parsers – Context Free Grammars.
Chapter 1. Introduction.
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.
Introduction to Compiler Construction Robert van Engelen COP5621 Compiler Construction Copyright Robert.
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.
CST 320 Compiler Methods Dr. Sherry Yang PV 171 (541)
1 COMP 3438 – Part II-Lecture 1: Overview of Compiler Design Dr. Zili Shao Department of Computing The Hong Kong Polytechnic Univ.
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.
1 Compiler 3.2 A Level computing. 2 So, Sir what is a compiler?
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.
Introduction Lecture 1 Wed, Jan 12, The Stages of Compilation Lexical analysis. Syntactic analysis. Semantic analysis. Intermediate code generation.
Topic #1: Introduction EE 456 – Compiling Techniques Prof. Carl Sable Fall 2003.
1 Compiler Design (40-414)  Main Text Book: Compilers: Principles, Techniques & Tools, 2 nd ed., Aho, Lam, Sethi, and Ullman, 2007  Evaluation:  Midterm.
國立台灣大學 資訊工程學系 薛智文 98 Spring Compiler TH 234, DTH 103.
. n COMPILERS n n AND n n INTERPRETERS. -Compilers nA compiler is a program thatt reads a program written in one language - the source language- and translates.
INTRODUCTION TO COMPILERS(cond….) Prepared By: Mayank Varshney(04CS3019)
Course Overview for Compilers J. H. Wang Sep. 14, 2015.
The Model of Compilation Natawut Nupairoj, Ph.D. Department of Computer Engineering Chulalongkorn University.
1 Compiler & its Phases Krishan Kumar Asstt. Prof. (CSE) BPRCE, Gohana.
1 CS308 Compiler Theory. 2 Course Information Instructor : –Prof. Minyi Guo –Yao Shen Course.
Course Overview for Compilers J. H. Wang Sep. 20, 2011.
1 February 23, February 23, 2016February 23, 2016February 23, 2016 Azusa, CA Sheldon X. Liang Ph. D. Computer Science at Azusa Pacific University.
1 Asstt. Prof Navjot Kaur Computer Dept PRESENTED BY.
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.
1 Compiler Construction Vana Doufexi office CS dept.
CS416 Compiler Design1. 2 Course Information Instructor : Dr. Ilyas Cicekli –Office: EA504, –Phone: , – Course Web.
Lecture 12 Intermediate Code Generation Translating Expressions
COMP 3002: Compiler Construction Pat Morin School of Computer Science.
Chapter 1. Introduction.
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
Lecture 9 Symbol Table and Attributed Grammars
Compiler Design (40-414) Main Text Book:
Introduction to Compiler Construction
Constructing Precedence Table
Compiler Construction (CS-636)
课程名 编译原理 Compiling Techniques
Compiler Lecture 1 CS510.
CS 536 / Fall 2017 Introduction to programming languages and compilers
Compiler Construction
CS416 Compiler Design lec00-outline September 19, 2018
Introduction to Compiler Construction
Course supervisor: Lubna Siddiqui
Lecture 2: General Structure of a Compiler
Introduction CI612 Compiler Design CI612 Compiler Design.
CPSC 388 – Compiler Design and Construction
Compiler 薛智文 TH 6 7 8, DTH Spring.
CSE401 Introduction to Compiler Construction
Compilers B V Sai Aravind (11CS10008).
Compiler 薛智文 TH 6 7 8, DTH Spring.
CS416 Compiler Design lec00-outline February 23, 2019
Introduction to Compiler Construction
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
Compiler Construction
Lec00-outline May 18, 2019 Compiler Design CS416 Compiler Design.
Compiler 薛智文 M 2 3 4, DTH Spring.
Introduction to Compiler Construction
Presentation transcript:

CPSC 388 – Compiler Design and Construction Lecture: MWF 11:00am-12:20pm, Room 106 Colton

Instructor Louis Oliphant Office: 111 Colton Office Hours: MWF 2:35pm-4:35pm TH 4pm-5pm (Open Door Policy)

Course Description An intense treatment of the theoretical and practical considerations involved in implementing translators for high- level programming languages. Students will design and implement parts of a compiler for a high level language. Prerequisites: CPSC 171 and CPSC 172 or permission.

Course Web Page

Textbook Compilers: Principles, Techniques, & Tools Compilers: Principles, Techniques, & Tools Second Edition Alfred V. Aho, Monica S. Lam, Ravi Sethi, & Jeffrey D. Ullman

Grading  Midterm: 15%  Final: 15%  Homeworks: 30% Approximately weekly written assignments  Programs: 40% 5 assignments building a compiler

Reading Assignment Chapter 1 Homework Assignment Read paper on FORTRAN and write 1 page report. (see webpage for details) Due: Sept 4 th at beginning of class

What is a Compiler? Compiler Source Language L Target Language L’ A compiler translates text from a source language, L, to A target language, L’. Java C++ FORTRAN JVM Intel Pentium MIPS IBM’s CELL

What is a Compiler? Source Language L (sequence of characters) Lexical Analyzer (Scanner) Sequence of Tokens Syntax Analyzer (Parser) Abstract Syntax Tree Symantic Analyzer Augmented, Annotated Abstract Syntax Tree Intermediate Code Generator Intermediate Code Optimizer Optimized Intermediate Code Target Language L’ Assembly Code Machine Code Code Generator

The Scanner  Reads characters from the source program.  Groups characters into lexemes sequences of characters that "go together"  Lexemes corresponds to a tokens; scanner returns next token (plus maybe some additional information) to the parser.  Scanner also discovers lexical errors (e.g., erroneous characters such as # in java).

Example Lexemes and Tokens Lexeme: ; SEMI-COLON = ASSIGN index IDENT tmp IDENT 21 INT-LIT INT-FLOAT Token: Source Code: position = initial + rate * 60 ; Corresponding Tokens: IDENT ASSIGN IDENT PLUS IDENT TIMES INT-LIT SEMI-COLON

The Parser  Groups tokens into "grammatical phrases", discovering the underlying structure of the source program.  Finds syntax errors. For example, in Java the source code position = * 5 ; corresponds to the sequence of tokens: IDENT ASSIGN TIMES INT-LIT SEMI-COLON All are legal tokens, but that sequence of tokens is erroneous.  Might find some "static semantic" errors, e.g., a use of an undeclared variable, or variables that are multiply declared.  Might generate code, or build some intermediate representation of the program such as an abstract-syntax tree.

Example Parse Source Code: position = initial + rate * 60 ; Abstract-Syntax Tree: = position+ initial* rate60 Interior nodes are operators. A node's children are operands. Each subtree forms "logical unit" e.g., the subtree with * at its root shows that because multiplication has higher precedence than addition, this operation must be performed as a unit (not initial+rate).

Semantic Analyzer  Checks for (more) "static semantic" errors  Annotate and/or change the abstract syntax tree

Example Symantic Analysis Abstract-Syntax Tree: = position+ initial* rate60 Annotated Abstract-Syntax Tree: = (float) position+ (float) initial* (float) rate 60 intToFloat (float)

Intermediate Code Generator  Translates from abstract-syntax tree to intermediate code  One possibility is 3-address code each instruction involves at most 3 operands Example: temp1 = inttofloat(60) temp2 = rate * temp1 temp3 = initial + temp2 position = temp3

Optimizer  Tries to improve code to Run faster Be smaller Consume less energy

Try Optimizing This (for speed) int sumcalc(int a, int b, int N) { int i; int x, y; x = 0; y = 0; for(i=0; i<=N; i++) { x=x+(4*a/b)*i+(i+1)*(i+1); x=x+b*y; } return x; }

Some Types of Optimization  Constant Propagation  Algebraic Simplification  Copy Propagation  Common Sub-expression Elimination  Dead Code Elimination  Loop Invariant Removal  Strength Reduction

Code Generator Generate object code from (optimized) intermediate code Example:.data c1:.float 60.0.text l.s$f0,rate mul.s$f0,c1 l.s$f2,initial add.s$f0,$f0,$f2 s.s$f0,position

Symbol Tables Lexical Analyzer (Scanner) Syntax Analyzer (Parser) Symantic Analyzer Intermediate Code Generator Optimizer Code Generator Symbol Table

Symbol Tables  Keep track of names declared in the program  Separate level for each scope  Used to analyze static symantics: Variables should not be declared more than once in a scope Variables should not be used before being declared Parameter types for methods should match method declaration

Compiler Modularity Lexical Analyzer (Scanner) Syntax Analyzer (Parser) Symantic Analyzer Intermediate Code Generator Optimizer Code Generator Front End Back End

Many Compilers Java C.Net FORTRAN … JVM Intel Pentium IBM Cell … Motorola Processor

Many Compilers Java C.Net FORTRAN … JVM Intel Pentium IBM Cell … Motorola Processor Intermediate Code Optimization

Summary  Compilers Translate Source Language to Target Language  Compilers have several steps Scanner Parser Semantic Analyzer Intermediate Code Generator Optimizer Code Generator  Symbol Table Used To Keep Track of Names Used in Program  Front End and Back End Simplify Compiler Design Introduction of new languages Introduction of new hardware

Reading Assignment Chapter 1 Homework Assignment Read paper on FORTRAN and write 1 page report. (see webpage for details) Due: Sept 4 th at beginning of class