CSE401 Introduction to Compiler Construction

Slides:



Advertisements
Similar presentations
Compilers Course 379K, TTH 9:30-11:00 Instructor: Dr. Doron A. Peled Office Hours: Mon 11:00-12:00.
Advertisements

Chapter 2-2 A Simple One-Pass Compiler
CPSC 388 – Compiler Design and Construction
1 CIS 461 Compiler Design and Construction Fall 2014 Instructor: Hugh McGuire slides derived from Tevfik Bultan, Keith Cooper, and Linda Torczon Lecture-Module.
Lexical Analysis Lexical analysis is the first phase of compilation: The file is converted from ASCII to tokens. It must be fast!
Reference Book: Modern Compiler Design by Grune, Bal, Jacobs and Langendoen Wiley 2000.
Compiler Summary Mooly Sagiv html://
Compiler Construction
Overview of Compiler Design CIS 631, CSE 691, CIS400, CSE 400 Compiler Design Dr. Nancy McCracken January 15, 2008.
Chapter 2 A Simple Compiler
Building An Interpreter After having done all of the analysis, it’s possible to run the program directly rather than compile it … and it may be worth it.
Introduction & Overview CS4533 from Cooper & Torczon.
CPSC 388 – Compiler Design and Construction Lecture: MWF 11:00am-12:20pm, Room 106 Colton.
CPSC 388 – Compiler Design and Construction Parsers – Context Free Grammars.
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.
Lexical Analysis - An Introduction. The Front End The purpose of the front end is to deal with the input language Perform a membership test: code  source.
Lexical Analysis - An Introduction Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved. Students enrolled in Comp 412 at.
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.
The TINY sample language and it’s compiler
1 COMP 3438 – Part II-Lecture 1: Overview of Compiler Design Dr. Zili Shao Department of Computing The Hong Kong Polytechnic Univ.
CS412/413 Introduction to Compilers and Translators Spring ’99 Lecture 8: Semantic Analysis and Symbol Tables.
Unit-1 Introduction Prepared by: Prof. Harish I Rathod
May 31, May 31, 2016May 31, 2016May 31, 2016 Azusa, CA Sheldon X. Liang Ph. D. Computer Science at Azusa Pacific University Azusa Pacific University,
CS453 LectureIntroduction1 CS453 Compiler Construction Instructor:Wim Bohm Computer Science Building 470 TA: tba
Chapter 2. Design of a Simple Compiler J. H. Wang Sep. 21, 2015.
CPS 506 Comparative Programming Languages Syntax Specification.
1 Compiler Construction (CS-636) Muhammad Bilal Bashir UIIT, Rawalpindi.
1 Compiler Design (40-414)  Main Text Book: Compilers: Principles, Techniques & Tools, 2 nd ed., Aho, Lam, Sethi, and Ullman, 2007  Evaluation:  Midterm.
Introduction to Compiling
Introduction CPSC 388 Ellen Walker Hiram College.
Programming Languages
Week 6(10.7): The TINY sample language and it ’ s compiler The TINY + extension of TINY Week 7 and 8(10.14 and 10.21): The lexical of TINY + Implement.
Compiler Design Introduction 1. 2 Course Outline Introduction to Compiling Lexical Analysis Syntax Analysis –Context Free Grammars –Top-Down Parsing –Bottom-Up.
INTRODUCTION TO COMPILERS(cond….) Prepared By: Mayank Varshney(04CS3019)
Compiler Introduction 1 Kavita Patel. Outlines 2  1.1 What Do Compilers Do?  1.2 The Structure of a Compiler  1.3 Compilation Process  1.4 Phases.
1 A Simple Syntax-Directed Translator CS308 Compiler Theory.
C H A P T E R T W O Linking Syntax And Semantics Programming Languages – Principles and Paradigms by Allen Tucker, Robert Noonan.
Compiler Construction CPCS302 Dr. Manal Abdulaziz.
CSC 4181 Compiler Construction
LECTURE 3 Compiler Phases. COMPILER PHASES Compilation of a program proceeds through a fixed series of phases.  Each phase uses an (intermediate) form.
Language Implementation Overview John Keyser Spring 2016.
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.
CS416 Compiler Design1. 2 Course Information Instructor : Dr. Ilyas Cicekli –Office: EA504, –Phone: , – Course Web.
CS510 Compiler Lecture 1. Sources Lecture Notes Book 1 : “Compiler construction principles and practice”, Kenneth C. Louden. Book 2 : “Compilers Principles,
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
Lecture 9 Symbol Table and Attributed Grammars
Chapter 3 – Describing Syntax
Advanced Computer Systems
Intro to compilers Based on end of Ch. 1 and start of Ch. 2 of textbook, plus a few additional references.
Compiler Design (40-414) Main Text Book:
Chapter 1 Introduction.
CS 3304 Comparative Languages
Compiler Construction (CS-636)
Chapter 1 Introduction.
Compiler Lecture 1 CS510.
CS 536 / Fall 2017 Introduction to programming languages and compilers
CS416 Compiler Design lec00-outline September 19, 2018
Basic Program Analysis: AST
Front End vs Back End of a Compilers
Chapter 2: A Simple One Pass Compiler
CSE 3302 Programming Languages
Compilers B V Sai Aravind (11CS10008).
CMPE 152: Compiler Design August 21/23 Lab
Designing a Predictive Parser
System Programming and administration
CS416 Compiler Design lec00-outline February 23, 2019
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
Compiler Construction
Lec00-outline May 18, 2019 Compiler Design CS416 Compiler Design.
Presentation transcript:

CSE401 Introduction to Compiler Construction Larry Snyder Allen 584

CSE401: Intro to Compiler Construction Goals Learn principles and practice of language implementation Bring together theory and pragmatics of previous classes Understand compiler-time vs run-time processing Study interactions among Language features Implementation efficiency Compiler complexity Architectural features Gain more experience with oo design Gain more experience with working in a team

Administrivia Prerequisites: 322, 326, 341, 378 Text: Engineering a Compiler, Cooper and Torczon, Morgan-Kaufmann 2004 Course Web will be up shortly Sign up for mailing list Grading: Project 40% Homework 15% MT 15% Final 25% Class Participation 5% … it’s a cool topic, lock into it

Project Start with a MiniJava complier in Java … improve it Add: Comments Floating-point values Arrays Static (class) variables For loops Break Statements … And more Completed in stages over the term Strongly encouraged: Work in teams, but only if joint work, not divided work Grading Basis Correctness Clarity of design/impl Quality of test cases

Example Compilation Sample (extended) MiniJava program: Factorial.java // Computes 10! and prints it out class Factorial { public static void main(String[] a) { System.out.println( new Fac().ComputeFac(10)); } class Fac { // the recursive helper function public int ComputeFac(int num) { int numAux; if (num < 1) numAux = 1; else numAux = num * this.ComputeFac(num-1); return numAux;

First Step: Lexical Analysis “Scanning”, “tokenizing” Read in characters, clump into tokens strip out whitespace & comments in the process

Specifying tokens: Regular Expressions Example: Ident ::= Letter AlphaNum* Integer ::= Digit+ AlphaNum ::= Letter | Digit Letter ::= 'a' | ... | 'z' | 'A' | ... | 'Z' Digit ::= '0' | ... | '9'

Second Step: Syntactic Analysis “Parsing” -- Read in tokens, turn into a tree based on syntactic structure report any errors in syntax

Specifying Syntax: Context-free Grammars EBNF is a popular notation for CFG’s Example: Stmt ::= if (Expr ) Stmt [else Stmt] | while (Expr ) Stmt | ID = Expr; | ... Expr ::= Expr + Expr | Expr < Expr | ... | ! Expr | Expr . ID ( [Expr {, Expr}] ) | ID | Integer | (Expr) EBNF specifies concrete syntax of language; parser constructs tree of the abstract syntax of the language

Third Step: Semantic Analysis “Name resolution and type checking” Given AST: figure out what declaration each name refers to perform type checking and other static consistency checks Key data structure: symbol table maps names to info about name derived from declaration tree of symbol tables corresponding to nesting of scopes Semantic analysis steps: 1. Process each scope, top down 2. Process declarations in each scope into symbol table for scope 3. Process body of each scope in context of symbol table

Fourth Step: Intermediate Code Gen Given annotated AST & symbol tables, translate into lower-level intermediate code Intermediate code is a separate language Source-language independent Target-machine independent Intermediate code is simple and regular Good representation for doing optimizations Might be a reasonable target language itself, e.g. Java bytecode

Example Int Fac.ComputeFac(*? this, int num) { int t1, numAux, t8, t3, t7, t2, t6, t0 t0 := 1; t1 := num < t0; ifnonzero t1 goto L0; t2 := 1; t3 := num - t2; t6 := Fac.ComputeFac(this, t3); t7 := num * t6; numAux := t7; goto L2; label L0; t8 := 1; numAux := t8 label L2; return numAux }

Fifth Step: Target Machine Code Gen Translate intermediate code into target code Need to do: Instruction selection: choose target instructions for (subsequences) of IR insts. Register allocation: allocate IR code variables to registers, spilling to memory when necessary Compute layout of each procedures stack frames and other runtime data structures Emit target code