CHAPTER 1 INTRODUCTION TO COMPILER SUNG-DONG KIM, DEPT. OF COMPUTER ENGINEERING, HANSUNG 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

Compilers and Language Translation
Compiler Principle and Technology Prof. Dongming LU Mar. 11th, 2015.
Lecture 01 - Introduction Eran Yahav 1. 2 Who? Eran Yahav Taub 734 Tel: Monday 13:30-14:30
Greg MorrisettFall  Compilers.  (duh)  Translating one programming language into another.  Also interpreters.  Translating and running a language.
Reference Book: Modern Compiler Design by Grune, Bal, Jacobs and Langendoen Wiley 2000.
From Cooper & Torczon1 Implications Must recognize legal (and illegal) programs Must generate correct code Must manage storage of all variables (and code)
Introduction & Overview CS4533 from Cooper & Torczon.
1.3 Executing Programs. How is Computer Code Transformed into an Executable? Interpreters Compilers Hybrid systems.
Invitation to Computer Science 5th Edition
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
Chapter 10: Compilers and Language Translation Invitation to Computer Science, Java Version, Third Edition.
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.
CS 326 Programming Languages, Concepts and Implementation Instructor: Mircea Nicolescu Lecture 2.
CST320 - Lec 11 Why study compilers? n n Ties lots of things you know together: –Theory (finite automata, grammars) –Data structures –Modularization –Utilization.
Unit-1 Introduction Prepared by: Prof. Harish I Rathod
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.
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.
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.
Introduction to Compiling
Introduction CPSC 388 Ellen Walker Hiram College.
Chapter 1 Introduction Major Data Structures in Compiler
1 Compiler Construction (CS-636) Muhammad Bilal Bashir UIIT, Rawalpindi.
Planning a compiler Source Language –A subset of C Target Language –Assembler Performance Criteria –Compiler speed –Code quality –Error diagnostics –Portability.
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.
Chapter 1 Introduction. Chapter 1 -- Introduction2  Def: Compiler --  a program that translates a program written in a language like Pascal, C, PL/I,
Chapter 1: Introduction 1 Compiler Designs and Constructions Chapter 1: Introduction Objectives: Course Objectives Introduction Dr. Mohsen Chitsaz.
1 Compiler & its Phases Krishan Kumar Asstt. Prof. (CSE) BPRCE, Gohana.
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.
 Compiler “ A compiler is a computer program which translates programs written in a particular high-level programming language into executable code for.
Compiler Construction CPCS302 Dr. Manal Abdulaziz.
CSC 4181 Compiler Construction
1 Asstt. Prof Navjot Kaur Computer Dept PRESENTED BY.
CSC 8505 Compiler Construction
Presented by : A best website designer company. Chapter 1 Introduction Prof Chung. 1.
Sung-Dong Kim Dept. of Computer Engineering, Hansung University
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)
Compiler Summary Lexical analysis—scanner – String of characters  token – Finite automata. Syntactical analysis – parser – Sequence of tokens –> language.
INTERMEDIATE LANGUAGES SUNG-DONG KIM DEPT. OF COMPUTER ENGINEERING, HANSUNG UNIVERSITY.
Compiler Chapter 9. Intermediate Languages Sung-Dong Kim Dept. of Computer Engineering, Hansung University.
Chapter 1. Introduction.
Advanced Computer Systems
Compiler Design (40-414) Main Text Book:
Introduction Chapter : Introduction.
PRINCIPLES OF COMPILER DESIGN
Chapter 1 Introduction.
Introduction to Compiler Construction
Compiler Construction (CS-636)
Introduction.
Compiler Chapter 9. Intermediate Languages
Chapter 1 Introduction.
Chapter 1: Introduction to Compiling (Cont.)
Compiler Lecture 1 CS510.
CMPE 152: Compiler Design December 5 Class Meeting
Lecture 2: General Structure of a Compiler
Compilers B V Sai Aravind (11CS10008).
Subject: Language Processor
Introduction to Compiler Construction
Chapter 1 Introduction.
Chapter 10: Compilers and Language Translation
Introduction Chapter : Introduction.
Introduction to Compiler Construction
Presentation transcript:

CHAPTER 1 INTRODUCTION TO COMPILER SUNG-DONG KIM, DEPT. OF COMPUTER ENGINEERING, HANSUNG UNIVERSITY

ABSTRACT  Language Translator: compiler, interpreter  Fundamental Principles of Compilation  Compilation Processes  Compiler Structure  Good Compiler  Portability, Retargetability, Bootstrapping  Short History  Automation Tools  Compiler Theory: Grammar & Automata (2014-1) Compiler 2

1. LANGUAGE TRANSLATOR  Source code/program  Target/object code/program  Language translator Compiler Interpreter Preprocessor Assembler Cross compiler … Language Translator Source Target (2014-1) Compiler 3

1.1 COMPILER  A compiler is a computer program which translates programs written in a particular high-level programming language into executable code for a specific target computer. (2014-1) Compiler 4

1.2 INTERPRETER  Input: executable specification  Output: result of executing the specification (2014-1) Compiler 5 Source Programs Interpreter Results

1.3 HYBRID METHOD  Compile + interpretation  Java (2014-1) Compiler 6 Compiler source code bytecode JVM JIT compiler results native code MACHINE

2. FUNDAMENTAL PRINCIPLES OF COMPILATION  The compiler must preserve the meaning of the program being compiled  The compiler must improve the input program in some discernible way (2014-1) Compiler 7

3. COMPILATION PROCESS (1)  Compiler components (2014-1) Compiler 8

3. COMPILATION PROCESS (2)  Front-end Lexical analysis: token Syntactic analysis(parsing): parse tree Semantic analysis: intermediate code  Back-end Code optimization Target code generation (2014-1) Compiler 9 Source language Target language

4. COMPILER STRUCTURE (2014-1) Compiler 10

어휘 분석 고급 언어 프로그램 기계어 또는 어셈블리어 프로그램 구문 분석 의미 분석 중간 코드 생성 코드 최적화 목적 코드 생성 심벌 테이블 오류 처리 (2014-1) Compiler 11

(2014-1) Compiler 12

(2014-1) Compiler 13

4.1 LEXICAL ANALYSIS  Lexical analyzer(scanner) (2014-1) Compiler 14 ex) if ( a > 10 )... Token : if ( a > 10 )... Token Number :

4.2 SYNTAX ANALYSIS (1)  Syntax analysis, parsing  Syntax analyzer, parser  Function Syntax checking Tree generation (2014-1) Compiler 15

4.2 SYNTAX ANALYSIS (2) (2014-1) Compiler 16 ex) if (a > 10) a = 1; if > = a 10 a 1

4.3 SEMANTIC ANALYSIS  Intermediate code generation  Semantic checking  if (a>10) a = 1.0; when a is integer, semantic error (2014-1) Compiler 17

4.4 CODE OPTIMIZATION (1)  Optional phase  Local optimization Constant folding Eliminating redundant load, store instructions Algebraic simplification Strength reduction (2014-1) Compiler 18

4.4 CODE OPTIMIZATION (2)  Global optimization Flow analysis technique Common sub-expression Moving loop invariants Removing unreachable codes (2014-1) Compiler 19

4.5 TARGET CODE GENERATION  Instruction selection & generation  Instruction scheduling  Register management/allocation  Storage allocation (2014-1) Compiler 20

5. GOOD COMPILER  Correct code generation  Ability of handling of programs of arbitrary size  Compilation speed  Compiler size  User-friendliness: quality of error reporting (2014-1) Compiler 21

6. OTHER ISSUES (1)  Portability The ease with which the compiler itself can be made to run on another machine  Retargetability The ease with which it can be made to generate code for another machine Replace/create back-end (2014-1) Compiler 22

6.1 BOOTSTRAPPING (1)  What language is used to write compiler itself? Implementation (host) language = machine language How the first compilers were written?  Simple case (2014-1) Compiler 23 MACHINE M1 Existing Compiler for language B Compiler for language A Written in language B Running compiler for language A

6.1 BOOTSTRAPPING (2)  More complicated case  T-diagram (2014-1) Compiler 24 MACHINE M1MACHINE M2 Cross compiler Existing Compiler for language B Compiler for language A Written in language B Running compiler for language A ST H

6.1 BOOTSTRAPPING (3)  Combination 1 (2014-1) Compiler 25 ABACBC HHH MACHINE H

6.1 BOOTSTRAPPING (4)  Combination 2 (2014-1) Compiler 26 AABB HH M KK MACHINE H MACHINE M MACHINE K

6.1 BOOTSTRAPPING (5)  Scenario 1 (2014-1) Compiler 27 MACHINE H Existing Compiler for language B Compiler for language A Written in language B Running compiler for language A AAHH BB H HH

6.1 BOOTSTRAPPING (6)  Scenario 2: cross compiler (2014-1) Compiler 28 MACHINE KMACHINE H Existing Compiler for language B Compiler for language A Written in language B Running compiler for language A A A H H BB K K K

6.1 BOOTSTRAPPING (7)  Bootstrapping process “quick and dirty” compiler in assembly language Inefficient and correct code generation Compile “good” compiler by using the “quick and dirty” compiler (2014-1) Compiler 29 AAHH AA H HH Compiler written in its own language A “quick and dirty” compiler written in machine language Running but inefficient compiler

6.1 BOOTSTRAPPING (8) Recompile  final version (2014-1) Compiler 30 AAHH AA H HH Compiler written in its own language A Running but inefficient compiler Final version of the compiler

6.1 BOOTSTRAPPING (9) Advantages Improvement to the source code of the compiler  working compiler Easy porting Porting a compiler written in its own source language (step 1) (2014-1) Compiler 31 AK AA H H AK H Compiler source code retargeted to K Original compiler Cross compiler

6.1 BOOTSTRAPPING (10) Porting a compiler written in its own source language (step 2) (2014-1) Compiler 32 AAKK AA H KK Compiler source code retargeted to K Cross compiler Retargeted compiler

7. SHORT HISTORY  : code generation  : parsing  1975-present: code generation and code optimization Reliability, efficiency, pleasant user interface How to compiler  what to compile (2014-1) Compiler 33

8. AUTOMATION TOOLS  Compiler compiler: compiler generator (2014-1) Compiler 34

8.1 LEXICAL ANALYZER GENERATOR  Ex: LEX (2014-1) Compiler 35

8.2 PARSER GENERATOR  Ex: YACC (2014-1) Compiler 36

(2014-1) Compiler 37

8.3 CODE GENERATION AUTOMATION (2014-1) Compiler 38

9. COMPILER THEORY: GRAMMAR & AUTOMATA (1)  Grammar Noam Chomsky classification Type 3: Regular Grammar (RG) Type 2: Context-Free Grammar (CFG) Type 1: Context-Sensitive Grammar (CSG) Type 0: Unrestricted Grammar (UG) (2014-1) Compiler 39

9. COMPILER THEORY: GRAMMAR & AUTOMATA (2)  RG ⊂ CFG ⊂ CSG ⊂ UG 무제한 문법 문맥 자유 문법 정규 문법 문맥 의존 문법 (2014-1) Compiler 40

9. COMPILER THEORY: GRAMMAR & AUTOMATA (3)  Regular language  Context-free language  Context-sensitive language  Recursively Enumerable Set (2014-1) Compiler 41

9. COMPILER THEORY: GRAMMAR & AUTOMATA (4)  Finite Automata: NFA, DFA  Pushdown Automata  Linear Bounded Automata  Turing Machine (2014-1) Compiler 42

10. OTHERS  Symbol table  Literal table  Error message (2014-1) Compiler 43