SlideShare a Scribd company logo
Chapter 1. Introduction
Compiler
Dr. Mohammed Khader
ASU
1
2
Outline
• 1.1 History of Compilation
• 1.2 What Compilers Do
• 1.3 Interpreters
• 1.4 Syntax and Semantics
• 1.5 Organization of a Compiler
3
Language Processors
• Act as Translators
– Transforming human-oriented programming
languages into computer-oriented machine
languages
4
Overview and History
• Compilers are fundamental to modern
computing.
• They act as translators, transforming
human-oriented programming languages
into computer-oriented machine languages.
Programming
Language
(Source)
Compiler
Machine
Language
(Target)
5
Overview and History (Cont’d.)
• The first real compiler
– FORTRAN compilers of the late 1950s
• Today, we can build a simple compiler in
a few month.
• Creating an efficient and reliable compiler
is still challenging.
6
Overview and History (Cont’d.)
• Compiler technology is largely applicable
and has been employed in rather
unexpected areas.
– Text-formatting languages, like LaTeX
– Silicon compiler for the creation of VLSI circuits
– Command languages of OS
– Query languages of Database systems
7
8
Front-end and Back-end
• Front-end performs the analysis of the
source language code to build the internal
representation, called
intermediate representation (IR).
• Back-end performs the target language
synthesis to generate the target code
(assembly code).
1.2 What Compilers Do
• Compilers may be distinguished in two
ways:
1. By the kind of machine code they generate
2. By the format of the target code they generate
9
10
Machine Code Generated by
Compilers(kind of Machine code)
 Pure machine code
– Compiler may generate code for a particular
machine’s instruction set without assuming the
existence of any operating system or library
routines.
– Pure machine code is used in compilers for
system implementation languages, which are
for implementing operating systems or
embedded applications.
11
Machine Code Generated by
Compilers (Cont.)
 Augmented machine code
– Compilers generate code for a machine
architecture that is augmented with:
1) operating system routines and
2) runtime language support routines.
12
Machine Code Generated by
Compilers (Cont.)
 Virtual machine code
– Compilers generate virtual machine code that is
composed entirely of virtual machine instructions.
– That code can run on any architecture for which a VM
interpreter is available.
• For example, the VM for Java, Java virtual machine (JVM), has a
JVM interpreter.
– Portability is achieved by writing just one virtual
machine (VM) interpreter for all the target architectures.
1.2.2 Target Code Formats
Another way that compilers differ from one another is in the
format of the target code they generate as follows:
1. Assembly Language (Source) Format
• Advantages:
– Simplifies translation:
• A number of code generation decisions (e.g. how to compute
addresses) can be left for the assembler.
– Cross-compilation:
• The compiler executes on one computer but generates code that
executes on another.
• Symbolic form is produced that is easily transferred between different
computers.
– Support experimental programming language designs
• Makes it easier to check the correctness of a compiler, since its output
can be observed.
• Disadvantage:
– Need an additional pass (Assembler)
13
1.2.2 Target Code Formats
2. Relocatable binary
– External references, local instruction addresses, and data addresses
are not yet bound.
– Addresses are assigned relative either to the beginning of the
module or to symbolically named locations.
• Advantages:
– More efficient and more control over the translation process: because
it eliminates one step of calculating absolute addresses.
– Allow modular compilation: breaking up of a large program into
separately compiled pieces.
– Allow cross-language references: calls of assembler routines or
subprograms in other high-level languages
– Support subroutine libraries for example, I/O, storage allocation,
and math routines
• Disadvantage:
– A linkage step is required to support libraries and to produce
absolute binary format that is executable. 14
1.2.2 Target Code Formats
3. Absolute binary
• Advantages:
– Program can be directly executed when the compiler is finished
– No need for intermediate step of linking.
– Faster: allows a program to be prepared and executed in a single
step.
– Guarantee the use of only the most current library routines
– Good for debugging (frequent changes)
• Disadvantages:
– Limited ability to interface with other code
– The program must be recompiled for each execution
15
16
1.3 Interpreters
Compiler vs. Interpreter
Compiler has compilation and execution phases:
1) The compilation phase generates target
program from source program.
2) The execution phase executes the target
program.
(Fig. 1.1).
Interpreter directly interprets (executes) the source
program that reads inputs and writes outputs
(Fig. 1.3).
17
Compiler versus Interpreter (Cont.)
1.4 Syntax and Semantics
• Syntax: structure
– E.g. context-free grammars (CFGs)
•a=b+c is legal,
•b+c=a is not legal
• Semantics: meaning
– E.g. a = b + c
•is illegal if any of the variables are
undeclared or if b or c is of type Boolean
– Static semantics
– Runtime semantics
18
Static Semantics
• A set of rules that specify which
syntactically legal programs are actually
valid
– E.g.: Identifier declaration, type-compatibility
of operators and operands, proper number of
parameters in procedure calls
• Can be specified either formally or
informally
– E.g.: attribute grammars
19
An Example of Attribute
Grammars
• Production rule:
– E  E+T
• Augmented production rule:
– Eresult  Ev1 + Tv2
•if v1.type = numeric and v2.type = numeric
then result.type  numeric
else call ERROR( )
20
Runtime Semantics
•Runtime, or execution, semantics are
used to specify what a program
computes.
A. Informal These semantics are often specified
very informally in a language manual or report;
B. Formal approaches to defining the runtime
semantics of programming languages.
21
The Structure of a Compiler
• Modern compilers are syntax-directed
– Compilation is driven by the syntactic
structure of programs;
– i.e., actions are associated with the structures.
22
Tasks performed by compilers
Analysis of the source program such as
scanning and parsing.
•Syntax analysis
•Semantic analysis
Synthesis of a target program such as code
generation, that when executed, will
correctly perform the computations
described by the source program.
23
1.5 Organization of a Compiler
(Used by all Phases
of The Compiler)
24
Front-end vs. Back-end
25
The Scanner
• The scanner begins the analysis of the source
program by reading the input text (character
by character) and grouping individual
characters into tokens such as :
– Identifiers
– Integers
– Reserved words
– Delimiters
• It eliminate unneeded information like comments
• It process compiler control directives.
• It enters preliminary information into symbol table.
26
The Parser
• Reading tokens and grouping them into phrases
according to the syntax specification such as
context free grammar CFG
• It usually builds an Abstract Syntax Tree (AST)
as a concise representation of program structure
– (Chap. 2 & 7)
27
The Type Checker
(Semantic Analysis)
• Checking the static semantics of each AST
node
– the type checker decorates the AST node by
adding type information to it
– It checks type correctness, reachability and
termination, and exception handling.
– Otherwise, a suitable error message is issued
28
Translator (Program Synthesis)
• Translating AST nodes into Intermediate
Representation code (IR) (such as byte code
in Java) that correctly implements the
meaning of the program
• In simple, nonoptimizing compilers, the
translator may generate target code
directly
29
The Optimizer
• Optimizer improves IR code’s performance.
• Analyzing and transforming the IR code
generated by the translator into functionally
equivalent but improved code
– Complex
• Optimization can also be done after code
generation
30
The Code Generator
• Mapping the IR code generated by the translator
into target machine code (assembly code)
– Machine-dependent, complex
• Register allocation
• Code scheduling
• Automatic construction of code generators has
been actively studied
– Matching a low-level IR to target-instruction
templates
– gcc has machine description files for more than ten
popular computer.
31
328
Organization of a Compiler (Cont.)
Symbol Tables
Scannerr Parser Type Checker
Translator
Optimizer
Code
Generator
Source
Program
Tokens AST
Decorated
AST
Intermediate
Representation
Intermediate
Representation
Target Code
Revised Figure 1.4: A syntax-directed compiler. AST denotes the Abstract
Syntax Tree.
Symbol Tables
• A mechanism that allows information to
be associated with identifiers and shared
among compiler phases
– Identifier declaration
– Identifier use
– Type checking
33
The Structure of a Compiler
34
Scanner
[Lexical Analyzer]
Parser
[Syntax Analyzer]
Semantic Process
[Semantic analyzer]
Code Generator
[Intermediate Code Generator]
Code Optimizer
Tokens
Parse tree
Abstract Syntax Tree w/ Attributes
Non-optimized Intermediate Code
Optimized Intermediate Code
Code Generator
Target machine code
Phases of a Compiler
[Aho, Lam, Sethi, Ullman]
Syntax Analyzer
character stream
target machine code
Lexical Analyzer
Intermediate Code Generator
Code Generator
token stream
syntax tree
intermediate representation
Symbol
Table
Semantic Analyzer
syntax tree
Machine-Independent
Code Optimization
Machine-Dependent
Code Optimization
(optional)
(optional)
35
Compiler Writing Tools
• Compiler generators (compiler compilers)
– Scanner generator
– Parser generator
– Symbol table manager
– Attribute grammar evaluator
– Code-generation tools
• Much of the effort in crafting a compiler lies in
writing and debugging the semantic phases
– Usually hand-coded
36
Compiler-writing tools
Regular expressions
Scanner generators
Lex (The input to lex consists of a definition of
each token as a regular expression )
Parser generators:
Yacc
Code generator generators
http://catalog.compilertools.net/
 37

More Related Content

Similar to Chap01-Intro.ppt

Compiler Design Basics
Compiler Design BasicsCompiler Design Basics
Compiler Design Basics
Akhil Kaushik
 
Week 08_Basics of Compiler Construction.pdf
Week 08_Basics of Compiler Construction.pdfWeek 08_Basics of Compiler Construction.pdf
Week 08_Basics of Compiler Construction.pdf
AnonymousQ3EMYoWNS
 
Compiler Construction Lecture One .pptx
Compiler Construction Lecture One  .pptxCompiler Construction Lecture One  .pptx
Compiler Construction Lecture One .pptx
انشال عارف
 
Pros and cons of c as a compiler language
  Pros and cons of c as a compiler language  Pros and cons of c as a compiler language
Pros and cons of c as a compiler language
Ashok Raj
 
Introduction to compiler
Introduction to compilerIntroduction to compiler
Introduction to compiler
Abha Damani
 
Introduction to Compilers
Introduction to CompilersIntroduction to Compilers
Introduction to Compilers
Akhil Kaushik
 
Compiler Construction
Compiler ConstructionCompiler Construction
Introduction to Compiler Construction
Introduction to Compiler Construction Introduction to Compiler Construction
Introduction to Compiler Construction
Sarmad Ali
 
Ch 1.pptx
Ch 1.pptxCh 1.pptx
Ch 1.pptx
woldu2
 
Phases of Compiler
Phases of CompilerPhases of Compiler
Phases of Compiler
Tanzeela_Hussain
 
Ss ui lecture 1
Ss ui lecture 1Ss ui lecture 1
Ss ui lecture 1
Avinash Kapse
 
SS UI Lecture 1
SS UI Lecture 1SS UI Lecture 1
SS UI Lecture 1
Avinash Kapse
 
COMPILER DESIGN PPTS.pptx
COMPILER DESIGN PPTS.pptxCOMPILER DESIGN PPTS.pptx
COMPILER DESIGN PPTS.pptx
MUSHAMHARIKIRAN6737
 
Compiler an overview
Compiler  an overviewCompiler  an overview
Compiler an overview
amudha arul
 
Compiler Design Introduction
Compiler Design IntroductionCompiler Design Introduction
Compiler Design Introduction
Kuppusamy P
 
System Programing Unit 1
System Programing Unit 1System Programing Unit 1
System Programing Unit 1
Manoj Patil
 
Phases of compiler
Phases of compilerPhases of compiler
Phases of compiler
Akhil Kaushik
 
Mba i-ifm-u-2-computer software
Mba i-ifm-u-2-computer softwareMba i-ifm-u-2-computer software
Mba i-ifm-u-2-computer software
Rai University
 
Compiler type
Compiler typeCompiler type
Compiler type
Amrish rajput
 
System software module 1 presentation file
System software module 1 presentation fileSystem software module 1 presentation file
System software module 1 presentation file
jithujithin657
 

Similar to Chap01-Intro.ppt (20)

Compiler Design Basics
Compiler Design BasicsCompiler Design Basics
Compiler Design Basics
 
Week 08_Basics of Compiler Construction.pdf
Week 08_Basics of Compiler Construction.pdfWeek 08_Basics of Compiler Construction.pdf
Week 08_Basics of Compiler Construction.pdf
 
Compiler Construction Lecture One .pptx
Compiler Construction Lecture One  .pptxCompiler Construction Lecture One  .pptx
Compiler Construction Lecture One .pptx
 
Pros and cons of c as a compiler language
  Pros and cons of c as a compiler language  Pros and cons of c as a compiler language
Pros and cons of c as a compiler language
 
Introduction to compiler
Introduction to compilerIntroduction to compiler
Introduction to compiler
 
Introduction to Compilers
Introduction to CompilersIntroduction to Compilers
Introduction to Compilers
 
Compiler Construction
Compiler ConstructionCompiler Construction
Compiler Construction
 
Introduction to Compiler Construction
Introduction to Compiler Construction Introduction to Compiler Construction
Introduction to Compiler Construction
 
Ch 1.pptx
Ch 1.pptxCh 1.pptx
Ch 1.pptx
 
Phases of Compiler
Phases of CompilerPhases of Compiler
Phases of Compiler
 
Ss ui lecture 1
Ss ui lecture 1Ss ui lecture 1
Ss ui lecture 1
 
SS UI Lecture 1
SS UI Lecture 1SS UI Lecture 1
SS UI Lecture 1
 
COMPILER DESIGN PPTS.pptx
COMPILER DESIGN PPTS.pptxCOMPILER DESIGN PPTS.pptx
COMPILER DESIGN PPTS.pptx
 
Compiler an overview
Compiler  an overviewCompiler  an overview
Compiler an overview
 
Compiler Design Introduction
Compiler Design IntroductionCompiler Design Introduction
Compiler Design Introduction
 
System Programing Unit 1
System Programing Unit 1System Programing Unit 1
System Programing Unit 1
 
Phases of compiler
Phases of compilerPhases of compiler
Phases of compiler
 
Mba i-ifm-u-2-computer software
Mba i-ifm-u-2-computer softwareMba i-ifm-u-2-computer software
Mba i-ifm-u-2-computer software
 
Compiler type
Compiler typeCompiler type
Compiler type
 
System software module 1 presentation file
System software module 1 presentation fileSystem software module 1 presentation file
System software module 1 presentation file
 

Recently uploaded

Fundamentals of Programming and Language Processors
Fundamentals of Programming and Language ProcessorsFundamentals of Programming and Language Processors
Fundamentals of Programming and Language Processors
Rakesh Kumar R
 
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of CodeA Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
Aftab Hussain
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
NYGGS Automation Suite
 
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling ExtensionsUI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
Peter Muessig
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
Aftab Hussain
 
SWEBOK and Education at FUSE Okinawa 2024
SWEBOK and Education at FUSE Okinawa 2024SWEBOK and Education at FUSE Okinawa 2024
SWEBOK and Education at FUSE Okinawa 2024
Hironori Washizaki
 
GreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-JurisicGreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-Jurisic
Green Software Development
 
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
Łukasz Chruściel
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
Fermin Galan
 
Mobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona InfotechMobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona Infotech
Drona Infotech
 
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdfAutomated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
timtebeek1
 
Oracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptxOracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptx
Remote DBA Services
 
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Crescat
 
Empowering Growth with Best Software Development Company in Noida - Deuglo
Empowering Growth with Best Software  Development Company in Noida - DeugloEmpowering Growth with Best Software  Development Company in Noida - Deuglo
Empowering Growth with Best Software Development Company in Noida - Deuglo
Deuglo Infosystem Pvt Ltd
 
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI AppAI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
Google
 
GraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph TechnologyGraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph Technology
Neo4j
 
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Łukasz Chruściel
 
Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...
Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...
Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...
kalichargn70th171
 
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
Alina Yurenko
 
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissancesAtelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Neo4j
 

Recently uploaded (20)

Fundamentals of Programming and Language Processors
Fundamentals of Programming and Language ProcessorsFundamentals of Programming and Language Processors
Fundamentals of Programming and Language Processors
 
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of CodeA Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
 
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling ExtensionsUI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
 
SWEBOK and Education at FUSE Okinawa 2024
SWEBOK and Education at FUSE Okinawa 2024SWEBOK and Education at FUSE Okinawa 2024
SWEBOK and Education at FUSE Okinawa 2024
 
GreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-JurisicGreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-Jurisic
 
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
 
Mobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona InfotechMobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona Infotech
 
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdfAutomated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
 
Oracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptxOracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptx
 
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
 
Empowering Growth with Best Software Development Company in Noida - Deuglo
Empowering Growth with Best Software  Development Company in Noida - DeugloEmpowering Growth with Best Software  Development Company in Noida - Deuglo
Empowering Growth with Best Software Development Company in Noida - Deuglo
 
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI AppAI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
 
GraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph TechnologyGraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph Technology
 
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
 
Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...
Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...
Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...
 
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
 
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissancesAtelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissances
 

Chap01-Intro.ppt

  • 1. Chapter 1. Introduction Compiler Dr. Mohammed Khader ASU 1
  • 2. 2
  • 3. Outline • 1.1 History of Compilation • 1.2 What Compilers Do • 1.3 Interpreters • 1.4 Syntax and Semantics • 1.5 Organization of a Compiler 3
  • 4. Language Processors • Act as Translators – Transforming human-oriented programming languages into computer-oriented machine languages 4
  • 5. Overview and History • Compilers are fundamental to modern computing. • They act as translators, transforming human-oriented programming languages into computer-oriented machine languages. Programming Language (Source) Compiler Machine Language (Target) 5
  • 6. Overview and History (Cont’d.) • The first real compiler – FORTRAN compilers of the late 1950s • Today, we can build a simple compiler in a few month. • Creating an efficient and reliable compiler is still challenging. 6
  • 7. Overview and History (Cont’d.) • Compiler technology is largely applicable and has been employed in rather unexpected areas. – Text-formatting languages, like LaTeX – Silicon compiler for the creation of VLSI circuits – Command languages of OS – Query languages of Database systems 7
  • 8. 8 Front-end and Back-end • Front-end performs the analysis of the source language code to build the internal representation, called intermediate representation (IR). • Back-end performs the target language synthesis to generate the target code (assembly code).
  • 9. 1.2 What Compilers Do • Compilers may be distinguished in two ways: 1. By the kind of machine code they generate 2. By the format of the target code they generate 9
  • 10. 10 Machine Code Generated by Compilers(kind of Machine code)  Pure machine code – Compiler may generate code for a particular machine’s instruction set without assuming the existence of any operating system or library routines. – Pure machine code is used in compilers for system implementation languages, which are for implementing operating systems or embedded applications.
  • 11. 11 Machine Code Generated by Compilers (Cont.)  Augmented machine code – Compilers generate code for a machine architecture that is augmented with: 1) operating system routines and 2) runtime language support routines.
  • 12. 12 Machine Code Generated by Compilers (Cont.)  Virtual machine code – Compilers generate virtual machine code that is composed entirely of virtual machine instructions. – That code can run on any architecture for which a VM interpreter is available. • For example, the VM for Java, Java virtual machine (JVM), has a JVM interpreter. – Portability is achieved by writing just one virtual machine (VM) interpreter for all the target architectures.
  • 13. 1.2.2 Target Code Formats Another way that compilers differ from one another is in the format of the target code they generate as follows: 1. Assembly Language (Source) Format • Advantages: – Simplifies translation: • A number of code generation decisions (e.g. how to compute addresses) can be left for the assembler. – Cross-compilation: • The compiler executes on one computer but generates code that executes on another. • Symbolic form is produced that is easily transferred between different computers. – Support experimental programming language designs • Makes it easier to check the correctness of a compiler, since its output can be observed. • Disadvantage: – Need an additional pass (Assembler) 13
  • 14. 1.2.2 Target Code Formats 2. Relocatable binary – External references, local instruction addresses, and data addresses are not yet bound. – Addresses are assigned relative either to the beginning of the module or to symbolically named locations. • Advantages: – More efficient and more control over the translation process: because it eliminates one step of calculating absolute addresses. – Allow modular compilation: breaking up of a large program into separately compiled pieces. – Allow cross-language references: calls of assembler routines or subprograms in other high-level languages – Support subroutine libraries for example, I/O, storage allocation, and math routines • Disadvantage: – A linkage step is required to support libraries and to produce absolute binary format that is executable. 14
  • 15. 1.2.2 Target Code Formats 3. Absolute binary • Advantages: – Program can be directly executed when the compiler is finished – No need for intermediate step of linking. – Faster: allows a program to be prepared and executed in a single step. – Guarantee the use of only the most current library routines – Good for debugging (frequent changes) • Disadvantages: – Limited ability to interface with other code – The program must be recompiled for each execution 15
  • 16. 16 1.3 Interpreters Compiler vs. Interpreter Compiler has compilation and execution phases: 1) The compilation phase generates target program from source program. 2) The execution phase executes the target program. (Fig. 1.1). Interpreter directly interprets (executes) the source program that reads inputs and writes outputs (Fig. 1.3).
  • 18. 1.4 Syntax and Semantics • Syntax: structure – E.g. context-free grammars (CFGs) •a=b+c is legal, •b+c=a is not legal • Semantics: meaning – E.g. a = b + c •is illegal if any of the variables are undeclared or if b or c is of type Boolean – Static semantics – Runtime semantics 18
  • 19. Static Semantics • A set of rules that specify which syntactically legal programs are actually valid – E.g.: Identifier declaration, type-compatibility of operators and operands, proper number of parameters in procedure calls • Can be specified either formally or informally – E.g.: attribute grammars 19
  • 20. An Example of Attribute Grammars • Production rule: – E  E+T • Augmented production rule: – Eresult  Ev1 + Tv2 •if v1.type = numeric and v2.type = numeric then result.type  numeric else call ERROR( ) 20
  • 21. Runtime Semantics •Runtime, or execution, semantics are used to specify what a program computes. A. Informal These semantics are often specified very informally in a language manual or report; B. Formal approaches to defining the runtime semantics of programming languages. 21
  • 22. The Structure of a Compiler • Modern compilers are syntax-directed – Compilation is driven by the syntactic structure of programs; – i.e., actions are associated with the structures. 22
  • 23. Tasks performed by compilers Analysis of the source program such as scanning and parsing. •Syntax analysis •Semantic analysis Synthesis of a target program such as code generation, that when executed, will correctly perform the computations described by the source program. 23
  • 24. 1.5 Organization of a Compiler (Used by all Phases of The Compiler) 24
  • 26. The Scanner • The scanner begins the analysis of the source program by reading the input text (character by character) and grouping individual characters into tokens such as : – Identifiers – Integers – Reserved words – Delimiters • It eliminate unneeded information like comments • It process compiler control directives. • It enters preliminary information into symbol table. 26
  • 27. The Parser • Reading tokens and grouping them into phrases according to the syntax specification such as context free grammar CFG • It usually builds an Abstract Syntax Tree (AST) as a concise representation of program structure – (Chap. 2 & 7) 27
  • 28. The Type Checker (Semantic Analysis) • Checking the static semantics of each AST node – the type checker decorates the AST node by adding type information to it – It checks type correctness, reachability and termination, and exception handling. – Otherwise, a suitable error message is issued 28
  • 29. Translator (Program Synthesis) • Translating AST nodes into Intermediate Representation code (IR) (such as byte code in Java) that correctly implements the meaning of the program • In simple, nonoptimizing compilers, the translator may generate target code directly 29
  • 30. The Optimizer • Optimizer improves IR code’s performance. • Analyzing and transforming the IR code generated by the translator into functionally equivalent but improved code – Complex • Optimization can also be done after code generation 30
  • 31. The Code Generator • Mapping the IR code generated by the translator into target machine code (assembly code) – Machine-dependent, complex • Register allocation • Code scheduling • Automatic construction of code generators has been actively studied – Matching a low-level IR to target-instruction templates – gcc has machine description files for more than ten popular computer. 31
  • 32. 328 Organization of a Compiler (Cont.) Symbol Tables Scannerr Parser Type Checker Translator Optimizer Code Generator Source Program Tokens AST Decorated AST Intermediate Representation Intermediate Representation Target Code Revised Figure 1.4: A syntax-directed compiler. AST denotes the Abstract Syntax Tree.
  • 33. Symbol Tables • A mechanism that allows information to be associated with identifiers and shared among compiler phases – Identifier declaration – Identifier use – Type checking 33
  • 34. The Structure of a Compiler 34 Scanner [Lexical Analyzer] Parser [Syntax Analyzer] Semantic Process [Semantic analyzer] Code Generator [Intermediate Code Generator] Code Optimizer Tokens Parse tree Abstract Syntax Tree w/ Attributes Non-optimized Intermediate Code Optimized Intermediate Code Code Generator Target machine code
  • 35. Phases of a Compiler [Aho, Lam, Sethi, Ullman] Syntax Analyzer character stream target machine code Lexical Analyzer Intermediate Code Generator Code Generator token stream syntax tree intermediate representation Symbol Table Semantic Analyzer syntax tree Machine-Independent Code Optimization Machine-Dependent Code Optimization (optional) (optional) 35
  • 36. Compiler Writing Tools • Compiler generators (compiler compilers) – Scanner generator – Parser generator – Symbol table manager – Attribute grammar evaluator – Code-generation tools • Much of the effort in crafting a compiler lies in writing and debugging the semantic phases – Usually hand-coded 36
  • 37. Compiler-writing tools Regular expressions Scanner generators Lex (The input to lex consists of a definition of each token as a regular expression ) Parser generators: Yacc Code generator generators http://catalog.compilertools.net/  37