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.

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

Introduction to Compiler Construction
CS 31003: Compilers Introduction to Phases of Compiler.
Welcome to CS 445 Compiler and Translator Design Clinton Jeffery JEB 230.
Yu-Chen Kuo1 Chapter 1 Introduction to Compiling.
Chapter 1: Introduction to Compiling
Compiler Chang Chi-Chung Textbook Compilers: Principles, Techniques, and Tools, 2/E.  Alfred V. Aho, Columbia University  Monica S. Lam,
Compiler Construction1 A Compulsory Module for Students in Computer Science Department Faculty of IT / Al – Al Bayt University First Semester 2009/2010.
1.3 Executing Programs. How is Computer Code Transformed into an Executable? Interpreters Compilers Hybrid systems.
Lecture 2 Phases of Compiler. Preprocessors, Compilers, Assemblers, and Linkers Preprocessor Compiler Assembler Linker Skeletal Source Program Source.
September 7, September 7, 2015September 7, 2015September 7, 2015 Azusa, CA Sheldon X. Liang Ph. D. Computer Science at Azusa Pacific University.
410/510 1 of 20 Week 1 – Lecture 1 Introduction The Textbook Assessment Programming & Tools A v. small compiler Compiler Construction.
COP4020 Programming Languages
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.
Parser-Driven Games Tool programming © Allan C. Milne Abertay University v
Introduction to Compiler Construction Robert van Engelen COP5621 Compiler Construction Copyright Robert.
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.
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 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.
Introduction Lecture 1 Wed, Jan 12, The Stages of Compilation Lexical analysis. Syntactic analysis. Semantic analysis. Intermediate code generation.
Introduction to Compilers. Related Area Programming languages Machine architecture Language theory Algorithms Data structures Operating systems Software.
Topic #1: Introduction EE 456 – Compiling Techniques Prof. Carl Sable Fall 2003.
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.
Compilers: Overview/1 1 Compiler Structures Objective – –what are the main features (structures) in a compiler? , Semester 1,
. 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 Compiling
Chapter 1 Introduction Major Data Structures in Compiler
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.
Chapter 1: Introduction 1 Compiler Designs and Constructions Chapter 1: Introduction Objectives: Course Objectives Introduction Dr. Mohsen Chitsaz.
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.
CH1.1 CSE244 Chapter 1: Introduction to Compiling Prof. Steven A. Demurjian, Sr. Computer Science & Engineering Department The University of Connecticut.
Compiler Construction CPCS302 Dr. Manal Abdulaziz.
CSC 4181 Compiler Construction
©SoftMoore ConsultingSlide 1 Structure of Compilers.
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.
Presented by : A best website designer company. Chapter 1 Introduction Prof Chung. 1.
Prologue Sung-Dong Kim, Dept. of Computer Engineering, Hansung University.
Objective of the course Understanding the fundamentals of the compilation technique Assist you in writing you own compiler (or any part of compiler)
Chapter 1. Introduction.
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
Advanced Computer Systems
Compiler Design (40-414) Main Text Book:
PRINCIPLES OF COMPILER DESIGN
Chapter 1 Introduction.
Introduction to Compiler Construction
Introduction.
Chapter 1 Introduction.
课程名 编译原理 Compiling Techniques
Chapter 1: Introduction to Compiling (Cont.)
Compiler Lecture 1 CS510.
Compiler Construction
Introduction to Compiler Construction
Compilers B V Sai Aravind (11CS10008).
Introduction to Compiler Construction
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
Compiler Structures 1. Overview Objective
Introduction to Compiler Construction
Presentation transcript:

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 (target language). –Traditionally, the source language is a high level language and the target language is a low level language (machine code). compiler Source program Target program Error message

Why do we need to learn how a compiler works? –It is very unlikely for anyone to write another C/C++/java compiler. –But … Parsing a small language occurs quite often: scripts languages such as python, parsing a set of commands for a mail server, etc. For systems people, the compiler knowledge is the basic requirement. –A new processor is fast because it runs code generated by a compiler fast. –If you implement a new operating system, you need to know how compiler interacts with the OS. An OS is fast because it runs code generated by a compiler fast. –New architectures keep coming: new compiler optimizations are always needed.

Knowledge required to write a good compiler: –Formal language (lexical analysis and parsing) –Programming language (activation record, scope, type checking, etc) –Algorithm (optimization, register allocation, etc) –Graph theory (optimization, data flow analysis) –Computer architecture (target language, machine dependent optimizations) –Software engineering (large amount of code)

Source program with macros Preprocessor Source program Compiler Target assembly program assembler Relocatable machine code Loader/link-editor Absolute machine code Try gcc with –v, -E, -S flags On linprog. A typical compilation process

Compiler Phases: Source program Lexical analyzer Syntax analyzer Semantic analyzer Intermediate code generator Code optimizer Code generator Symbol table manager Error handler Front End Backend

Compiler phases: –source program is a stream of characters: pos = init+rate*60 –lexical analysis: groups characters into non-separatable units, called token, and generates token stream: Id1 = id2 + id3 * const the information about the identifiers must be stored somewhere (symbol table). –Syntax analysis: checks whether the token stream meets the grammatical specification of the language and generates the syntax tree. –Semantic analysis: checks whether the program has a meaning (e.g. if pos is a record and init and rate are integers then the assignment does not make sense). = Id1+ id2* id360

Compiler phases: –intermediate code generation, intermediate code is something that is both close to the final machine code and easy to manipulate (for optimization). One example is the three-address code: dst = op1 op op2 The three-address code for the assignment statement: temp1 = 60; temp2 = id3 + temp1; temp3 = id2 + temp2; id1 = temp3 –Code optimization: produces better/semantically equivalent code. temp1 = id3 * 60.0 id1 = id2 + temp1 –code generator: generates assembly MOVF id3, R2 MULF #60.0, R2 MOVF id2, R1 ADDF R2, R1 MOVF R1, id1

The use of intermediate code can also reduce the complexity of compilers: –m front ends and n backends share a common intermediate code. 1 2 m IC 1 2 n Front Ends Backends

Compiler construction tools: –scanner generator (lex) –parser generator (yacc) –syntax-directed translation engines –automatic code generators –data-flow engines