The Model of Compilation Natawut Nupairoj, Ph.D. Department of Computer Engineering Chulalongkorn University.

Slides:



Advertisements
Similar presentations
CPSC Compiler Tutorial 9 Review of Compiler.
Advertisements

Yu-Chen Kuo1 Chapter 1 Introduction to Compiling.
1 Semantic Processing. 2 Contents Introduction Introduction A Simple Compiler A Simple Compiler Scanning – Theory and Practice Scanning – Theory and Practice.
Chapter 1: Introduction to Compiling
Compiler Construction1 A Compulsory Module for Students in Computer Science Department Faculty of IT / Al – Al Bayt University First Semester 2009/2010.
Lecture 2 Phases of Compiler. Preprocessors, Compilers, Assemblers, and Linkers Preprocessor Compiler Assembler Linker Skeletal Source Program Source.
2.2 A Simple Syntax-Directed Translator Syntax-Directed Translation 2.4 Parsing 2.5 A Translator for Simple Expressions 2.6 Lexical Analysis.
Course Revision Contents  Compilers  Compilers Vs Interpreters  Structure of Compiler  Compilation Phases  Compiler Construction Tools  A Simple.
Lexical Analysis Natawut Nupairoj, Ph.D.
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
CSC 338: Compiler design and implementation
Compiler Construction1 COMP Compiler Construction Lecturer: Dr. Arthur Cater Teaching Assistant:
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.
Introduction to Language Processing Technology Natawut Nupairoj, Ph.D. Department of Computer Engineering Chulalongkorn University.
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.
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.
Chapter 1 Introduction Study Goals: Master: the phases of a compiler Understand: what is a compiler Know: interpreter,compiler structure.
. 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.
Compiler Construction By: Muhammad Nadeem Edited By: M. Bilal Qureshi.
1 Compiler & its Phases Krishan Kumar Asstt. Prof. (CSE) BPRCE, Gohana.
1 A Simple Syntax-Directed Translator CS308 Compiler Theory.
 Fall Chart 2  Translators and Compilers  Textbook o Programming Language Processors in Java, Authors: David A. Watts & Deryck F. Brown, 2000,
C H A P T E R T W O Linking Syntax And Semantics Programming Languages – Principles and Paradigms by Allen Tucker, Robert Noonan.
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.
Dr. Mohamed Ramadan Saady 314ALL CH1.1 Chapter 1: Introduction to Compiling.
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.
©SoftMoore ConsultingSlide 1 Structure of Compilers.
1 Asstt. Prof Navjot Kaur Computer Dept PRESENTED BY.
CS 404Ahmed Ezzat 1 CS 404 Introduction to Compiler Design Lecture 1 Ahmed Ezzat.
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,
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 Samuel College of Computer Science & Technology Harbin Engineering University.
Compiler Design (40-414) Main Text Book:
PRINCIPLES OF COMPILER DESIGN
Chapter 1 Introduction.
Introduction to Compiler Construction
A Simple Syntax-Directed Translator
Compiler Construction (CS-636)
Chapter 1 Introduction.
课程名 编译原理 Compiling Techniques
Chapter 1: Introduction to Compiling (Cont.)
Compiler Lecture 1 CS510.
Introduction CI612 Compiler Design CI612 Compiler Design.
Compilers B V Sai Aravind (11CS10008).
CMPE 152: Compiler Design August 21/23 Lab
Subject: Language Processor
Lec00-outline May 18, 2019 Compiler Design CS416 Compiler Design.
Presentation transcript:

The Model of Compilation Natawut Nupairoj, Ph.D. Department of Computer Engineering Chulalongkorn University

Outline Overview. Front-End  Lexical Analysis.  Syntactic Analysis.  Semantic Analysis. Back-End  Code Generation.  Code Optimization.

Overview Translate a “source” program (in language S) into an “equivalent” “object” program (in language O). Translator source program (S) object program (O) error messages

The Model of Compilation Reduce Complexity Source/Target Independent  Plug-able Compiler IR: contain sufficient information  tree-like structure the “syntax tree” or  Assembly-like format “three-address code”. Analysis (Front-End) Synthesis (Back-End) Intermediate Representation sourceobject

Front-End Lexical Analysis  group the input stream into tokens Syntactic Analysis  see if the source is “valid” or “correct” Contextual/Semantic Analysis  make sure the program is “meaningful” or semantically correct.

Front-End Components Scanner Source program (text stream) Parser Intermediate Representation (file or in memory) Semantic Analyzer Front-End Construct parse tree. Group token. next-token token Symbol Table main(){ Check semantic/contextual. identifier main symbol ( parse-tree

Lexical Analysis Scanner. Group the input stream into tokens  identifiers.  numbers.  keywords.  symbols & signs. Lexeme: Character sequence forming a token. Eliminate all blanks and comments.

position := initial + rate * 60 Example: Tokens identifier position 2. assignment symbol := 3. identifier initial 4. plus symbol + 5. identifier rate 6. muliplication symbol * 7. integer-literal 60

Syntax Analysis Parser. Check if the source is “grammatically” correct. Construct a parse tree.

Mini-Triangle Syntax single-Command ::=V-name := Expression |Identifier ( Expression ) |if Expression then single-Command else single-Command |while Expression do single-Command |let Declaration in single-Command |begin Command end

Mini-Triangle Syntax Expression::=primary-Expression |Expression Operator primary-Expression primary-Expression ::=Integer-Literal |V-name |Operator primary-Expression |( Expression ) V-name::=Identifier... Operator::=+ | - | * | / | | = | \

Example: Parse Tree

Semantic Analysis Make sure that the program is “meaningful”. Walk the parse tree to check  Type checking.  Type conversion. Example: rate * 60  rate is a real variable rate * inttoreal(60) Generate IR (can also done by parser).

Example of IR Abstract Syntax Tree (AST) position := initial + rate * 60 interior node = operation children = arguments leaves = identifiers or constants := position+ initial* rate60

Example of IR Three-Address Code tmp := rate * 60 tmp := initial + tmp position := tmp position := initial + rate * 60

Back-End Code Optimization  improve IR: machine-independent.  improve object code: machine-depedent.  optimizing compiler.  widely-used. Code Generation  generate object code.  assign memory/register locations.  instruction selection.

Front-End Components IR Optimizer Intermediate Representation (file or in memory) Code Generator Object code (assembly or binary) Peephole Optimizer Back-End Generate object code. Machine-independent optimization. IR Symbol Table Machine-dependent optimization Object code

Other Phases Symbol-Table Management  information about identifier being-used. name type scope  Scanner creates an entry into the table. Error Handler  what to do when found errors in the source.

Compiler-Construction Tools Parser generators.  Generate a parser from a CFG.  Yacc, Bison. Scanner generators.  Generate a scanner from regular expressions.  Lex, Flex.