May 31, 2016 1 May 31, 2016May 31, 2016May 31, 2016 Azusa, CA Sheldon X. Liang Ph. D. Computer Science at Azusa Pacific University Azusa Pacific University,

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

From Cooper & Torczon1 The Front End The purpose of the front end is to deal with the input language Perform a membership test: code  source language?
Lexical Analysis III Recognizing Tokens Lecture 4 CS 4318/5331 Apan Qasem Texas State University Spring 2015.
1 The scanning process Main goal: recognize words/tokens Snapshot: At any point in time, the scanner has read some input and is on the way to identifying.
1 The scanning process Goal: automate the process Idea: –Start with an RE –Build a DFA How? –We can build a non-deterministic finite automaton (Thompson's.
College of Computer Science & Technology Compiler Construction Principles & Implementation Techniques -1- Compiler Construction Principles & Implementation.
From Cooper & Torczon1 Implications Must recognize legal (and illegal) programs Must generate correct code Must manage storage of all variables (and code)
Compiler Construction
BİL744 Derleyici Gerçekleştirimi (Compiler Design)1.
CS 153: Concepts of Compiler Design August 25 Class Meeting Department of Computer Science San Jose State University Fall 2014 Instructor: Ron Mak
Introduction & Overview CS4533 from Cooper & Torczon.
CS 3240: Languages and Computation Course Overview Sasha Boldyreva.
CS 540 Spring CS 540 Spring 2013 GMU2 The Course covers: Lexical Analysis Syntax Analysis Semantic Analysis Runtime environments Code Generation.
September 7, September 7, 2015September 7, 2015September 7, 2015 Azusa, CA Sheldon X. Liang Ph. D. Computer Science at Azusa Pacific University.
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.
1 October 1, October 1, 2015October 1, 2015October 1, 2015 Azusa, CA Sheldon X. Liang Ph. D. Computer Science at Azusa Pacific University Azusa.
1 October 2, October 2, 2015October 2, 2015October 2, 2015 Azusa, CA Sheldon X. Liang Ph. D. Computer Science at Azusa Pacific University Azusa.
Chapter 10: Compilers and Language Translation Invitation to Computer Science, Java Version, Third Edition.
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.
어휘분석 (Lexical Analysis). Overview Main task: to read input characters and group them into “ tokens. ” Secondary tasks: –Skip comments and whitespace;
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.
Concordia University Department of Computer Science and Software Engineering Click to edit Master title style COMPILER DESIGN Review Joey Paquet,
Lecture # 3 Chapter #3: Lexical Analysis. Role of Lexical Analyzer It is the first phase of compiler Its main task is to read the input characters and.
1 COMP 3438 – Part II-Lecture 1: Overview of Compiler Design Dr. Zili Shao Department of Computing The Hong Kong Polytechnic Univ.
Lexical Analysis I Specifying Tokens Lecture 2 CS 4318/5531 Spring 2010 Apan Qasem Texas State University *some slides adopted from Cooper and Torczon.
Joey Paquet, Lecture 12 Review. Joey Paquet, Course Review Compiler architecture –Lexical analysis, syntactic analysis, semantic.
4b 4b Lexical analysis Finite Automata. Finite Automata (FA) FA also called Finite State Machine (FSM) –Abstract model of a computing entity. –Decides.
D. M. Akbar Hussain: Department of Software & Media Technology 1 Compiler is tool: which translate notations from one system to another, usually from source.
CS412/413 Introduction to Compilers Radu Rugina Lecture 4: Lexical Analyzers 28 Jan 02.
1 November 1, November 1, 2015November 1, 2015November 1, 2015 Azusa, CA Sheldon X. Liang Ph. D. Computer Science at Azusa Pacific University Azusa.
Lexical Analysis: Finite Automata CS 471 September 5, 2007.
Introduction to Compilers. Related Area Programming languages Machine architecture Language theory Algorithms Data structures Operating systems Software.
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
Compiler Design Introduction 1. 2 Course Outline Introduction to Compiling Lexical Analysis Syntax Analysis –Context Free Grammars –Top-Down Parsing –Bottom-Up.
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.
Compiler Construction By: Muhammad Nadeem Edited By: M. Bilal Qureshi.
Lexical Analysis – Part II EECS 483 – Lecture 3 University of Michigan Wednesday, September 13, 2006.
1 January 18, January 18, 2016January 18, 2016January 18, 2016 Azusa, CA Sheldon X. Liang Ph. D. Computer Science at Azusa Pacific University Azusa.
CS412/413 Introduction to Compilers and Translators Spring ’99 Lecture 2: Lexical Analysis.
What is a compiler? –A program that reads a program written in one language (source language) and translates it into an equivalent program in another language.
1 February 23, February 23, 2016February 23, 2016February 23, 2016 Azusa, CA Sheldon X. Liang Ph. D. Computer Science at Azusa Pacific University.
1 February 23, February 23, 2016February 23, 2016February 23, 2016 Azusa, CA Sheldon X. Liang Ph. D. Computer Science at Azusa Pacific University.
CSC 4181 Compiler Construction
©SoftMoore ConsultingSlide 1 Structure of Compilers.
CS 404Ahmed Ezzat 1 CS 404 Introduction to Compiler Design Lecture 1 Ahmed Ezzat.
LECTURE 5 Scanning. SYNTAX ANALYSIS We know from our previous lectures that the process of verifying the syntax of the program is performed in two stages:
1 Compiler Construction Vana Doufexi office CS dept.
Presented by : A best website designer company. Chapter 1 Introduction Prof Chung. 1.
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,
Advanced Computer Systems
Compiler Design (40-414) Main Text Book:
Chapter 1 Introduction.
CS 3304 Comparative Languages
Chapter 1 Introduction.
课程名 编译原理 Compiling Techniques
Compiler Lecture 1 CS510.
CS416 Compiler Design lec00-outline September 19, 2018
Lecture 2: General Structure of a Compiler
Introduction CI612 Compiler Design CI612 Compiler Design.
Lexical Analysis - An Introduction
CSE401 Introduction to Compiler Construction
Subject: Language Processor
CS416 Compiler Design lec00-outline February 23, 2019
Lexical Analysis - An Introduction
Compiler Construction
Lec00-outline May 18, 2019 Compiler Design CS416 Compiler Design.
Presentation transcript:

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, Azusa, CA 91702, Tel: (800) Department of Computer Science, CS400 Compiler Construction

May 31, Azusa Pacific University, Azusa, CA 91702, Tel: (800) Department of Computer Science, Administrative info  Instructor  Name: Sheldon X. Liang   Office: WC 204  Hours: to set up appointment CS400 Compiler Construction

May 31, CS400 Compiler Construction Azusa Pacific University, Azusa, CA 91702, Tel: (800) Department of Computer Science, Administrative info  Course webpage  cs-linux.cs.apu.edu/~sliang  contains: lecture notes & other handouts howeworks & manuals policies, grades useful links

May 31, CS400 Compiler Construction Azusa Pacific University, Azusa, CA 91702, Tel: (800) Department of Computer Science, What is a compiler  A program that reads a program written in some language and translates it into a program written in some other language Modula-2 to C Java to bytecodes Ada to C++  How was the first compiler created?

May 31, CS400 Compiler Construction Azusa Pacific University, Azusa, CA 91702, Tel: (800) Department of Computer Science, Why study compilers?  Typical front-end technology: Grammars e.g. human-computer interaction => HCI Regular expressions e.g. limited rules to represent unlimited expressions Parsers e.g. grasp meanings from information stream Syntax-directed e.g. guide to “speak” in right way

May 31, CS400 Compiler Construction Azusa Pacific University, Azusa, CA 91702, Tel: (800) Department of Computer Science, Why study compilers?  Technology found use outside compilers: Used in tools that find bugs in software e.g. human-computer interaction => HCI Used in tools that find security holes in existing code e.g. limited rules to represent unlimited expressions Applied to a wide range of problems e.g. in software design and software development  We learn something not just for something Competence of problem-solving Solve new problems we will encounter in the future

May 31, CS400 Compiler Construction Azusa Pacific University, Azusa, CA 91702, Tel: (800) Department of Computer Science, Why study compilers?  Application of a wide range of theoretical techniques Data Structures Theory of Computation Algorithms Computer Architecture  Good SW engineering experience  Better understanding of programming languages

May 31, CS400 Compiler Construction Azusa Pacific University, Azusa, CA 91702, Tel: (800) Department of Computer Science, Features of compilers  Correctness preserve the meaning of the code check syntactic mistakes alert potential problems  Speed of target code  Cooperation with debugger  Support for separate compilation  Good error reporting / handling

May 31, CS400 Compiler Construction Azusa Pacific University, Azusa, CA 91702, Tel: (800) Department of Computer Science, Compiler structure  Use intermediate representation why? source code target code Front EndBack End IR

May 31, CS400 Compiler Construction Azusa Pacific University, Azusa, CA 91702, Tel: (800) Department of Computer Science, Compiler structure  Front end  Recognize legal/ illegal programs  Generate IR (for further process)  The process can be automated !!!  Back end  Translate IR into target code instruction selection register allocation instruction scheduling

May 31, CS400 Compiler Construction Azusa Pacific University, Azusa, CA 91702, Tel: (800) Department of Computer Science, Compiler structure

May 31, CS400 Compiler Construction Azusa Pacific University, Azusa, CA 91702, Tel: (800) Department of Computer Science, Compiler structure  Optimization  goals improve running time of generated code improve space, power consumption, etc.  how? perform a number of transformations on the IR multiple passes  Important: preserve meaning of code what you think and what you get

May 31, CS400 Compiler Construction Azusa Pacific University, Azusa, CA 91702, Tel: (800) Department of Computer Science, The Front End  Scanning (aka lexical analysis)  recognize “words” (tokens) key words, variables etc.  Parsing (aka syntax analysis)  check syntax if - then not if - else  Semantic analysis  examine meaning (e.g. type checking) duplicate declaration

May 31, CS400 Compiler Construction Azusa Pacific University, Azusa, CA 91702, Tel: (800) Department of Computer Science, Compiler: structure and process Scanning… Parsing… Checking… IR

May 31, CS400 Compiler Construction Azusa Pacific University, Azusa, CA 91702, Tel: (800) Department of Computer Science, Compiler tool: lexical analysis Scanner   Its job :  recognize words (tokens) e.g. x = 1 becomes ID equal Int  collect identifier information e.g. ID corresponds to x and its type  Ignore white space and comments  report errors  Good news :~)  the process can be automated

May 31, CS400 Compiler Construction Azusa Pacific University, Azusa, CA 91702, Tel: (800) Department of Computer Science, Compiler tool: syntax analysis Parser   Its job :  Check & verify syntax based on rules e.g. “ID equal Int” makes up an expression coming soon: how context-free grammars specify syntax  Report errors  Build IR often a syntax tree  Good news :~)  the process can be automated

May 31, CS400 Compiler Construction Azusa Pacific University, Azusa, CA 91702, Tel: (800) Department of Computer Science, Compiler tool: semantic analysis checker   Its job :  Check the meaning of the program e.g. x = y; are x, y declared properly? e.g. x = y; is y defined before being used? e.g. x = y; are theirs types compatible?  Meaning may depend on context  Report errors (less effectively)  Report warnings (more effectively)

May 31, CS400 Compiler Construction Azusa Pacific University, Azusa, CA 91702, Tel: (800) Department of Computer Science, Compiler result: intermediate IRs   Intermediate Representations :  Graphical e.g. parse tree, DAG (directed acyclic graph)  Linear e.g. three address code (one operator): x+y*z ==> t 1 = y*z / t 2 = x+t 1  Hybrid e.g. linear for blocks of straight-line code, a graph to connect blocks  Low-level or high-level machine-dependent or machine-independent

May 31, CS400 Compiler Construction Azusa Pacific University, Azusa, CA 91702, Tel: (800) Department of Computer Science, Compiler result: intermediate IRs   Intermediate Representations :  Graphical e.g. parse tree, DAG (directed acyclic graph)  Linear e.g. three address code (one operator): x+y*z ==> t 1 = y*z / t 2 = x+t 1  Hybrid e.g. linear for blocks of straight-line code, a graph to connect blocks  Low-level or high-level machine-dependent or machine-independent

May 31, CS400 Compiler Construction Azusa Pacific University, Azusa, CA 91702, Tel: (800) Department of Computer Science, Compiler process: scanning Scanning   Lexical analysis :  Main goal: recognize words  How? by recognizing patterns e.g. an ID is a sequence of letters or digits that starts with a letter  Lexical patterns form a regular language  Regular languages are described using regular expressions (REs)  Can we create an automatic RE recognizer? Yes! (Hold that thought)

May 31, CS400 Compiler Construction Azusa Pacific University, Azusa, CA 91702, Tel: (800) Department of Computer Science, Compiler process: scanning Scanning   Definition: regular expression (over alphabet  )   is an RE denoting {  }  If , then  is an RE denoting {  }  If r and s are Res, then (r) => RE denoting L(r) r | s => RE denoting L(r)  L(s) rs => RE denoting L(r)L(s) r* => RE denoting the Kleene closure of L(r)  Property: REs are closed under many operations  This allows us to build complex REs

May 31, CS400 Compiler Construction Azusa Pacific University, Azusa, CA 91702, Tel: (800) Department of Computer Science, Compiler process: scanning Scanning   Definition: Deterministic Finite Automaton(DFA)  A 5-tuple ( , S, , s 0, F) where  is the alphabet S is he set of states  is the transition function (S  S ) s 0 is the starting state F is the set of final states (F  S)  Notation:  Use a transition diagram to describe a DFA  DFAs are equivalent to REs  Hey! We just came up with a recognizer!

May 31, CS400 Compiler Construction Azusa Pacific University, Azusa, CA 91702, Tel: (800) Department of Computer Science, Compiler process: scanning Scanning   Goal: automate the process  Idea:  Start with an RE  Build a DFA  How? We can build a non-deterministic finite automaton (Thompson’s construction) Convert that to a deterministic one (subset construction) Minimize the DFA (Hopcroft’s algorithm)  Implement it  Existing scanner generator: flex

Thank you very much! Questions? May 31, Azusa Pacific University, Azusa, CA 91702, Tel: (800) Department of Computer Science, CS400 Compiler Construction Introduction to Compiler