CH1.1 CSE244 Chapter 1: Introduction to Compiling Prof. Steven A. Demurjian, Sr. Computer Science & Engineering Department The University of Connecticut.

Slides:



Advertisements
Similar presentations
Introduction to Compiler Construction
Advertisements

CPSC Compiler Tutorial 9 Review of Compiler.
Yu-Chen Kuo1 Chapter 1 Introduction to Compiling.
Chapter 1: Introduction to Compiling
Reference Book: Modern Compiler Design by Grune, Bal, Jacobs and Langendoen Wiley 2000.
Compiler Chang Chi-Chung Textbook Compilers: Principles, Techniques, and Tools, 2/E.  Alfred V. Aho, Columbia University  Monica S. Lam,
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.
Lecture 2 Phases of Compiler. Preprocessors, Compilers, Assemblers, and Linkers Preprocessor Compiler Assembler Linker Skeletal Source Program Source.
Invitation to Computer Science 5th Edition
September 7, September 7, 2015September 7, 2015September 7, 2015 Azusa, CA Sheldon X. Liang Ph. D. Computer Science at Azusa Pacific University.
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.
Chapter 10: Compilers and Language Translation Invitation to Computer Science, Java Version, Third Edition.
Introduction to Compiler Construction Robert van Engelen COP5621 Compiler Construction Copyright Robert.
CSC 338: Compiler design and implementation
CST320 - Lec 11 Why study compilers? n n Ties lots of things you know together: –Theory (finite automata, grammars) –Data structures –Modularization –Utilization.
RIT 08/11/47Chapter 11 Chapter 1: Introduction to Compiling Dr. Winai Wichaipanitch Rajamangala Institute of Technology Klong 6 Thanyaburi Pathumthani.
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
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.
Compilers: Overview/1 1 Compiler Structures Objective – –what are the main features (structures) in a compiler? , Semester 1,
國立台灣大學 資訊工程學系 薛智文 98 Spring Compiler TH 234, DTH 103.
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.
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.
1 Asstt. Prof Navjot Kaur Computer Dept PRESENTED BY.
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.
Objective of the course Understanding the fundamentals of the compilation technique Assist you in writing you own compiler (or any part of compiler)
Compilers Design Chapter1 : Introduction, Structure of a Compiler
Advanced Computer Systems
Compiler Design (40-414) Main Text Book:
PRINCIPLES OF COMPILER DESIGN
Chapter 1 Introduction.
Introduction to Compiler Construction
Compiler Construction (CS-636)
Chapter 1 Introduction.
Chapter 1: Introduction to Compiling (Cont.)
Compiler Lecture 1 CS510.
Compiler Construction
CS416 Compiler Design lec00-outline September 19, 2018
Introduction to Compiler Construction
Introduction CI612 Compiler Design CI612 Compiler Design.
Compiler 薛智文 TH 6 7 8, DTH Spring.
Compiler 薛智文 TH 6 7 8, DTH Spring.
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.
Compiler 薛智文 M 2 3 4, DTH Spring.
Introduction to Compiler Construction
Presentation transcript:

CH1.1 CSE244 Chapter 1: Introduction to Compiling Prof. Steven A. Demurjian, Sr. Computer Science & Engineering Department The University of Connecticut 191 Auditorium Road, Box U-155 Storrs, CT (860) Dr. Robert LaBarre United Technologies Research Center 411 Silver Lane E. Hartford, CT

CH1.2 CSE244 Introduction to Compilers  As a Discipline, Involves Multiple CSE Areas  Programming Languages and Algorithms  Software Engineering & Theory / Foundations  Computer Architecture & Operating Systems  But, Has Surprisingly Simplistic Intent: Compiler Source program Target Program Error messages Diverse & Varied

CH1.3 CSE244 Classifications of Compilers  Compilers Viewed from Many Perspectives  However, All utilize same basic tasks to accomplish their actions Single Pass Multiple Pass Load & Go Construction Debugging Optimizing Functional

CH1.4 CSE244 Classifications of Compilers  Also, Broadly Categorized as:  We Will Discuss Each Category in This Class Analysis: Synthesis: Decompose Source into an intermediate representation Target program generation from representation

CH1.5 CSE244 Important Notes  In Today’s Technology, Analysis Is Often Performed by Software Tools - This Wasn’t the Case in Early CSE Days  Structure / Syntax directed editors: Force “syntactically” correct code to be entered  Pretty Printers: Standardized version for program structure (i.e., blank space, indenting, etc.)  Static Checkers: A “quick” compilation to detect rudimentary errors  Interpreters: “real” time execution of code a “line-at-a-time”

CH1.6 CSE244 Important Notes  Compilation Is Not Limited to Programming Language Applications  Text Formatters  LATEX & TROFF Are Languages Whose Commands Format Text  Silicon Compilers  Textual / Graphical: Take Input and Generate Circuit Design  Database Query Processors  Database Query Languages Are Also a Programming Language  Input Is“compiled” Into a Set of Operations for Accessing the Database

CH1.7 CSE244 The Many Phases of a Compiler Source Program Lexical Analyzer 1 Syntax Analyzer 2 Semantic Analyzer 3 Intermediate Code Generator 4 Code Optimizer 5 Code Generator 6 Target Program Symbol-table Manager Error Handler 1, 2, 3 : Analysis - Our Focus 4, 5, 6 : Synthesis

CH1.8 CSE244  Three Phases:  Linear / Lexical Analysis:  L-to-r Scan to Identify Tokens  Hierarchical Analysis:  Grouping of Tokens Into Meaningful Collection  Semantic Analysis:  Checking to Insure Correctness of Components The Analysis Task For Compilation

CH1.9 CSE244 Phase 1. Lexical Analysis Easiest Analysis - Identify tokens which are building blocks For Example: All are tokens Blanks, Line breaks, etc. are scanned out Position := initial + rate * 60 ; _______ __ _____ _ ___ _ __ _

CH1.10 CSE244 Phase 2. Hierarchical Analysis aka Parsing or Syntax Analysis For previous example, we would have Parse Tree: identifier expression identifier expression number expression assignment statement position := + * 60 initial rate Nodes of tree are constructed using a grammar for the language

CH1.11 CSE244 What is a Grammar?  Grammar is a Set of Rules Which Govern the Interdependencies & Structure Among the Tokens statementis anassignment statement, or while statement, or if statement, or... assignment statement expression is an identifier := expression ; (expression), or expression + expression, or expression * expression, or number, or identifier, or...

CH1.12 CSE244 Why Have We Divided Analysis in This Manner?  Lexical Analysis - Scans Input & Its Linear Actions Are Not Recursive  Identify Only Individual “words” that are the the Tokens of the Language  Recursion Is Required to Identify Structure of an Expression, As Indicated in Parse Tree  Verify that the “words” are Correctly Assembled into “sentences”  What is Third Phase?  Determine Whether the Sentences have One and Only One Unambiguous Interpretation  “John Took Picture of Mary Out on the Patio”

CH1.13 CSE244 Phase 3. Semantic Analysis  Find More Complicated Semantic Errors and Support Code Generation  Parse Tree Is Augmented With Semantic Actions position initial rate := + * 60 Compressed Tree position initial rate := + * inttoreal 60 Conversion Action

CH1.14 CSE244 Phase 3. Semantic Analysis  Most Important Activity in This Phase:  Type Checking - Legality of Operands  Many Different Situations: Real := int + char ; A[int] := A[real] + int ; while char <> int do …. Etc.

CH1.15 CSE244 Analysis in Text Formatting Simple Commands : LATEX \begin{single} \end{single} \noindent \section{Introduction} $A_i$ $A_{i_j}$ Embedded in a stream of text, i.e., a FILE \ and $ serve as signals to LATEX begin single noindent section Language Commands What are tokens? What is hierarchical structure? What kind of semantic analysis is required?

CH1.16 CSE244 Supporting Phases/ Activities for Analysis  Symbol Table Creation / Maintenance  Contains Info on Each “Meaningful” Token, Typically Identifiers  Data Structure Created / Initialized During Lexical Analysis  Utilized / Updated During Later Analysis & Synthesis  Error Handling  Detection of Different Errors Which Correspond to All Phases  What Kinds of Errors Are Found During the Analysis Phase?  What Happens When an Error Is Found?

CH1.17 CSE244 The Many Phases of a Compiler Source Program Lexical Analyzer 1 Syntax Analyzer 2 Semantic Analyzer 3 Intermediate Code Generator 4 Code Optimizer 5 Code Generator 6 Target Program Symbol-table Manager Error Handler 1, 2, 3 : Analysis - Our Focus 4, 5, 6 : Synthesis

CH1.18 CSE244 The Synthesis Task For Compilation  Intermediate Code Generation  Abstract Machine Version of Code - Independent of Architecture  Easy to Produce and Do Final, Machine Dependent Code Generation  Code Optimization  Find More Efficient Ways to Execute Code  Replace Code With More Optimal Statements  2-approaches: High-level Language & “Peephole” Optimization  Final Code Generation  Generate Relocatable Machine Dependent Code

CH1.19 CSE244 Reviewing the Entire Process ErrorsErrors position := initial + rate * 60 lexical analyzer syntax analyzer semantic analyzer intermediate code generator id1 := id2 + id3 * 60 := id1 id2l id3 + * 60 := id1 id2l id3 + * inttoreal 60 Symbol Table position.... initial …. rate….

CH1.20 CSE244 Reviewing the Entire Process ErrorsErrors intermediate code generator code optimizer final code generator temp1 := inttoreal(60) temp2 := id3 * temp1 temp3 := id2 + temp2 id1 := temp3 temp1 := id3 * 60.0 id1 := id2 + temp1 mov f id3, r2 mulf #60.0, r2 movf id2, r1 addf r2, r2 movf r1, id1 position.... initial …. rate…. Symbol Table

CH1.21 CSE244 Compiler Cousins: Preprocessors Compiler Cousins: Preprocessors Provide Input to Compilers 1. Macro Processing #define in C: does text substitution before compiling #define X 3 #define Y A*B+C #define Z getchar()

CH1.22 CSE File Inclusion #include in C - bring in another file before compiling defs.h ////// main.c #include “defs.h” …---…---…--- ////// …---…---…---

CH1.23 CSE Rational Preprocessors  Augment “Old” Languages With Modern Constructs  Add Macros for If - Then, While, Etc.  #Define Can Make C Code More Pascal-like #define begin { #define end } #define then

CH1.24 CSE Language Extensions for a Database System EQUEL - Database query language embedded in C ## Retrieve (DN=Department.Dnum) where ## Department.Dname = ‘Research’ is Preprocessed into: ingres_system(“Retr…..Research’”,____,____); a procedure call in a programming language.

CH1.25 CSE244 The Grouping of Phases Front End : Analysis + Intermediate Code Generation Back End : Code Generation + Optimization vs. Number of Passes: Single - Preferred Multiple - Easier, but less efficient Tradeoffs ……..

CH1.26 CSE244 Compiler Construction Tools Parser Generators : Produce Syntax Analyzers Scanner Generators : Produce Lexical Analyzers Syntax-directed Translation Engines : Generate Intermediate Code Automatic Code Generators : Generate Actual Code Data-Flow Engines : Support Optimization