SlideShare una empresa de Scribd logo
1 de 22
Descargar para leer sin conexión
: Introduction 1
Introduction
2
What is a Compiler?
• A compiler is a computer
program that translates a
program in a source language
into an equivalent program in a
target language.
• A source program/code is a
program/code written in the
source language, which is
usually a high-level language.
• A target program/code is a
program/code written in the
target language, which often is a
machine language or an
intermediate code.
compiler
Source
program
Target
program
Error
message
3
Process of Compiling
scanner
parser
Semantic analyzer
Intermediate code generator
Code optimization
Code generator
Code optimization
Stream of characters
Stream of tokens
Parse/syntax tree
Annotated tree
Intermediate code
Intermediate code
Target code
Target code
4
Some Data Structures
• Symbol table
• Literal table
• Parse tree
5
Symbol Table
• Identifiers are names of variables,
constants, functions, data types, etc.
• Store information associated with identifiers
– Information associated with different types of
identifiers can be different
• Information associated with variables are name, type,
address,size (for array), etc.
• Information associated with functions are name,type
of return value, parameters, address, etc.
6
Symbol Table (cont’d)
• Accessed in every phase of compilers
– The scanner, parser, and semantic analyzer put
names of identifiers in symbol table.
– The semantic analyzer stores more information
(e.g. data types) in the table.
– The intermediate code generator, code
optimizer and code generator use information in
symbol table to generate appropriate code.
• Mostly use hash table for efficiency.
7
Literal table
• Store constants and strings used in program
– reduce the memory size by reusing constants
and strings
• Can be combined with symbol table
8
Parse tree
• Dynamically-allocated, pointer-based
structure
• Information for different data types
related to parse trees need to be stored
somewhere.
– Nodes are variant records, storing
information for different types of data
– Nodes store pointers to information stored
in other data structure, e.g. symbol table
9
Scanning
• A scanner reads a stream of characters and
puts them together into some meaningful
(with respect to the source language) units
called tokens.
• It produces a stream of tokens for the next
phase of compiler.
10
Parsing
• A parser gets a stream of tokens from the
scanner, and determines if the syntax
(structure) of the program is correct
according to the (context-free) grammar of
the source language.
• Then, it produces a data structure, called a
parse tree or an abstract syntax tree, which
describes the syntactic structure of the
program.
11
Semantic analysis
• It gets the parse tree from the parser together with
information about some syntactic elements
• It determines if the semantics or meaning of the
program is correct.
• This part deals with static semantic.
– semantic of programs that can be checked by reading
off from the program only.
– syntax of the language which cannot be described in
context-free grammar.
• Mostly, a semantic analyzer does type checking.
• It modifies the parse tree in order to get that
(static) semantically correct code.
12
Intermediate code generation
• An intermediate code generator
– takes a parse tree from the semantic analyzer
– generates a program in the intermediate
language.
• In some compilers, a source program is
translated into an intermediate code first and
then the intermediate code is translated into
the target language.
• In other compilers, a source program is
translated directly into the target language.
13
Intermediate code generation (cont’d)
• Using intermediate code is beneficial when
compilers which translates a single source
language to many target languages are
required.
– The front-end of a compiler – scanner to
intermediate code generator – can be used for
every compilers.
– Different back-ends – code optimizer and code
generator– is required for each target language.
• One of the popular intermediate code is
three-address code. A three-address code
instruction is in the form of x = y op z.
14
Code optimization
• Replacing an inefficient sequence of
instructions with a better sequence of
instructions.
• Sometimes called code improvement.
• Code optimization can be done:
– after semantic analyzing
• performed on a parse tree
– after intermediate code generation
• performed on a intermediate code
– after code generation
• performed on a target code
15
Code generation
• A code generator
– takes either an intermediate code or a parse
tree
– produces a target program.
16
Error Handling
• Error can be found in every phase of
compilation.
– Errors found during compilation are called static
(or compile-time) errors.
– Errors found during execution are called
dynamic (or run-time) errors
• Compilers need to detect, report, and
recover from error found in source programs
• Error handlers are different in different
phases of compiler.
Chapter 1 2301373: Introduction 17
• a compiler which generates target code for a
different machine from one on which the
compiler runs.
• A host language is a language in which the
compiler is written.
– T-diagram
• Cross compilers are used very often in
practice.
Cross Compiler
S
H
T
18
Cross Compilers (cont’d)
• If we want a compiler from
language A to language B on a
machine with language E,
– write one with E
– write one with D if you have a
compiler from D to E on some
machine
• It is better than the former approach
if D is a high-level language but E is
a machine language
– write one from G to B with E if we
have a compiler from A to G
written in E
A
E
B
D
?
E
A
D
B
G
E
BA
E
G
19
Porting
• Porting: construct a compiler between a
source and a target language using one
host language from another host language
A
A
K
A
H
H A
H
K
A
A
K
A
H
K A
K
K
20
Bootstrapping
• If we have to implement, from
scratch, a compiler from a
high-level language A to a
machine, which is also a host,
language,
– direct method
– bootstrapping
A
H
H
A
A1
H
A1
A2
H
A2
A3
H
A3
H
H
21
Cousins of Compilers
• Linkers
• Loaders
• Interpreters
• Assemblers
Chapter 1 2301373: Introduction 22
History (1930’s -40’s)
• 1930’s
– John von Neumann invented the concept of
stored-program computer.
– Alan Turing defined Turing machine and
computability.
• 1940’s
– Many electro-mechanic, stored-program
computers were constructed.
• ABC (Atanasoff Berry Computer) at Iowa
• Z1-4 (by Zuse) in Germany
• ENIAC (programmed by a plug board)

Más contenido relacionado

La actualidad más candente (20)

Linkers
LinkersLinkers
Linkers
 
Stack and its usage in assembly language
Stack and its usage in assembly language Stack and its usage in assembly language
Stack and its usage in assembly language
 
Compiler Construction
Compiler ConstructionCompiler Construction
Compiler Construction
 
Introduction to Compiler design
Introduction to Compiler design Introduction to Compiler design
Introduction to Compiler design
 
COMPILER DESIGN OPTIONS
COMPILER DESIGN OPTIONSCOMPILER DESIGN OPTIONS
COMPILER DESIGN OPTIONS
 
Compiler Construction Course - Introduction
Compiler Construction Course - IntroductionCompiler Construction Course - Introduction
Compiler Construction Course - Introduction
 
Context switching
Context switchingContext switching
Context switching
 
Real time-embedded-system-lec-02
Real time-embedded-system-lec-02Real time-embedded-system-lec-02
Real time-embedded-system-lec-02
 
The Phases of a Compiler
The Phases of a CompilerThe Phases of a Compiler
The Phases of a Compiler
 
Assembly Language
Assembly LanguageAssembly Language
Assembly Language
 
Compiler an overview
Compiler  an overviewCompiler  an overview
Compiler an overview
 
Phases of compiler
Phases of compilerPhases of compiler
Phases of compiler
 
instruction cycle ppt
instruction cycle pptinstruction cycle ppt
instruction cycle ppt
 
Yacc
YaccYacc
Yacc
 
Interpreter
InterpreterInterpreter
Interpreter
 
loaders and linkers
 loaders and linkers loaders and linkers
loaders and linkers
 
Lecture 3 basic syntax and semantics
Lecture 3  basic syntax and semanticsLecture 3  basic syntax and semantics
Lecture 3 basic syntax and semantics
 
Syntax analysis
Syntax analysisSyntax analysis
Syntax analysis
 
Computer languages
Computer languagesComputer languages
Computer languages
 
Interrupts
InterruptsInterrupts
Interrupts
 

Destacado

Programing paradigm & implementation
Programing paradigm & implementationPrograming paradigm & implementation
Programing paradigm & implementationBilal Maqbool ツ
 
Object Oriented Programing - Inheritance
Object Oriented Programing - InheritanceObject Oriented Programing - Inheritance
Object Oriented Programing - InheritanceBayu Firmawan Paoh
 
Dynamics Telephony Dialer Intro
Dynamics Telephony Dialer IntroDynamics Telephony Dialer Intro
Dynamics Telephony Dialer IntroEddie Steede
 
Object Oriented Programing - Polymrphism
Object Oriented Programing - PolymrphismObject Oriented Programing - Polymrphism
Object Oriented Programing - PolymrphismBayu Firmawan Paoh
 
Object Oriented Programing - Intro
Object Oriented Programing - IntroObject Oriented Programing - Intro
Object Oriented Programing - IntroBayu Firmawan Paoh
 
ELIXIR Webinar: Introducing TeSS
ELIXIR Webinar: Introducing TeSSELIXIR Webinar: Introducing TeSS
ELIXIR Webinar: Introducing TeSSNiall Beard
 
Spark as a distributed Scala
Spark as a distributed ScalaSpark as a distributed Scala
Spark as a distributed ScalaAlex Fruzenshtein
 
WEB MINING: PATTERN DISCOVERY ON THE WORLD WIDE WEB - 2011
WEB MINING: PATTERN DISCOVERY ON THE WORLD WIDE WEB - 2011WEB MINING: PATTERN DISCOVERY ON THE WORLD WIDE WEB - 2011
WEB MINING: PATTERN DISCOVERY ON THE WORLD WIDE WEB - 2011Mustafa TURAN
 
나프다 웨비너 1604: Elixir와 함수형 프로그래밍을 이용한 웹 개발
나프다 웨비너 1604: Elixir와 함수형 프로그래밍을 이용한 웹 개발나프다 웨비너 1604: Elixir와 함수형 프로그래밍을 이용한 웹 개발
나프다 웨비너 1604: Elixir와 함수형 프로그래밍을 이용한 웹 개발Changwook Park
 
Magic Clusters and Where to Find Them 2.0 - Eugene Pirogov
Magic Clusters and Where to Find Them 2.0 - Eugene Pirogov Magic Clusters and Where to Find Them 2.0 - Eugene Pirogov
Magic Clusters and Where to Find Them 2.0 - Eugene Pirogov Elixir Club
 
Control flow in_elixir
Control flow in_elixirControl flow in_elixir
Control flow in_elixirAnna Neyzberg
 
Flowex: Flow-Based Programming with Elixir GenStage - Anton Mishchuk
Flowex: Flow-Based Programming with Elixir GenStage - Anton MishchukFlowex: Flow-Based Programming with Elixir GenStage - Anton Mishchuk
Flowex: Flow-Based Programming with Elixir GenStage - Anton MishchukElixir Club
 
Phoenix: Inflame the Web - Alex Troush
Phoenix: Inflame the Web - Alex TroushPhoenix: Inflame the Web - Alex Troush
Phoenix: Inflame the Web - Alex TroushElixir Club
 
IS 151 Lecture 3
IS 151 Lecture 3IS 151 Lecture 3
IS 151 Lecture 3wajanga
 
IS 139 Lecture 7
IS 139 Lecture 7IS 139 Lecture 7
IS 139 Lecture 7wajanga
 
GenStage and Flow - Jose Valim
GenStage and Flow - Jose Valim GenStage and Flow - Jose Valim
GenStage and Flow - Jose Valim Elixir Club
 

Destacado (20)

Programing paradigm & implementation
Programing paradigm & implementationPrograming paradigm & implementation
Programing paradigm & implementation
 
Object Oriented Programing - Inheritance
Object Oriented Programing - InheritanceObject Oriented Programing - Inheritance
Object Oriented Programing - Inheritance
 
Dynamics Telephony Dialer Intro
Dynamics Telephony Dialer IntroDynamics Telephony Dialer Intro
Dynamics Telephony Dialer Intro
 
Object Oriented Programing - Polymrphism
Object Oriented Programing - PolymrphismObject Oriented Programing - Polymrphism
Object Oriented Programing - Polymrphism
 
Object Oriented Programing - Intro
Object Oriented Programing - IntroObject Oriented Programing - Intro
Object Oriented Programing - Intro
 
Aspect Oriented Programing - Introduction
Aspect Oriented Programing - IntroductionAspect Oriented Programing - Introduction
Aspect Oriented Programing - Introduction
 
ELIXIR Webinar: Introducing TeSS
ELIXIR Webinar: Introducing TeSSELIXIR Webinar: Introducing TeSS
ELIXIR Webinar: Introducing TeSS
 
Spark as a distributed Scala
Spark as a distributed ScalaSpark as a distributed Scala
Spark as a distributed Scala
 
Big Data eBook
Big Data eBookBig Data eBook
Big Data eBook
 
WEB MINING: PATTERN DISCOVERY ON THE WORLD WIDE WEB - 2011
WEB MINING: PATTERN DISCOVERY ON THE WORLD WIDE WEB - 2011WEB MINING: PATTERN DISCOVERY ON THE WORLD WIDE WEB - 2011
WEB MINING: PATTERN DISCOVERY ON THE WORLD WIDE WEB - 2011
 
나프다 웨비너 1604: Elixir와 함수형 프로그래밍을 이용한 웹 개발
나프다 웨비너 1604: Elixir와 함수형 프로그래밍을 이용한 웹 개발나프다 웨비너 1604: Elixir와 함수형 프로그래밍을 이용한 웹 개발
나프다 웨비너 1604: Elixir와 함수형 프로그래밍을 이용한 웹 개발
 
Magic Clusters and Where to Find Them 2.0 - Eugene Pirogov
Magic Clusters and Where to Find Them 2.0 - Eugene Pirogov Magic Clusters and Where to Find Them 2.0 - Eugene Pirogov
Magic Clusters and Where to Find Them 2.0 - Eugene Pirogov
 
Control flow in_elixir
Control flow in_elixirControl flow in_elixir
Control flow in_elixir
 
Spring IO for startups
Spring IO for startupsSpring IO for startups
Spring IO for startups
 
Flowex: Flow-Based Programming with Elixir GenStage - Anton Mishchuk
Flowex: Flow-Based Programming with Elixir GenStage - Anton MishchukFlowex: Flow-Based Programming with Elixir GenStage - Anton Mishchuk
Flowex: Flow-Based Programming with Elixir GenStage - Anton Mishchuk
 
Phoenix: Inflame the Web - Alex Troush
Phoenix: Inflame the Web - Alex TroushPhoenix: Inflame the Web - Alex Troush
Phoenix: Inflame the Web - Alex Troush
 
Chap 10(structure and unions)
Chap 10(structure and unions)Chap 10(structure and unions)
Chap 10(structure and unions)
 
IS 151 Lecture 3
IS 151 Lecture 3IS 151 Lecture 3
IS 151 Lecture 3
 
IS 139 Lecture 7
IS 139 Lecture 7IS 139 Lecture 7
IS 139 Lecture 7
 
GenStage and Flow - Jose Valim
GenStage and Flow - Jose Valim GenStage and Flow - Jose Valim
GenStage and Flow - Jose Valim
 

Similar a Introduction to Compilers in 40 Characters

introduction to computer vision and image processing
introduction to computer vision and image processingintroduction to computer vision and image processing
introduction to computer vision and image processingpakboy12
 
Compiler Design Introduction
Compiler Design Introduction Compiler Design Introduction
Compiler Design Introduction Thapar Institute
 
Compiler Design Basics
Compiler Design BasicsCompiler Design Basics
Compiler Design BasicsAkhil Kaushik
 
Introduction to Compilers
Introduction to CompilersIntroduction to Compilers
Introduction to CompilersAkhil Kaushik
 
Cd ch1 - introduction
Cd   ch1 - introductionCd   ch1 - introduction
Cd ch1 - introductionmengistu23
 
CD - CH1 - Introduction to compiler design.pptx
CD - CH1 - Introduction to compiler design.pptxCD - CH1 - Introduction to compiler design.pptx
CD - CH1 - Introduction to compiler design.pptxZiyadMohammed17
 
4_5802928814682016556.pptx
4_5802928814682016556.pptx4_5802928814682016556.pptx
4_5802928814682016556.pptxAshenafiGirma5
 
COMPILER DESIGN.pdf
COMPILER DESIGN.pdfCOMPILER DESIGN.pdf
COMPILER DESIGN.pdfAdiseshaK
 
Introduction to compiler
Introduction to compilerIntroduction to compiler
Introduction to compilerAbha Damani
 
Compier Design_Unit I.ppt
Compier Design_Unit I.pptCompier Design_Unit I.ppt
Compier Design_Unit I.pptsivaganesh293
 
Compier Design_Unit I.ppt
Compier Design_Unit I.pptCompier Design_Unit I.ppt
Compier Design_Unit I.pptsivaganesh293
 
Compiler Design Basics
Compiler Design BasicsCompiler Design Basics
Compiler Design BasicsAkhil Kaushik
 
Session01 basics programming
Session01 basics programmingSession01 basics programming
Session01 basics programmingHarithaRanasinghe
 
Phases of Compiler.pptx
Phases of Compiler.pptxPhases of Compiler.pptx
Phases of Compiler.pptxssuser3b4934
 

Similar a Introduction to Compilers in 40 Characters (20)

introduction to computer vision and image processing
introduction to computer vision and image processingintroduction to computer vision and image processing
introduction to computer vision and image processing
 
Introduction to Compiler
Introduction to CompilerIntroduction to Compiler
Introduction to Compiler
 
Compiler Design Introduction
Compiler Design Introduction Compiler Design Introduction
Compiler Design Introduction
 
Compiler Design Basics
Compiler Design BasicsCompiler Design Basics
Compiler Design Basics
 
COMPILER DESIGN PPTS.pptx
COMPILER DESIGN PPTS.pptxCOMPILER DESIGN PPTS.pptx
COMPILER DESIGN PPTS.pptx
 
Introduction to Compilers
Introduction to CompilersIntroduction to Compilers
Introduction to Compilers
 
Cd ch1 - introduction
Cd   ch1 - introductionCd   ch1 - introduction
Cd ch1 - introduction
 
CD - CH1 - Introduction to compiler design.pptx
CD - CH1 - Introduction to compiler design.pptxCD - CH1 - Introduction to compiler design.pptx
CD - CH1 - Introduction to compiler design.pptx
 
4_5802928814682016556.pptx
4_5802928814682016556.pptx4_5802928814682016556.pptx
4_5802928814682016556.pptx
 
COMPILER DESIGN.pdf
COMPILER DESIGN.pdfCOMPILER DESIGN.pdf
COMPILER DESIGN.pdf
 
Introduction to compiler
Introduction to compilerIntroduction to compiler
Introduction to compiler
 
Compier Design_Unit I.ppt
Compier Design_Unit I.pptCompier Design_Unit I.ppt
Compier Design_Unit I.ppt
 
Compier Design_Unit I.ppt
Compier Design_Unit I.pptCompier Design_Unit I.ppt
Compier Design_Unit I.ppt
 
Compiler Design Basics
Compiler Design BasicsCompiler Design Basics
Compiler Design Basics
 
1 compiler outline
1 compiler outline1 compiler outline
1 compiler outline
 
Presentation1
Presentation1Presentation1
Presentation1
 
Presentation1
Presentation1Presentation1
Presentation1
 
Session01 basics programming
Session01 basics programmingSession01 basics programming
Session01 basics programming
 
Phases of Compiler.pptx
Phases of Compiler.pptxPhases of Compiler.pptx
Phases of Compiler.pptx
 
1 cc
1 cc1 cc
1 cc
 

Más de Bilal Maqbool ツ (20)

Dld lecture module 01
Dld lecture module 01Dld lecture module 01
Dld lecture module 01
 
Complement
ComplementComplement
Complement
 
Chapter10
Chapter10Chapter10
Chapter10
 
Uncdtalk
UncdtalkUncdtalk
Uncdtalk
 
Okkkkk
OkkkkkOkkkkk
Okkkkk
 
Good
GoodGood
Good
 
Dld lecture module 06
Dld lecture module 06Dld lecture module 06
Dld lecture module 06
 
Dld lecture module 05
Dld lecture module 05Dld lecture module 05
Dld lecture module 05
 
Dld lecture module 04 01
Dld lecture module 04  01Dld lecture module 04  01
Dld lecture module 04 01
 
Dld lecture module 03
Dld lecture module 03Dld lecture module 03
Dld lecture module 03
 
Dld lecture module 02
Dld lecture module 02Dld lecture module 02
Dld lecture module 02
 
Lecture 3 report writtng
Lecture 3 report writtngLecture 3 report writtng
Lecture 3 report writtng
 
Lecture 2
Lecture 2Lecture 2
Lecture 2
 
Lecture 1 report writing
Lecture 1 report writingLecture 1 report writing
Lecture 1 report writing
 
Bill gates
Bill gatesBill gates
Bill gates
 
Programming assignment 02 (bilal maqbool 10) 2011
Programming assignment 02    (bilal maqbool 10) 2011Programming assignment 02    (bilal maqbool 10) 2011
Programming assignment 02 (bilal maqbool 10) 2011
 
Programming assignment 30 12-11
Programming assignment 30 12-11Programming assignment 30 12-11
Programming assignment 30 12-11
 
Internet presentation
Internet presentationInternet presentation
Internet presentation
 
Presentation internet programming report
Presentation internet programming reportPresentation internet programming report
Presentation internet programming report
 
Magnetic storage devices
Magnetic storage devicesMagnetic storage devices
Magnetic storage devices
 

Último

How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPCeline George
 
ROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxVanesaIglesias10
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptxmary850239
 
TEACHER REFLECTION FORM (NEW SET........).docx
TEACHER REFLECTION FORM (NEW SET........).docxTEACHER REFLECTION FORM (NEW SET........).docx
TEACHER REFLECTION FORM (NEW SET........).docxruthvilladarez
 
Expanded definition: technical and operational
Expanded definition: technical and operationalExpanded definition: technical and operational
Expanded definition: technical and operationalssuser3e220a
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfTechSoup
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSJoshuaGantuangco2
 
Oppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and FilmOppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and FilmStan Meyer
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parentsnavabharathschool99
 
EMBODO Lesson Plan Grade 9 Law of Sines.docx
EMBODO Lesson Plan Grade 9 Law of Sines.docxEMBODO Lesson Plan Grade 9 Law of Sines.docx
EMBODO Lesson Plan Grade 9 Law of Sines.docxElton John Embodo
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17Celine George
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfJemuel Francisco
 
ICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfVanessa Camilleri
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)lakshayb543
 

Último (20)

How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
 
ROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptx
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 
Paradigm shift in nursing research by RS MEHTA
Paradigm shift in nursing research by RS MEHTAParadigm shift in nursing research by RS MEHTA
Paradigm shift in nursing research by RS MEHTA
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx
 
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptxYOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
 
TEACHER REFLECTION FORM (NEW SET........).docx
TEACHER REFLECTION FORM (NEW SET........).docxTEACHER REFLECTION FORM (NEW SET........).docx
TEACHER REFLECTION FORM (NEW SET........).docx
 
Expanded definition: technical and operational
Expanded definition: technical and operationalExpanded definition: technical and operational
Expanded definition: technical and operational
 
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptxLEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
 
Oppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and FilmOppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and Film
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parents
 
EMBODO Lesson Plan Grade 9 Law of Sines.docx
EMBODO Lesson Plan Grade 9 Law of Sines.docxEMBODO Lesson Plan Grade 9 Law of Sines.docx
EMBODO Lesson Plan Grade 9 Law of Sines.docx
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
 
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptxFINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
 
ICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdf
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
 
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptxYOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
 

Introduction to Compilers in 40 Characters

  • 2. 2 What is a Compiler? • A compiler is a computer program that translates a program in a source language into an equivalent program in a target language. • A source program/code is a program/code written in the source language, which is usually a high-level language. • A target program/code is a program/code written in the target language, which often is a machine language or an intermediate code. compiler Source program Target program Error message
  • 3. 3 Process of Compiling scanner parser Semantic analyzer Intermediate code generator Code optimization Code generator Code optimization Stream of characters Stream of tokens Parse/syntax tree Annotated tree Intermediate code Intermediate code Target code Target code
  • 4. 4 Some Data Structures • Symbol table • Literal table • Parse tree
  • 5. 5 Symbol Table • Identifiers are names of variables, constants, functions, data types, etc. • Store information associated with identifiers – Information associated with different types of identifiers can be different • Information associated with variables are name, type, address,size (for array), etc. • Information associated with functions are name,type of return value, parameters, address, etc.
  • 6. 6 Symbol Table (cont’d) • Accessed in every phase of compilers – The scanner, parser, and semantic analyzer put names of identifiers in symbol table. – The semantic analyzer stores more information (e.g. data types) in the table. – The intermediate code generator, code optimizer and code generator use information in symbol table to generate appropriate code. • Mostly use hash table for efficiency.
  • 7. 7 Literal table • Store constants and strings used in program – reduce the memory size by reusing constants and strings • Can be combined with symbol table
  • 8. 8 Parse tree • Dynamically-allocated, pointer-based structure • Information for different data types related to parse trees need to be stored somewhere. – Nodes are variant records, storing information for different types of data – Nodes store pointers to information stored in other data structure, e.g. symbol table
  • 9. 9 Scanning • A scanner reads a stream of characters and puts them together into some meaningful (with respect to the source language) units called tokens. • It produces a stream of tokens for the next phase of compiler.
  • 10. 10 Parsing • A parser gets a stream of tokens from the scanner, and determines if the syntax (structure) of the program is correct according to the (context-free) grammar of the source language. • Then, it produces a data structure, called a parse tree or an abstract syntax tree, which describes the syntactic structure of the program.
  • 11. 11 Semantic analysis • It gets the parse tree from the parser together with information about some syntactic elements • It determines if the semantics or meaning of the program is correct. • This part deals with static semantic. – semantic of programs that can be checked by reading off from the program only. – syntax of the language which cannot be described in context-free grammar. • Mostly, a semantic analyzer does type checking. • It modifies the parse tree in order to get that (static) semantically correct code.
  • 12. 12 Intermediate code generation • An intermediate code generator – takes a parse tree from the semantic analyzer – generates a program in the intermediate language. • In some compilers, a source program is translated into an intermediate code first and then the intermediate code is translated into the target language. • In other compilers, a source program is translated directly into the target language.
  • 13. 13 Intermediate code generation (cont’d) • Using intermediate code is beneficial when compilers which translates a single source language to many target languages are required. – The front-end of a compiler – scanner to intermediate code generator – can be used for every compilers. – Different back-ends – code optimizer and code generator– is required for each target language. • One of the popular intermediate code is three-address code. A three-address code instruction is in the form of x = y op z.
  • 14. 14 Code optimization • Replacing an inefficient sequence of instructions with a better sequence of instructions. • Sometimes called code improvement. • Code optimization can be done: – after semantic analyzing • performed on a parse tree – after intermediate code generation • performed on a intermediate code – after code generation • performed on a target code
  • 15. 15 Code generation • A code generator – takes either an intermediate code or a parse tree – produces a target program.
  • 16. 16 Error Handling • Error can be found in every phase of compilation. – Errors found during compilation are called static (or compile-time) errors. – Errors found during execution are called dynamic (or run-time) errors • Compilers need to detect, report, and recover from error found in source programs • Error handlers are different in different phases of compiler.
  • 17. Chapter 1 2301373: Introduction 17 • a compiler which generates target code for a different machine from one on which the compiler runs. • A host language is a language in which the compiler is written. – T-diagram • Cross compilers are used very often in practice. Cross Compiler S H T
  • 18. 18 Cross Compilers (cont’d) • If we want a compiler from language A to language B on a machine with language E, – write one with E – write one with D if you have a compiler from D to E on some machine • It is better than the former approach if D is a high-level language but E is a machine language – write one from G to B with E if we have a compiler from A to G written in E A E B D ? E A D B G E BA E G
  • 19. 19 Porting • Porting: construct a compiler between a source and a target language using one host language from another host language A A K A H H A H K A A K A H K A K K
  • 20. 20 Bootstrapping • If we have to implement, from scratch, a compiler from a high-level language A to a machine, which is also a host, language, – direct method – bootstrapping A H H A A1 H A1 A2 H A2 A3 H A3 H H
  • 21. 21 Cousins of Compilers • Linkers • Loaders • Interpreters • Assemblers
  • 22. Chapter 1 2301373: Introduction 22 History (1930’s -40’s) • 1930’s – John von Neumann invented the concept of stored-program computer. – Alan Turing defined Turing machine and computability. • 1940’s – Many electro-mechanic, stored-program computers were constructed. • ABC (Atanasoff Berry Computer) at Iowa • Z1-4 (by Zuse) in Germany • ENIAC (programmed by a plug board)