Chapter 1 Introduction Chapter 1 Introduction The Goal



































- Slides: 35

Chapter 1 Introduction Chapter 1 - Introduction

The Goal of Chapter 1 Introduce different forms of language translators Give a high level overview of the structure of a typical compiler Discuss trends in programming languages and machine architecture that are shaping compilers. Chapter 1 - Introduction 2

What is a Compiler? Def: Compiler -– a program that translates a program written in a language like Pascal, C, PL/I, FORTRAN, or COBOL into another language. An important role of the compiler is to report any errors that it detects. Chapter 1 - Introduction 3

What is an Interpreter? Def: Interpreter -– Instead of producing a target program at translation, it appears to directly execute the operations specified in the source program on the inputs specified by the user. Chapter 1 - Introduction 4

What are the Differences? Compiler is usually much faster. Interpreter usually gives better diagnostics. Chapter 1 - Introduction 5

2. Structure of a Compiler So far we have viewed the compiler as a single black box. Chapter 1 - Introduction 6

2. Structure of a Compiler Now we want to open that box. Chapter 1 - Introduction 7

Chapter 1 - Introduction 8

2. Structure of a Compiler 1. The Lexical Analyzer reads the 2. 3. stream of characters and groups them into meaningful sequences called lexemes. The Syntax Analyzer depicts the grammatical structure of the lexemes in a syntax tree The Semantic Analyzer checks the tree for semantic consistency (type checking) Chapter 1 - Introduction 9

2. Structure of a Compiler 4. Intermediate Code Generation – produces assembly like instructions (three address code) 5. Code Optimization – seeks to improve intermediate code so better target code can be generated 6. Code Generation – takes the intermediate code and maps to the target code. Chapter 1 - Introduction 10

2. Structure of a Compiler 7. Symbol Table Management - An essential function of the compiler is to record the variable names used in the source program and collect attributes of each name. (type, scope, …) Chapter 1 - Introduction 11

2. 8 The Grouping of the Phases into Passes Pass – several phases may be grouped together into a pass that reads an input file and writes an output file. – Front End Lexical Analysis, Syntax Analysis, Semantic Analysis, and Intermediate Code Generation – Code Optimization Might be an optional pass. – Back End Code Generation for a specific target machine. Chapter 1 - Introduction 12

2. 9 Compiler-Construction Tools The compiler writer, like any software developer, can profitably use modern software development environments containing tools – Editor, debugger, version managers, profilers, test harnesses, … There also tools to help implement various phases of a compiler. – Scanner Generator, Parser generator, … Chapter 1 - Introduction 13

Chapter 1 - Introduction 14

3. The Evolution of Programming Languages Chapter 1 - Introduction 15

3. 1 The Move to Higher-Level Languages Chapter 1 - Introduction 16

3. 2 Impacts on Compilers Chapter 1 - Introduction 17

4. The Science of Building a Compiler Chapter 1 - Introduction 18

4. 1 Modeling in Compiler Design and Implementation Chapter 1 - Introduction 19

4. 2 The Science of Code Optimization Chapter 1 - Introduction 20

5. Applications of Compiler Technology Chapter 1 - Introduction 21

5. 1 Implementation of High Level Programming Languages Chapter 1 - Introduction 22

5. 2 Optimizations for Computer Architectures Chapter 1 - Introduction 23

5. 3 Design of New Computer Architectures Chapter 1 - Introduction 24

5. 4 Program Translations Chapter 1 - Introduction 25

5. 5 Software Productivity Tools Chapter 1 - Introduction 26

6. Programming Language Basics Chapter 1 - Introduction 27

6. 1 The Static/Dynamic Distinction Chapter 1 - Introduction 28

6. 2 Environments and States Chapter 1 - Introduction 29

6. 3 Static Scope and. Block Structure Chapter 1 - Introduction 30

6. 4 Explicit Access Control Chapter 1 - Introduction 31

6. 5 Dynamic Scope Chapter 1 - Introduction 32

6. 6 Parameter Passing Mechanisms Chapter 1 - Introduction 33

6. 7 Aliasing Chapter 1 - Introduction 34

7. Summary Chapter 1 - Introduction 35