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

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?
Regular Expressions Finite State Automaton. Programming Languages2 Regular expressions  Terminology on Formal languages: –alphabet : a finite set of.
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.
From Cooper & Torczon1 Implications Must recognize legal (and illegal) programs Must generate correct code Must manage storage of all variables (and code)
Compiler Construction
Introduction & Overview CS4533 from Cooper & Torczon.
Scanner Front End The purpose of the front end is to deal with the input language Perform a membership test: code  source language? Is the.
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.
어휘분석 (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.
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.
Lexical Analysis I Specifying Tokens Lecture 2 CS 4318/5531 Spring 2010 Apan Qasem Texas State University *some slides adopted from Cooper and Torczon.
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,
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.
Review: Compiler Phases: Source program Lexical analyzer Syntax analyzer Semantic analyzer Intermediate code generator Code optimizer Code generator Symbol.
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.
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.
CS 404Ahmed Ezzat 1 CS 404 Introduction to Compiler Design Lecture 1 Ahmed Ezzat.
1 Compiler Construction Vana Doufexi office CS dept.
CS416 Compiler Design1. 2 Course Information Instructor : Dr. Ilyas Cicekli –Office: EA504, –Phone: , – Course Web.
Topic 3: Automata Theory 1. OutlineOutline Finite state machine, Regular expressions, DFA, NDFA, and their equivalence, Grammars and Chomsky hierarchy.
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
CS 3304 Comparative Languages
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
Lexical and Syntax Analysis
CS 326 Programming Languages, Concepts and Implementation
Finite-State Machines (FSMs)
Chapter 1 Introduction.
Finite-State Machines (FSMs)
课程名 编译原理 Compiling Techniques
Compiler Lecture 1 CS510.
CS 536 / Fall 2017 Introduction to programming languages and compilers
Recognizer for a Language
CS416 Compiler Design lec00-outline September 19, 2018
Course supervisor: Lubna Siddiqui
Introduction CI612 Compiler Design CI612 Compiler Design.
CPSC 388 – Compiler Design and Construction
Lexical Analysis - An Introduction
Lexical Analysis — Part II: Constructing a Scanner from Regular Expressions Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved.
Review: Compiler Phases:
Lecture 5: Lexical Analysis III: The final bits
CSE401 Introduction to Compiler Construction
Lexical Analysis — Part II: Constructing a Scanner from Regular Expressions Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved.
R.Rajkumar Asst.Professor CSE
Lecture 4: Lexical Analysis II: From REs to DFAs
CS 3304 Comparative Languages
CS 3304 Comparative Languages
Subject: Language Processor
CS416 Compiler Design lec00-outline February 23, 2019
Lexical Analysis - An Introduction
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
Lec00-outline May 18, 2019 Compiler Design CS416 Compiler Design.
Lecture 5 Scanning.
CSc 453 Lexical Analysis (Scanning)
Compiler design Review COMP 442/6421 – Compiler Design
Presentation transcript:

Compiler Construction Lawate p m

Administrative info Instructor Teaching Assistant Name: Vana Doufexi E-mail: vdoufexi@cs.northwestern.edu Office: Ford Building, #2-229 Hours: E-mail to set up appointment Teaching Assistant TBA

Administrative info Course webpage Newsgroup http://www.cs.northwestern.edu/academics/courses/322 contains: news staff information lecture notes & other handouts homeworks & manuals policies, grades newsgroup info useful links Newsgroup Name: cs.322 nntp: news.cs.northwestern.edu

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 COOL to MIPS code How was the first compiler created?

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

Features of compilers Correctness Speed of target code preserve the meaning of the code Speed of target code Speed of compilation Good error reporting/handling Cooperation with the debugger Support for separate compilation

Compiler structure Front End Back End IR source code target code Use intermediate representation Why?

Compiler Structure Front end Back end Recognize legal/illegal programs report/handle errors Generate IR The process can be automated Back end Translate IR into target code instruction selection register allocation instruction scheduling lots of NPC problems -- use approximations

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

The Front End Scanning (a.k.a. lexical analysis) recognize "words" (tokens) Parsing (a.k.a. syntax analysis) check syntax Semantic analysis examine meaning (e.g. type checking) Other issues: symbol table (to keep track of identifiers) error detection/reporting/recovery

The Scanner Its job: Good news given a character stream, recognize words (tokens) e.g. x = 1 becomes IDENTIFIER EQUAL INTEGER collect identifier information e.g. IDENTIFIER corresponds to a lexeme (the actual word x) and its type (acquired from the declaration of x). ignore white space and comments report errors Good news the process can be automated

The Parser Its job: Good news Check and verify syntax based on specified syntax rules e.g. IDENTIFIER LPAREN RPAREN make 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

Semantic analysis Its job: Check the meaning of the program e.g. In x=y, is y defined before being used? Are x and y declared? e.g. In x=y, are the types of x and y such that you can assign one to the other? Meaning may depend on context Report errors

IRs Graphical Linear Hybrid Low-level or high-level e.g. parse tree, DAG Linear e.g. three-address code Hybrid e.g. linear for blocks of straight-line code, a graph to connect blocks Low-level or high-level

The scanning process Main goal: recognize words How? by recognizing patterns e.g. an identifier 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)

The scanning process Definition: Regular expressions (over alphabet )  is an RE denoting {} If , then  is an RE denoting {} If r and s are REs, then (r) is an RE denoting L(r) r|s is an RE denoting L(r)L(s) rs is an RE denoting L(r)L(s) r* is an RE denoting the Kleene closure of L(r) Property: REs are closed under many operations This allows us to build complex REs.

The scanning process Definition: Deterministic Finite Automaton a five-tuple (, S, , s0, F) where  is the alphabet S is the set of states  is the transition function (SS) s0 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!

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 construction) Convert that to a deterministic one (Subset construction) Minimize the DFA (Hopcroft's algorithm) Implement it Existing scanner generator: flex