Introduction to Compiler design

Dr. C.V. Suresh Babu
Dr. C.V. Suresh BabuTeacher / Trainer / Coach / Author / Publisher / Educational consultant en Hindustan University / Sathyasai B.Ed college
11
Dr. C.V. Suresh Babu
2
• Because computer can't understand the source code directly. It will
understand only object level code.
• Source codes are human readable format but the system cannot
understand it.
• So, the compiler is intermediate between human readable format
and machine-readable format.
3
4
Topics
• Introduction
• Lexical analysis
• Syntax analysis
• Symbol tables
5
Language processing system
To create an executable target program several programs may
be required
Collecting the source
Program ( modules,
macros, etc.)
Assembly-language
program
66
-In order to reduce the complexity of designing and building
computers, nearly all of these are made to execute relatively
simple commands (but do so very quickly).
-A program for a computer must be built by combining these very
simple commands into a program in what is called machine
language.
-Most programming is done using a high-level programming
language -> But this language can be very different from the
machine language that the computer can execute.
===>This is where the compiler comes in
7
• Using a high-level language for programming has a large impact
on how fast programs can be developed:
– Compared to machine language, the notation used by
programming languages is closer to the way humans think
about problems,
– The compiler can spot some obvious programming mistakes,
– Programs written in a high-level language tend to be shorter
than equivalent programs written in machine language
– The same program can be compiled to many different
machine languages and, hence, be brought to run on many
different machines.
8
A compiler translates a program written in a high-level
programming language that is suitable for human
programmers into the low-level machine language that is
required by computers
+
spots and reports obvious programmer mistakes.
8
What’s a compiler ?
9
Running the target program
• If the target program is an executable machine-language
program, it can then be called by the user to process inputs
and produce outputs.
9
10
What’s an interpreter ?
• An interpreter is another way of implementing a programming
language.
• Interpretation shares many aspects with compiling (Lexing,
parsing and type-checking)
 But
Instead of producing a target program as a translation, an
interpreter appears to directly execute the operations specified
in the source program on inputs supplied by the user
10
1111
12
The Structure of a Compiler
12
1313
Dividing into tokens (symbols :
variable name, keyword or number)
Producing a tree-structure that
reflects the structure of the program.
Determining if the program
violates certain consistency requirements (if a
variable is used but not declared, use a boolean
value as a function pointer)
Translating the intermediate language to
assembly language (a textual representation of
machine code) for a specific machine
architecture.
Translating the assembly-language code into
binary representation and addresses of
variables, functions are determined.
1414
15
Symbol Table Management
- The symbol table is a data structure containing a record for each
variable name, with fields for the attributes of the name
(storage allocated for a name, its type, its scope where in the
program its value may be used), and for procedure names
(number and types of its arguments, the method of passing
each argument and the type returned ).
- The data structure should be designed to allow the compiler to
find the record for each name quickly and to store or retrieve
data from that record quickly.
15
16
17
18
19
20
21
22
Intermediate Code Generation
In the process of translating a source program into
target code, a compiler may construct one or more
intermediate representations, which can have a
variety of forms.
It should be easy to
produce
It should be easy to translate
into the target machine.
23
The machine-independent code-optimization phase attempts to
improve the intermediate code so that better target code will
result.
faster
shorter code
target code
that consumes
less power
Code Optimization
24
Code Generation
The code generator takes as input an intermediate representation
of the source program and maps it into the target language.
A judicious assignment of registers to hold
variables.
25
The Grouping o f Phases into Passes
In an implementation, activities from several phases
may be grouped together.
- Front-end phases : {lexical analysis, syntax analysis,
semantic analysis, and intermediate code generation }(
one pass)
- Back-end phases : {code generation, aspects of code
optimization, error handling , symbol-table operations}
N.B: Several phases of compilation are usually
implemented in a single pass  Reading an input
file and writing an output file.
26
Compiler- Construction Tools
• The compiler writer, like any software developer,
can profitably use modern software development
environments containing tools such as language
editors, debuggers, version managers , profilers,
test harnesses, and so on.
• In addition to these general software-development
tools, other more specialized tools have been
created to help implement various phases of a
compiler.
27
Compiler-construction tools
examples
• Parser generators (to produce syntax analyzers)
• Scanner generators (to generate automatically lexical
analyzers)
• Syntax-directed translation engines (producing
routines that walk the parse tree)
• Code-generator (taking rules that define the
translation of each operation of the intermediate
language into the machine language for the target
machine)
• Data-flow analysis engines ( optimizing code)
• Compiler- construction toolkits
28
The Evolution of Programming
Languages
• The Move to Higher-level Languages
•Impacts on Compile
29
The Science of Building a Compiler
• Modeling in Compiler Design and
Implementation
• The Science of Code Optimization
– Compiler optimizations must meet the following
design objectives:
• The optimization must be correct, that is, preserve the
meaning of the compiled program,
• The optimization must improve the performance of many
programs,
• The compilation time must be kept reasonable, and
• The engineering effort required must be manageable.
30
Applications of Compiler
Technology
• Implementation of High-Level Programming
Languages
– The key ideas behind object orientation are
• 1 . Data abstraction and
• 2. Inheritance of properties,
• Optimizations for Computer Architectures
– Parallelism
– Memory Hierarchies
31
• Design of New Computer Architectures
– RISC
– CISC
– Specialized Architectures
1 de 31

Recomendados

Phases of Compiler por
Phases of CompilerPhases of Compiler
Phases of CompilerTanzeela_Hussain
43.5K vistas34 diapositivas
Compiler Chapter 1 por
Compiler Chapter 1Compiler Chapter 1
Compiler Chapter 1Huawei Technologies
53.3K vistas129 diapositivas
Lecture 01 introduction to compiler por
Lecture 01 introduction to compilerLecture 01 introduction to compiler
Lecture 01 introduction to compilerIffat Anjum
19.9K vistas33 diapositivas
Compilers por
CompilersCompilers
CompilersBense Tony
20.2K vistas30 diapositivas
Compiler Design Basics por
Compiler Design BasicsCompiler Design Basics
Compiler Design BasicsAkhil Kaushik
7.2K vistas48 diapositivas
Compiler Design por
Compiler DesignCompiler Design
Compiler DesignMir Majid
46.2K vistas18 diapositivas

Más contenido relacionado

La actualidad más candente

Lexical analysis - Compiler Design por
Lexical analysis - Compiler DesignLexical analysis - Compiler Design
Lexical analysis - Compiler DesignMuhammed Afsal Villan
20.8K vistas39 diapositivas
Language processing activity por
Language processing activityLanguage processing activity
Language processing activityDhruv Sabalpara
10.7K vistas6 diapositivas
Compiler construction tools por
Compiler construction toolsCompiler construction tools
Compiler construction toolsAkhil Kaushik
1.3K vistas22 diapositivas
basics of compiler design por
basics of compiler designbasics of compiler design
basics of compiler designPreeti Katiyar
1.1K vistas14 diapositivas
Fundamentals of Language Processing por
Fundamentals of Language ProcessingFundamentals of Language Processing
Fundamentals of Language ProcessingHemant Sharma
21.8K vistas11 diapositivas
Software Engineering Practice por
Software Engineering PracticeSoftware Engineering Practice
Software Engineering PracticeResearch & Development LAB QUEST Nawabshah
43.3K vistas22 diapositivas

La actualidad más candente(20)

Language processing activity por Dhruv Sabalpara
Language processing activityLanguage processing activity
Language processing activity
Dhruv Sabalpara10.7K vistas
Compiler construction tools por Akhil Kaushik
Compiler construction toolsCompiler construction tools
Compiler construction tools
Akhil Kaushik1.3K vistas
basics of compiler design por Preeti Katiyar
basics of compiler designbasics of compiler design
basics of compiler design
Preeti Katiyar1.1K vistas
Fundamentals of Language Processing por Hemant Sharma
Fundamentals of Language ProcessingFundamentals of Language Processing
Fundamentals of Language Processing
Hemant Sharma21.8K vistas
Loaders ( system programming ) por Adarsh Patel
Loaders ( system programming ) Loaders ( system programming )
Loaders ( system programming )
Adarsh Patel18.6K vistas
Type checking por rawan_z
Type checkingType checking
Type checking
rawan_z5.1K vistas
Ll(1) Parser in Compilers por Mahbubur Rahman
Ll(1) Parser in CompilersLl(1) Parser in Compilers
Ll(1) Parser in Compilers
Mahbubur Rahman21.7K vistas
Code optimization in compiler design por Kuppusamy P
Code optimization in compiler designCode optimization in compiler design
Code optimization in compiler design
Kuppusamy P4.1K vistas
Error detection recovery por Tech_MX
Error detection recoveryError detection recovery
Error detection recovery
Tech_MX32.1K vistas
Parsing in Compiler Design por Akhil Kaushik
Parsing in Compiler DesignParsing in Compiler Design
Parsing in Compiler Design
Akhil Kaushik2.4K vistas
Compiler Design Lecture Notes por FellowBuddy.com
Compiler Design Lecture NotesCompiler Design Lecture Notes
Compiler Design Lecture Notes
FellowBuddy.com7.8K vistas
what is compiler and five phases of compiler por adilmehmood93
what is compiler and five phases of compilerwhat is compiler and five phases of compiler
what is compiler and five phases of compiler
adilmehmood939.2K vistas

Similar a Introduction to Compiler design

4_5802928814682016556.pptx por
4_5802928814682016556.pptx4_5802928814682016556.pptx
4_5802928814682016556.pptxAshenafiGirma5
18 vistas36 diapositivas
Cd ch1 - introduction por
Cd   ch1 - introductionCd   ch1 - introduction
Cd ch1 - introductionmengistu23
109 vistas36 diapositivas
Unit 1_Evaluation Criteria_session 3.pptx por
Unit 1_Evaluation Criteria_session 3.pptxUnit 1_Evaluation Criteria_session 3.pptx
Unit 1_Evaluation Criteria_session 3.pptxAsst.Prof. M.Gokilavani
27 vistas24 diapositivas
Chap01-Intro.ppt por
Chap01-Intro.pptChap01-Intro.ppt
Chap01-Intro.pptAhmadAbubaker16
4 vistas37 diapositivas
Compiler Design Introduction por
Compiler Design Introduction Compiler Design Introduction
Compiler Design Introduction Thapar Institute
39 vistas235 diapositivas
Introduction_to_Programming.pptx por
Introduction_to_Programming.pptxIntroduction_to_Programming.pptx
Introduction_to_Programming.pptxPmarkNorcio
13 vistas45 diapositivas

Similar a Introduction to Compiler design (20)

Cd ch1 - introduction por mengistu23
Cd   ch1 - introductionCd   ch1 - introduction
Cd ch1 - introduction
mengistu23109 vistas
Introduction_to_Programming.pptx por PmarkNorcio
Introduction_to_Programming.pptxIntroduction_to_Programming.pptx
Introduction_to_Programming.pptx
PmarkNorcio13 vistas
Compiler Design Introduction por Kuppusamy P
Compiler Design IntroductionCompiler Design Introduction
Compiler Design Introduction
Kuppusamy P167 vistas
Programming languages,compiler,interpreter,softwares por Nisarg Amin
Programming languages,compiler,interpreter,softwaresProgramming languages,compiler,interpreter,softwares
Programming languages,compiler,interpreter,softwares
Nisarg Amin2.5K vistas
Introduction to Compilers por Akhil Kaushik
Introduction to CompilersIntroduction to Compilers
Introduction to Compilers
Akhil Kaushik129 vistas
Compiler an overview por amudha arul
Compiler  an overviewCompiler  an overview
Compiler an overview
amudha arul239 vistas
Embedded c c++ programming fundamentals master por Hossam Hassan
Embedded c c++ programming fundamentals masterEmbedded c c++ programming fundamentals master
Embedded c c++ programming fundamentals master
Hossam Hassan6.6K vistas
Ch 1.pptx por woldu2
Ch 1.pptxCh 1.pptx
Ch 1.pptx
woldu27 vistas
Programming Paradigm & Languages por Gaditek
Programming Paradigm & LanguagesProgramming Paradigm & Languages
Programming Paradigm & Languages
Gaditek397 vistas
Programming Paradigm & Languages por Gaditek
Programming Paradigm & LanguagesProgramming Paradigm & Languages
Programming Paradigm & Languages
Gaditek3.4K vistas

Más de Dr. C.V. Suresh Babu

Data analytics with R por
Data analytics with RData analytics with R
Data analytics with RDr. C.V. Suresh Babu
843 vistas12 diapositivas
Association rules por
Association rulesAssociation rules
Association rulesDr. C.V. Suresh Babu
374 vistas6 diapositivas
Clustering por
ClusteringClustering
ClusteringDr. C.V. Suresh Babu
476 vistas12 diapositivas
Classification por
ClassificationClassification
ClassificationDr. C.V. Suresh Babu
208 vistas22 diapositivas
Blue property assumptions. por
Blue property assumptions.Blue property assumptions.
Blue property assumptions.Dr. C.V. Suresh Babu
5.4K vistas11 diapositivas
Introduction to regression por
Introduction to regressionIntroduction to regression
Introduction to regressionDr. C.V. Suresh Babu
267 vistas9 diapositivas

Más de Dr. C.V. Suresh Babu(20)

A study on “impact of artificial intelligence in covid19 diagnosis” por Dr. C.V. Suresh Babu
A study on “impact of artificial intelligence in covid19 diagnosis”A study on “impact of artificial intelligence in covid19 diagnosis”
A study on “impact of artificial intelligence in covid19 diagnosis”
A study on “impact of artificial intelligence in covid19 diagnosis” por Dr. C.V. Suresh Babu
A study on “impact of artificial intelligence in covid19 diagnosis”A study on “impact of artificial intelligence in covid19 diagnosis”
A study on “impact of artificial intelligence in covid19 diagnosis”

Último

Structure and Functions of Cell.pdf por
Structure and Functions of Cell.pdfStructure and Functions of Cell.pdf
Structure and Functions of Cell.pdfNithya Murugan
455 vistas10 diapositivas
Computer Introduction-Lecture06 por
Computer Introduction-Lecture06Computer Introduction-Lecture06
Computer Introduction-Lecture06Dr. Mazin Mohamed alkathiri
82 vistas12 diapositivas
Google solution challenge..pptx por
Google solution challenge..pptxGoogle solution challenge..pptx
Google solution challenge..pptxChitreshGyanani1
117 vistas18 diapositivas
Recap of our Class por
Recap of our ClassRecap of our Class
Recap of our ClassCorinne Weisgerber
74 vistas15 diapositivas
ICS3211_lecture 08_2023.pdf por
ICS3211_lecture 08_2023.pdfICS3211_lecture 08_2023.pdf
ICS3211_lecture 08_2023.pdfVanessa Camilleri
127 vistas30 diapositivas
Drama KS5 Breakdown por
Drama KS5 BreakdownDrama KS5 Breakdown
Drama KS5 BreakdownWestHatch
73 vistas2 diapositivas

Último(20)

Structure and Functions of Cell.pdf por Nithya Murugan
Structure and Functions of Cell.pdfStructure and Functions of Cell.pdf
Structure and Functions of Cell.pdf
Nithya Murugan455 vistas
Drama KS5 Breakdown por WestHatch
Drama KS5 BreakdownDrama KS5 Breakdown
Drama KS5 Breakdown
WestHatch73 vistas
AUDIENCE - BANDURA.pptx por iammrhaywood
AUDIENCE - BANDURA.pptxAUDIENCE - BANDURA.pptx
AUDIENCE - BANDURA.pptx
iammrhaywood77 vistas
7 NOVEL DRUG DELIVERY SYSTEM.pptx por Sachin Nitave
7 NOVEL DRUG DELIVERY SYSTEM.pptx7 NOVEL DRUG DELIVERY SYSTEM.pptx
7 NOVEL DRUG DELIVERY SYSTEM.pptx
Sachin Nitave59 vistas
Are we onboard yet University of Sussex.pptx por Jisc
Are we onboard yet University of Sussex.pptxAre we onboard yet University of Sussex.pptx
Are we onboard yet University of Sussex.pptx
Jisc93 vistas
EIT-Digital_Spohrer_AI_Intro 20231128 v1.pptx por ISSIP
EIT-Digital_Spohrer_AI_Intro 20231128 v1.pptxEIT-Digital_Spohrer_AI_Intro 20231128 v1.pptx
EIT-Digital_Spohrer_AI_Intro 20231128 v1.pptx
ISSIP359 vistas
OEB 2023 Co-learning To Speed Up AI Implementation in Courses.pptx por Inge de Waard
OEB 2023 Co-learning To Speed Up AI Implementation in Courses.pptxOEB 2023 Co-learning To Speed Up AI Implementation in Courses.pptx
OEB 2023 Co-learning To Speed Up AI Implementation in Courses.pptx
Inge de Waard169 vistas
Class 10 English notes 23-24.pptx por TARIQ KHAN
Class 10 English notes 23-24.pptxClass 10 English notes 23-24.pptx
Class 10 English notes 23-24.pptx
TARIQ KHAN125 vistas
Scope of Biochemistry.pptx por shoba shoba
Scope of Biochemistry.pptxScope of Biochemistry.pptx
Scope of Biochemistry.pptx
shoba shoba126 vistas
Community-led Open Access Publishing webinar.pptx por Jisc
Community-led Open Access Publishing webinar.pptxCommunity-led Open Access Publishing webinar.pptx
Community-led Open Access Publishing webinar.pptx
Jisc91 vistas
Narration ppt.pptx por TARIQ KHAN
Narration  ppt.pptxNarration  ppt.pptx
Narration ppt.pptx
TARIQ KHAN131 vistas
UWP OA Week Presentation (1).pptx por Jisc
UWP OA Week Presentation (1).pptxUWP OA Week Presentation (1).pptx
UWP OA Week Presentation (1).pptx
Jisc87 vistas

Introduction to Compiler design

  • 2. 2
  • 3. • Because computer can't understand the source code directly. It will understand only object level code. • Source codes are human readable format but the system cannot understand it. • So, the compiler is intermediate between human readable format and machine-readable format. 3
  • 4. 4 Topics • Introduction • Lexical analysis • Syntax analysis • Symbol tables
  • 5. 5 Language processing system To create an executable target program several programs may be required Collecting the source Program ( modules, macros, etc.) Assembly-language program
  • 6. 66 -In order to reduce the complexity of designing and building computers, nearly all of these are made to execute relatively simple commands (but do so very quickly). -A program for a computer must be built by combining these very simple commands into a program in what is called machine language. -Most programming is done using a high-level programming language -> But this language can be very different from the machine language that the computer can execute. ===>This is where the compiler comes in
  • 7. 7 • Using a high-level language for programming has a large impact on how fast programs can be developed: – Compared to machine language, the notation used by programming languages is closer to the way humans think about problems, – The compiler can spot some obvious programming mistakes, – Programs written in a high-level language tend to be shorter than equivalent programs written in machine language – The same program can be compiled to many different machine languages and, hence, be brought to run on many different machines.
  • 8. 8 A compiler translates a program written in a high-level programming language that is suitable for human programmers into the low-level machine language that is required by computers + spots and reports obvious programmer mistakes. 8 What’s a compiler ?
  • 9. 9 Running the target program • If the target program is an executable machine-language program, it can then be called by the user to process inputs and produce outputs. 9
  • 10. 10 What’s an interpreter ? • An interpreter is another way of implementing a programming language. • Interpretation shares many aspects with compiling (Lexing, parsing and type-checking)  But Instead of producing a target program as a translation, an interpreter appears to directly execute the operations specified in the source program on inputs supplied by the user 10
  • 11. 1111
  • 12. 12 The Structure of a Compiler 12
  • 13. 1313 Dividing into tokens (symbols : variable name, keyword or number) Producing a tree-structure that reflects the structure of the program. Determining if the program violates certain consistency requirements (if a variable is used but not declared, use a boolean value as a function pointer) Translating the intermediate language to assembly language (a textual representation of machine code) for a specific machine architecture. Translating the assembly-language code into binary representation and addresses of variables, functions are determined.
  • 14. 1414
  • 15. 15 Symbol Table Management - The symbol table is a data structure containing a record for each variable name, with fields for the attributes of the name (storage allocated for a name, its type, its scope where in the program its value may be used), and for procedure names (number and types of its arguments, the method of passing each argument and the type returned ). - The data structure should be designed to allow the compiler to find the record for each name quickly and to store or retrieve data from that record quickly. 15
  • 16. 16
  • 17. 17
  • 18. 18
  • 19. 19
  • 20. 20
  • 21. 21
  • 22. 22 Intermediate Code Generation In the process of translating a source program into target code, a compiler may construct one or more intermediate representations, which can have a variety of forms. It should be easy to produce It should be easy to translate into the target machine.
  • 23. 23 The machine-independent code-optimization phase attempts to improve the intermediate code so that better target code will result. faster shorter code target code that consumes less power Code Optimization
  • 24. 24 Code Generation The code generator takes as input an intermediate representation of the source program and maps it into the target language. A judicious assignment of registers to hold variables.
  • 25. 25 The Grouping o f Phases into Passes In an implementation, activities from several phases may be grouped together. - Front-end phases : {lexical analysis, syntax analysis, semantic analysis, and intermediate code generation }( one pass) - Back-end phases : {code generation, aspects of code optimization, error handling , symbol-table operations} N.B: Several phases of compilation are usually implemented in a single pass  Reading an input file and writing an output file.
  • 26. 26 Compiler- Construction Tools • The compiler writer, like any software developer, can profitably use modern software development environments containing tools such as language editors, debuggers, version managers , profilers, test harnesses, and so on. • In addition to these general software-development tools, other more specialized tools have been created to help implement various phases of a compiler.
  • 27. 27 Compiler-construction tools examples • Parser generators (to produce syntax analyzers) • Scanner generators (to generate automatically lexical analyzers) • Syntax-directed translation engines (producing routines that walk the parse tree) • Code-generator (taking rules that define the translation of each operation of the intermediate language into the machine language for the target machine) • Data-flow analysis engines ( optimizing code) • Compiler- construction toolkits
  • 28. 28 The Evolution of Programming Languages • The Move to Higher-level Languages •Impacts on Compile
  • 29. 29 The Science of Building a Compiler • Modeling in Compiler Design and Implementation • The Science of Code Optimization – Compiler optimizations must meet the following design objectives: • The optimization must be correct, that is, preserve the meaning of the compiled program, • The optimization must improve the performance of many programs, • The compilation time must be kept reasonable, and • The engineering effort required must be manageable.
  • 30. 30 Applications of Compiler Technology • Implementation of High-Level Programming Languages – The key ideas behind object orientation are • 1 . Data abstraction and • 2. Inheritance of properties, • Optimizations for Computer Architectures – Parallelism – Memory Hierarchies
  • 31. 31 • Design of New Computer Architectures – RISC – CISC – Specialized Architectures