Compiler Construction Tools Libby Rasnick Christopher Newport University CPSC 560 Spring 2003.

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
Software & Services Group, Developer Products Division Copyright© 2010, Intel Corporation. All rights reserved. *Other brands and names are the property.
Compilers and Language Translation
Cpeg421-08S/final-review1 Course Review Tom St. John.
BİL744 Derleyici Gerçekleştirimi (Compiler Design)1.
UMBC Introduction to Compilers CMSC 431 Shon Vick 01/28/02.
Lecture 2 Phases of Compiler. Preprocessors, Compilers, Assemblers, and Linkers Preprocessor Compiler Assembler Linker Skeletal Source Program Source.
Invitation to Computer Science 5th Edition
2.2 A Simple Syntax-Directed Translator Syntax-Directed Translation 2.4 Parsing 2.5 A Translator for Simple Expressions 2.6 Lexical Analysis.
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.
CISC 471 First Exam Review Game Questions. Overview 1 Draw the standard phases of a compiler for compiling a high level language to machine code, showing.
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.
Lesson 10 CDT301 – Compiler Theory, Spring 2011 Teacher: Linus Källberg.
Joey Paquet, Lecture 12 Review. Joey Paquet, Course Review Compiler architecture –Lexical analysis, syntactic analysis, semantic.
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
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.
1 Compiler Design (40-414)  Main Text Book: Compilers: Principles, Techniques & Tools, 2 nd ed., Aho, Lam, Sethi, and Ullman, 2007  Evaluation:  Midterm.
. 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
Introduction CPSC 388 Ellen Walker Hiram College.
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.
Intermediate Code Representations
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.
1 CS308 Compiler Theory. 2 Course Information Instructor : –Prof. Minyi Guo –Yao Shen Course.
Compiler Construction CPCS302 Dr. Manal Abdulaziz.
CSC 4181 Compiler Construction
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.
Overview of Compilation Prepared by Manuel E. Bermúdez, Ph.D. Associate Professor University of Florida Programming Language Principles Lecture 2.
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,
CC410: System Programming Dr. Manal Helal – Fall 2014 – Lecture 12–Compilers.
Lecture 9 Symbol Table and Attributed Grammars
Compiler principles Compiler Jakub Yaghob.
Compiler Design (40-414) Main Text Book:
PRINCIPLES OF COMPILER DESIGN
Chapter 1 Introduction.
CS510 Compiler Lecture 1.
Introduction to Compiler Construction
Constructing Precedence Table
Introduction.
Compiler Construction
Chapter 1 Introduction.
PROGRAMMING LANGUAGES
Compiler Lecture 1 CS510.
CS416 Compiler Design lec00-outline September 19, 2018
Introduction to Compiler Construction
Course supervisor: Lubna Siddiqui
Compiler Design 4. Language Grammars
Lexical and Syntax Analysis
Lecture 2: General Structure of a Compiler
Introduction CI612 Compiler Design CI612 Compiler Design.
Subject: Language Processor
CS416 Compiler Design lec00-outline February 23, 2019
Introduction to Compiler Construction
Chapter 10: Compilers and Language Translation
Lec00-outline May 18, 2019 Compiler Design CS416 Compiler Design.
Introduction to Compiler Construction
Compiler Design 3. Lexical Analyzer, Flex
Compiler design Review COMP 442/6421 – Compiler Design
Presentation transcript:

Compiler Construction Tools Libby Rasnick Christopher Newport University CPSC 560 Spring 2003

Contents Defining Compiler Construction Tools (aka CCTs) Defining Compiler Construction Tools (aka CCTs) Uses for CCTs Uses for CCTs CCTs in the Compiler Structure CCTs in the Compiler Structure Lexical Analyzer Lexical Analyzer Syntax Analyzer Syntax Analyzer Semantic Analyzer Semantic Analyzer Intermediate Code Generator Intermediate Code Generator Code Optimizer Code Optimizer Code Generator Code Generator Compiler Construction Kit - Cocktail Compiler Construction Kit - Cocktail References References

Defining CCTs programs or environments that assist in the creation of an entire compiler or its parts programs or environments that assist in the creation of an entire compiler or its parts

Uses for CCTs generate lexical analyzers, generate lexical analyzers, syntax analyzers, syntax analyzers, semantic analyzers, semantic analyzers, intermediate code, intermediate code, optimized target code optimized target code

CCTs in the Compiler Structure

Lexical Analyzer scanner generators scanner generators input: source program input: source program output: lexical analyzer output: lexical analyzer task of reading characters from source program and recognizing tokens or basic syntactic components [3] task of reading characters from source program and recognizing tokens or basic syntactic components [3] maintains a list of reserved words maintains a list of reserved words

Lexical Analyzer Flex (fast lexical analyzer generator) Flex (fast lexical analyzer generator) Example which specifies a scanner which replaces the string username with the users login name Example which specifies a scanner which replaces the string username with the users login name % % username printf(%s, getlogin()); username printf(%s, getlogin());

Syntax Analyzer parser generators parser generators input: context-free grammar input: context-free grammar output: syntax analyzer output: syntax analyzer the task of the syntax analyzer is to produce a representation of the source program in a form directly representing its syntax structure. This representation is usually in the form of a binary tree or similar data structure [3] the task of the syntax analyzer is to produce a representation of the source program in a form directly representing its syntax structure. This representation is usually in the form of a binary tree or similar data structure [3]

Syntax Analyzer Bison (Yacc-compatible parser gen.) [5] Bison (Yacc-compatible parser gen.) [5] a general purpose parser generator that converts grammar description for an LALR(1) CFG into a C program a general purpose parser generator that converts grammar description for an LALR(1) CFG into a C program Bison grammar example (reverse polish notation) Bison grammar example (reverse polish notation) %{ %{ #define YYSTYPE double #define YYSTYPE double #include #include %} %} %token NUM %token NUM % /* grammar rules and actions below */ % /* grammar rules and actions below */

Semantic Analyzer syntax-directed translators syntax-directed translators input: parse tree input: parse tree output: routines to generate I-code output: routines to generate I-code The role of the semantic analyzer is to derive methods by which the stuctures constructed by the syntax analyzer may be evaluate or executed. [3] The role of the semantic analyzer is to derive methods by which the stuctures constructed by the syntax analyzer may be evaluate or executed. [3] type checker type checker two common tactics: two common tactics: ~ flatten the semantic analyzers parse tree ~ flatten the semantic analyzers parse tree ~ embed semantic analyzer w/in syntax analyzer ~ embed semantic analyzer w/in syntax analyzer (syntax-driven translation) (syntax-driven translation)

Intermediate Code Generator Automatic code generators Automatic code generators input: I-code rules input: I-code rules output: crude target machine program output: crude target machine program The task of the code generator is to traverse this tree, producing functionally equivalent object code. [3] The task of the code generator is to traverse this tree, producing functionally equivalent object code. [3] three address code is one type three address code is one type

Intermediate Code Generator Example 7 + (8 * y) / 2 Example 7 + (8 * y) / 2 a := 8 b := y c := a * b a := c b := 2 c := a / b a := 7 b := c c := a + b expr 7+ / 2 () 8 * y

Code Optimizer Data flow engines Data flow engines input: I-code input: I-code output: transformed code output: transformed code This improvement is achieved by program transformations that are traditionally called optimizations, although the term optimization is a misnomer because there is rarely a guarantee that the resulting code is the best possible. [1] This improvement is achieved by program transformations that are traditionally called optimizations, although the term optimization is a misnomer because there is rarely a guarantee that the resulting code is the best possible. [1]

Code Optimizer Peephole Optimization Peephole Optimization machine or assembly code is used along with knowledge of target machines instruction set to replace I-code instructions with shorter or more quickly executed instructions - this is repeated as much as is necessary [3]

Code Optimizer Common Optimizing Transformations [2] Common Optimizing Transformations [2] Optim. NameRequired AnalysisTransformation Optim. NameRequired AnalysisTransformation constant foldingsimulated exec.elimination constant foldingsimulated exec.elimination dead code elim.simulated exec.elimination dead code elim.simulated exec.elimination loop unrollingloop struct., stat.smotion (replic.) loop unrollingloop struct., stat.smotion (replic.) linearizing arraysloop structureelimination linearizing arraysloop structureelimination load/store optim.DFAmotion load/store optim.DFAmotion branch chainingstatisticsselection (dec) branch chainingstatisticsselection (dec) math identitiesnoneselection, elimination math identitiesnoneselection, elimination common subexp.simulated exec.elimination common subexp.simulated exec.elimination

Code Optimizer Example 7 + (8 * y) / 2 Example 7 + (8 * y) / 2 a := y a := a * 8 a := a / 2 a := + 7 expr 7+ / 2 () 8 * y

Code Generator Automatic code generators Automatic code generators input: optimized (transformed) I-code input: optimized (transformed) I-code output: target machine program output: target machine program Example 7 + (8 * y) / 2 Example 7 + (8 * y) / 2 Load a, y Load a, y Mult a, 8 Mult a, 8 Div a, 2 Div a, 2 Add a, 7 Add a, 7

Compiler Construction Tool Kits tool kits contain all (or almost all) phases of a compiler tool kits contain all (or almost all) phases of a compiler Example: Cocktail [7] Example: Cocktail [7] Developed until 1993 at Karlsruhe research lab, the German National Research Center for Information Technology.

Compiler Construction Tool Kits Components: Components: Rex (Regular EXpression tool) Rex (Regular EXpression tool) - scanner generator - scanner generator Lalr - an LALR(1) parser generator accepting grammars in extended BNF Lalr - an LALR(1) parser generator accepting grammars in extended BNF Ell - an LL(1) parser generator accepting same grammars as Lalr, but must obey LL(1) property Ell - an LL(1) parser generator accepting same grammars as Lalr, but must obey LL(1) property Ast - generator for abstract syntax trees Ast - generator for abstract syntax trees Ag - attribute evaluator generator Ag - attribute evaluator generator Puma - transformation tool based on pattern matching Puma - transformation tool based on pattern matching

References 1 1 Aho, Alfred V., Sethi, Ravi and Ullman, Jeffrey D. Compilers: principles, techniques, and tools. (1986). Reading: Addison-Wesley. 2 2 Peters, James, Pittman, Thomas. The art of compiler design: theory and practice. (1992). Englewood Cliffs: Prentice Hall. 3 Watson, Des. High-level languages and their compilers. (1989). Wokingham: Addison- Wesley.

References ilercontructiontools ilercontructiontools 4 Heng, Christopher. (2003). Free Compiler Construction Tools. ilercontructiontools (01 March 2003). ilercontructiontools The Lex & Yacc Page. (01 March 2003) Compiler Construction Kits. (01 March 2003) The Cocktail Compiler Toolbox. (01 March 2003).