Chapter 1 Introduction.

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
CPSC Compiler Tutorial 9 Review of Compiler.
Compilers Book: Crafting a Compiler with C
Reference Book: Modern Compiler Design by Grune, Bal, Jacobs and Langendoen Wiley 2000.
BİL744 Derleyici Gerçekleştirimi (Compiler Design)1.
1.3 Executing Programs. How is Computer Code Transformed into an Executable? Interpreters Compilers Hybrid systems.
September 7, September 7, 2015September 7, 2015September 7, 2015 Azusa, CA Sheldon X. Liang Ph. D. Computer Science at Azusa Pacific University.
Course Revision Contents  Compilers  Compilers Vs Interpreters  Structure of Compiler  Compilation Phases  Compiler Construction Tools  A Simple.
COP4020 Programming Languages
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.
Introduction to Compiler Construction Robert van Engelen COP5621 Compiler Construction Copyright Robert.
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.
CST320 - Lec 11 Why study compilers? n n Ties lots of things you know together: –Theory (finite automata, grammars) –Data structures –Modularization –Utilization.
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 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.
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.
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.
The Model of Compilation Natawut Nupairoj, Ph.D. Department of Computer Engineering Chulalongkorn University.
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.
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,
1 Crafting a Compiler with C Chapter 1 Introduction Teacher : Dr. Lawrence Y. Deng contact: Grading: Attendance 10%, Midterm exam.
Chapter 1 Introduction Samuel College of Computer Science & Technology Harbin Engineering University.
CHAPTER 1 INTRODUCTION TO COMPILER SUNG-DONG KIM, DEPT. OF COMPUTER ENGINEERING, HANSUNG UNIVERSITY.
Chapter 1. Introduction.
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
Advanced Computer Systems
Compiler Design (40-414) Main Text Book:
Introduction Chapter : Introduction.
COMP 433 – Theory of Compilers (Level – 10)
PRINCIPLES OF COMPILER DESIGN
CS510 Compiler Lecture 1.
Introduction to Compiler Construction
CS 3304 Comparative Languages
Compiler Construction (CS-636)
Introduction.
SOFTWARE DESIGN AND ARCHITECTURE
Chapter 1 Introduction.
课程名 编译原理 Compiling Techniques
Chapter 1: Introduction to Compiling (Cont.)
Compiler Lecture 1 CS510.
CS416 Compiler Design lec00-outline September 19, 2018
Introduction to Compiler Construction
Introduction CI612 Compiler Design CI612 Compiler Design.
Compiler Construction
CPSC 388 – Compiler Design and Construction
Compiler 薛智文 TH 6 7 8, DTH Spring.
COP4020 Programming Languages
Compiler 薛智文 TH 6 7 8, DTH Spring.
Subject: Language Processor
CS416 Compiler Design lec00-outline February 23, 2019
Introduction to Compiler Construction
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
Chapter 10: Compilers and Language Translation
Lec00-outline May 18, 2019 Compiler Design CS416 Compiler Design.
Introduction Chapter : Introduction.
Compiler 薛智文 M 2 3 4, DTH Spring.
Introduction to Compiler Construction
Review for the Midterm. Overview (Chapter 1):
Presentation transcript:

Chapter 1 Introduction

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 Programming Languages 1.5 Compiler Design and Programming Language Design 1.7 Computer Architecture and Compiler Design 1.8 Compiler Design Considerations

Overview and History (1) Cause Software for early computers was written in assembly language The benefits of reusing software on different CPUs started to become significantly greater than the cost of writing a compiler The first real compiler FORTRAN compilers of the late 1950s 18 person-years to build

Overview and History (2) Compiler technology is more broadly applicable and has been employed in rather unexpected areas. Text-formatting languages, like nroff and troff; preprocessor packages like eqn, tbl, pic Silicon compiler for the creation of VLSI circuits Command languages of OS Query languages of Database systems

What Do Compilers Do (1) A compiler acts as a translator, transforming human-oriented programming languages into computer-oriented machine languages. Ignore machine-dependent details for programmer Programming Language (Source) Machine Language (Target) Compiler

What Do Compilers Do (2) Compilers may generate three types of code: Pure Machine Code Machine instruction set without assuming the existence of any operating system or library. Mostly being OS or embedded applications. Augmented Machine Code Code with OS routines and runtime support routines. More often Virtual Machine Code Virtual instructions, can be run on any architecture with a virtual machine interpreter or a just-in-time compiler Ex. Java

What Do Compilers Do (3) Another way that compilers differ from one another is in the format of the target machine code they generate: Assembly or other source format Relocatable binary Relative address A linkage step is required Absolute binary Absolute address Can be executed directly

The Structure of a Compiler (1) Any compiler must perform two major tasks Analysis of the source program Synthesis of a machine-language program Compiler Analysis Synthesis

The Structure of a Compiler (2) Source Program Tokens Syntactic Scanner Parser Semantic Routines Structure (Character Stream) Intermediate Representation Optimizer Symbol and Attribute Tables (Used by all Phases of The Compiler) Code Generator Target machine code

The Structure of a Compiler (3) Source Program Tokens Syntactic Scanner Parser Semantic Routines Structure (Character Stream) Intermediate Representation Scanner The scanner begins the analysis of the source program by reading the input, character by character, and grouping characters into individual words and symbols (tokens) RE ( Regular expression ) NFA ( Non-deterministic Finite Automata ) DFA ( Deterministic Finite Automata ) LEX Optimizer Symbol and Attribute Tables (Used by all Phases of The Compiler) Code Generator Target machine code

The Structure of a Compiler (4) Source Program Tokens Syntactic Scanner Parser Semantic Routines Structure (Character Stream) Intermediate Representation Parser Given a formal syntax specification (typically as a context-free grammar [CFG] ), the parse reads tokens and groups them into units as specified by the productions of the CFG being used. As syntactic structure is recognized, the parser either calls corresponding semantic routines directly or builds a syntax tree. CFG ( Context-Free Grammar ) BNF ( Backus-Naur Form ) GAA ( Grammar Analysis Algorithms ) LL, LR, SLR, LALR Parsers YACC Optimizer Symbol and Attribute Tables (Used by all Phases of The Compiler) Code Generator Target machine code

The Structure of a Compiler (5) Source Program Tokens Syntactic Scanner Parser Semantic Routines Structure (Character Stream) Intermediate Representation Semantic Routines Perform two functions Check the static semantics of each construct Do the actual translation The heart of a compiler Syntax Directed Translation Semantic Processing Techniques IR (Intermediate Representation) Optimizer Symbol and Attribute Tables (Used by all Phases of The Compiler) Code Generator Target machine code

The Structure of a Compiler (6) Source Program Tokens Syntactic Scanner Parser Semantic Routines Structure (Character Stream) Intermediate Representation Optimizer The IR code generated by the semantic routines is analyzed and transformed into functionally equivalent but improved IR code This phase can be very complex and slow Peephole optimization loop optimization, register allocation, code scheduling Register and Temporary Management Peephole Optimization Optimizer Symbol and Attribute Tables (Used by all Phases of The Compiler) Code Generator Target machine code

The Structure of a Compiler (7) Source Program Tokens Syntactic Scanner Parser Semantic Routines Structure (Character Stream) Intermediate Representation Code Generator Interpretive Code Generation Generating Code from Tree/Dag Grammar-Based Code Generator Optimizer Code Generator Target machine code

The Structure of a Compiler (8) Code Generator [Intermediate Code Generator] Non-optimized Intermediate Code Scanner [Lexical Analyzer] Tokens Code Optimizer Parser [Syntax Analyzer] Optimized Intermediate Code Parse tree Code Optimizer Semantic Process [Semantic analyzer] Target machine code Abstract Syntax Tree w/ Attributes

The Structure of a Compiler (9) Compiler writing tools Compiler generators or compiler- compilers E.g. scanner and parser generators Examples : Yacc, Lex

The Syntax and Semantics of Programming Language (1) A programming language must include the specification of syntax (structure) and semantics (meaning). Syntax typically means the context-free syntax because of the almost universal use of context-free-grammar (CFGs) Ex. a = b + c is syntactically legal b + c = a is illegal

The Syntax and Semantics of Programming Language (2) The semantics of a programming language are commonly divided into two classes: Static semantics Semantics rules that can be checked at compiled time. Ex. The type and number of a function’s arguments Runtime semantics Semantics rules that can be checked only at run time

Compiler Design and Programming Language Design (1) An interesting aspect is how programming language design and compiler design influence one another. Programming languages that are easy to compile have many advantages

Compiler Design and Programming Language Design(2) Languages such as Snobol and APL are usually considered noncompilable What attributes must be found in a programming language to allow compilation? Can the scope and binding of each identifier reference be determined before execution begins? Can the type of object be determined before execution begins? Can existing program text be changed or added to during execution?

Computer Architecture and Compiler Design Compilers should exploit the hardware- specific feature and computing capability to optimize code. The problems encountered in modern computing platforms: Instruction sets for some popular architectures are highly nonuniform. High-level programming language operations are not always easy to support. Ex. exceptions, threads, dynamic heap access … Exploiting architectural features such as cache, distributed processors and memory Effective use of a large number of processors

Compiler Design Considerations Debugging Compilers Designed to aid in the development and debugging of programs. Optimizing Compilers Designed to produce efficient target code Retargetable Compilers A compiler whose target architecture can be changed without its machine-independent components having to be rewritten.