SlideShare a Scribd company logo
INTRODUCTION
TO COMPILER
DEVELOPMENT
Compiler Construction
PRESENTED BY
PRESENTED BY
PRESENTED BY
D E E P
C S - E 1 9 - 0 1 5
WHAT IS COMPILER
A compiler is a special program that processes statements written in a
particular programming language and turns them into machine language or
"code" that a computer's processor uses. Typically, a programmer writes
language statements in a language such as C++ or C one line at a time using
an editor. The file that is created contains what are called the source
statements. The programmer then runs the appropriate language compiler,
specifying the name of the file that contains the source statements.
Towards the end of the 1950s, machine-independent programming
languages were first proposed. Subsequently, several experimental
compilers were developed. The first compiler was written by Grace
Hopper, in 1952, for the A-0 programming language. The FORTRAN team
led by John Backus at IBM is generally credited as having introduced the
first complete compiler in 1957. COBOL was an early language to be
compiled on multiple architectures, in 1960
HISTORY OF COMPILER
WHY DO WE NEED A
COMPILER?
A Computer understands only binary language and executes instructions
coded in binary language. It cannot execute a single instruction given in any
other form. Therefore, we must provide instructions to the computer in binary
language. Means we must write computer programs entirely in binary
language (sequence of 0s and 1s). So, there was a need of a translator that
translates the computer instructions given in English language to binary
language.
Computers do not understand human languages. In fact, at the lowest
level, computers only understand sequences of numbers that represent
operational codes (op codes for short). On the other hand, it would be very
difficult for humans to write programs in terms of op codes. Therefore,
programming languages were invented to make it easier for humans to
write computer programs.
Programming languages are for humans to read and understand. The
program (source code) must be translated into machine language so that
the computer can execute the program (as the computer only
understands machine language). The way that this translation occurs
depends on whether the programming language is a compiled language
or an interpreted language.
HOW COMPILER WORKS
WORK OF PHASES
The compilation process is a sequence of
various phases. Each phase takes input
from its previous stage, has its own
representation of source program, and
feeds its output to the next phase of the
compiler. Let us understand the phases
of a compiler.
HOW COMPILER WORK
THROUGH ITS PHASES
LEXICAL ANALYSIS


The first phase of scanner works as a text scanner. This phase scans the
source code as a stream of characters and converts it into meaningful
lexemes. Lexical analyzer represents these lexemes in the form of tokens
as:
<token-name, attribute-value>
#include <iostream>
int main() {
cout << "Hello World!";
return 0;
}
HELLO WORLD PROGRAM
SYNTAX ANALYSIS
The next phase is called the syntax analysis or
parsing. It takes the token produced by lexical
analysis as input and generates a parse tree (or
syntax tree). In this phase, token arrangements are
checked against the source code grammar, i.e. the
parser checks if the expression made by the
tokens is syntactically correct.
SEMANTIC
ANALYSIS Semantic analysis checks whether the parse tree
constructed follows the rules of language. For
example, assignment of values is between
compatible data types, and adding string to an
integer. Also, the semantic analyzer keeps track of
identifiers, their types and expressions; whether
identifiers are declared before use or not etc. The
semantic analyzer produces an annotated syntax
tree as an output.
After semantic analysis, the compiler generates an
intermediate code of the source code for the target machine.
It represents a program for some abstract machine. It is in
between the high-level language and the machine language.
This intermediate code should be generated in such a way
that it makes it easier to be translated into the target machine
code.
INTERMEDIATE CODE GENERATION
CODE OPTIMIZATION


THE NEXT PHASE DOES CODE OPTIMIZATION OF THE
INTERMEDIATE CODE. OPTIMIZATION CAN BE ASSUMED
AS SOMETHING THAT REMOVES UNNECESSARY CODE
LINES, AND ARRANGES THE SEQUENCE OF STATEMENTS
IN ORDER TO SPEED UP THE PROGRAM EXECUTION
WITHOUT WASTING RESOURCES (CPU, MEMORY).
CODE GENERATION


IN THIS PHASE, THE CODE GENERATOR TAKES THE
OPTIMIZED REPRESENTATION OF THE INTERMEDIATE
CODE AND MAPS IT TO THE TARGET MACHINE
LANGUAGE. THE CODE GENERATOR TRANSLATES THE
INTERMEDIATE CODE INTO A SEQUENCE OF (GENERALLY)
RE-LOCATABLE MACHINE CODE. SEQUENCE OF
INSTRUCTIONS OF MACHINE CODE PERFORMS THE TASK
AS THE INTERMEDIATE CODE WOULD DO.
SYMBOL TABLE


IT IS A DATA-STRUCTURE MAINTAINED THROUGHOUT ALL
THE PHASES OF A COMPILER. ALL THE IDENTIFIER'S
NAMES ALONG WITH THEIR TYPES ARE STORED HERE.
THE SYMBOL TABLE MAKES IT EASIER FOR THE
COMPILER TO QUICKLY SEARCH THE IDENTIFIER RECORD
AND RETRIEVE IT. THE SYMBOL TABLE IS ALSO USED
FOR SCOPE MANAGEMENT.
Thank you
Q&A YOU MAY ASK

More Related Content

What's hot

Features of machine language, assembly language, high level language & their ...
Features of machine language, assembly language, high level language & their ...Features of machine language, assembly language, high level language & their ...
Features of machine language, assembly language, high level language & their ...
SHUBHAM PATIDAR FISHERIES ADDAA
 
Programming languages
Programming languagesProgramming languages
Programming languages
vito_carleone
 
La 5 Pl Translator
La 5   Pl TranslatorLa 5   Pl Translator
La 5 Pl Translator
Cma Mohd
 
Programming languages
Programming languagesProgramming languages
Programming languages
Akash Varaiya
 

What's hot (20)

BASIC Programming Language
BASIC Programming LanguageBASIC Programming Language
BASIC Programming Language
 
Chapter 5
Chapter 5Chapter 5
Chapter 5
 
Features of machine language, assembly language, high level language & their ...
Features of machine language, assembly language, high level language & their ...Features of machine language, assembly language, high level language & their ...
Features of machine language, assembly language, high level language & their ...
 
Computer programming languages
Computer programming languagesComputer programming languages
Computer programming languages
 
Computer languages 11
Computer languages 11Computer languages 11
Computer languages 11
 
FIT-Unit3 chapter2- Computer Languages
FIT-Unit3 chapter2- Computer LanguagesFIT-Unit3 chapter2- Computer Languages
FIT-Unit3 chapter2- Computer Languages
 
History of Programming Language
History of Programming LanguageHistory of Programming Language
History of Programming Language
 
compiler vs interpreter
compiler vs interpretercompiler vs interpreter
compiler vs interpreter
 
Assignment on basic programming language
Assignment on  basic programming languageAssignment on  basic programming language
Assignment on basic programming language
 
LANGUAGE TRANSLATOR
LANGUAGE TRANSLATORLANGUAGE TRANSLATOR
LANGUAGE TRANSLATOR
 
Programming languages
Programming languagesProgramming languages
Programming languages
 
La 5 Pl Translator
La 5   Pl TranslatorLa 5   Pl Translator
La 5 Pl Translator
 
What is Compiler?
What is Compiler?What is Compiler?
What is Compiler?
 
Rajesh ppt
Rajesh pptRajesh ppt
Rajesh ppt
 
Language Translator ( Compiler)
Language Translator ( Compiler)Language Translator ( Compiler)
Language Translator ( Compiler)
 
High Level Language (HLL)
High Level Language (HLL)High Level Language (HLL)
High Level Language (HLL)
 
Programming languages,compiler,interpreter,softwares
Programming languages,compiler,interpreter,softwaresProgramming languages,compiler,interpreter,softwares
Programming languages,compiler,interpreter,softwares
 
software development and programming languages
software development and programming languages software development and programming languages
software development and programming languages
 
Computer Language Translator
Computer Language TranslatorComputer Language Translator
Computer Language Translator
 
Programming languages
Programming languagesProgramming languages
Programming languages
 

Similar to Introduction to compiler development

Language translators
Language translatorsLanguage translators
Language translators
Aditya Sharat
 
Compiler Construction Lecture One .pptx
Compiler Construction Lecture One  .pptxCompiler Construction Lecture One  .pptx
Compiler Construction Lecture One .pptx
انشال عارف
 
Introduction to Programming Concepts By Aamir Saleem Ansari
Introduction to Programming Concepts By Aamir Saleem AnsariIntroduction to Programming Concepts By Aamir Saleem Ansari
Introduction to Programming Concepts By Aamir Saleem Ansari
Tech
 
Basic programming concepts
Basic programming conceptsBasic programming concepts
Basic programming concepts
salmankhan570
 

Similar to Introduction to compiler development (20)

2 Programming Language.pdf
2 Programming Language.pdf2 Programming Language.pdf
2 Programming Language.pdf
 
Compiler_Lecture1.pdf
Compiler_Lecture1.pdfCompiler_Lecture1.pdf
Compiler_Lecture1.pdf
 
Chapter 2 Program language translation.pptx
Chapter 2 Program language translation.pptxChapter 2 Program language translation.pptx
Chapter 2 Program language translation.pptx
 
Chapter1.pdf
Chapter1.pdfChapter1.pdf
Chapter1.pdf
 
computerprogramminglanguages-201216152310.pptx
computerprogramminglanguages-201216152310.pptxcomputerprogramminglanguages-201216152310.pptx
computerprogramminglanguages-201216152310.pptx
 
Language translators
Language translatorsLanguage translators
Language translators
 
Insight into progam execution ppt
Insight into progam execution pptInsight into progam execution ppt
Insight into progam execution ppt
 
Compiler design slide share
Compiler design slide shareCompiler design slide share
Compiler design slide share
 
Assembler
AssemblerAssembler
Assembler
 
Unit 1
Unit 1Unit 1
Unit 1
 
Compiler Construction Lecture One .pptx
Compiler Construction Lecture One  .pptxCompiler Construction Lecture One  .pptx
Compiler Construction Lecture One .pptx
 
Software programming and development
Software programming and developmentSoftware programming and development
Software programming and development
 
basics of compiler design
basics of compiler designbasics of compiler design
basics of compiler design
 
Introduction to Programming Concepts By Aamir Saleem Ansari
Introduction to Programming Concepts By Aamir Saleem AnsariIntroduction to Programming Concepts By Aamir Saleem Ansari
Introduction to Programming Concepts By Aamir Saleem Ansari
 
Introduction to computer programming
Introduction to computer programmingIntroduction to computer programming
Introduction to computer programming
 
COMPILER DESIGN OPTIONS
COMPILER DESIGN OPTIONSCOMPILER DESIGN OPTIONS
COMPILER DESIGN OPTIONS
 
COMPILER DESIGN.docx
COMPILER DESIGN.docxCOMPILER DESIGN.docx
COMPILER DESIGN.docx
 
df
dfdf
df
 
Chapter#01 cc
Chapter#01 ccChapter#01 cc
Chapter#01 cc
 
Basic programming concepts
Basic programming conceptsBasic programming concepts
Basic programming concepts
 

Recently uploaded

Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 

Recently uploaded (20)

JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
UiPath Test Automation using UiPath Test Suite series, part 2
UiPath Test Automation using UiPath Test Suite series, part 2UiPath Test Automation using UiPath Test Suite series, part 2
UiPath Test Automation using UiPath Test Suite series, part 2
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
IoT Analytics Company Presentation May 2024
IoT Analytics Company Presentation May 2024IoT Analytics Company Presentation May 2024
IoT Analytics Company Presentation May 2024
 
UiPath Test Automation using UiPath Test Suite series, part 1
UiPath Test Automation using UiPath Test Suite series, part 1UiPath Test Automation using UiPath Test Suite series, part 1
UiPath Test Automation using UiPath Test Suite series, part 1
 
НАДІЯ ФЕДЮШКО БАЦ «Професійне зростання QA спеціаліста»
НАДІЯ ФЕДЮШКО БАЦ  «Професійне зростання QA спеціаліста»НАДІЯ ФЕДЮШКО БАЦ  «Професійне зростання QA спеціаліста»
НАДІЯ ФЕДЮШКО БАЦ «Професійне зростання QA спеціаліста»
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptxUnpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
 
Demystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John StaveleyDemystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John Staveley
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 

Introduction to compiler development

  • 1. INTRODUCTION TO COMPILER DEVELOPMENT Compiler Construction PRESENTED BY PRESENTED BY PRESENTED BY D E E P C S - E 1 9 - 0 1 5
  • 2. WHAT IS COMPILER A compiler is a special program that processes statements written in a particular programming language and turns them into machine language or "code" that a computer's processor uses. Typically, a programmer writes language statements in a language such as C++ or C one line at a time using an editor. The file that is created contains what are called the source statements. The programmer then runs the appropriate language compiler, specifying the name of the file that contains the source statements.
  • 3. Towards the end of the 1950s, machine-independent programming languages were first proposed. Subsequently, several experimental compilers were developed. The first compiler was written by Grace Hopper, in 1952, for the A-0 programming language. The FORTRAN team led by John Backus at IBM is generally credited as having introduced the first complete compiler in 1957. COBOL was an early language to be compiled on multiple architectures, in 1960 HISTORY OF COMPILER
  • 4. WHY DO WE NEED A COMPILER? A Computer understands only binary language and executes instructions coded in binary language. It cannot execute a single instruction given in any other form. Therefore, we must provide instructions to the computer in binary language. Means we must write computer programs entirely in binary language (sequence of 0s and 1s). So, there was a need of a translator that translates the computer instructions given in English language to binary language.
  • 5. Computers do not understand human languages. In fact, at the lowest level, computers only understand sequences of numbers that represent operational codes (op codes for short). On the other hand, it would be very difficult for humans to write programs in terms of op codes. Therefore, programming languages were invented to make it easier for humans to write computer programs. Programming languages are for humans to read and understand. The program (source code) must be translated into machine language so that the computer can execute the program (as the computer only understands machine language). The way that this translation occurs depends on whether the programming language is a compiled language or an interpreted language. HOW COMPILER WORKS
  • 6. WORK OF PHASES The compilation process is a sequence of various phases. Each phase takes input from its previous stage, has its own representation of source program, and feeds its output to the next phase of the compiler. Let us understand the phases of a compiler. HOW COMPILER WORK THROUGH ITS PHASES
  • 7. LEXICAL ANALYSIS The first phase of scanner works as a text scanner. This phase scans the source code as a stream of characters and converts it into meaningful lexemes. Lexical analyzer represents these lexemes in the form of tokens as: <token-name, attribute-value>
  • 8. #include <iostream> int main() { cout << "Hello World!"; return 0; } HELLO WORLD PROGRAM
  • 9. SYNTAX ANALYSIS The next phase is called the syntax analysis or parsing. It takes the token produced by lexical analysis as input and generates a parse tree (or syntax tree). In this phase, token arrangements are checked against the source code grammar, i.e. the parser checks if the expression made by the tokens is syntactically correct.
  • 10. SEMANTIC ANALYSIS Semantic analysis checks whether the parse tree constructed follows the rules of language. For example, assignment of values is between compatible data types, and adding string to an integer. Also, the semantic analyzer keeps track of identifiers, their types and expressions; whether identifiers are declared before use or not etc. The semantic analyzer produces an annotated syntax tree as an output.
  • 11. After semantic analysis, the compiler generates an intermediate code of the source code for the target machine. It represents a program for some abstract machine. It is in between the high-level language and the machine language. This intermediate code should be generated in such a way that it makes it easier to be translated into the target machine code. INTERMEDIATE CODE GENERATION
  • 12. CODE OPTIMIZATION THE NEXT PHASE DOES CODE OPTIMIZATION OF THE INTERMEDIATE CODE. OPTIMIZATION CAN BE ASSUMED AS SOMETHING THAT REMOVES UNNECESSARY CODE LINES, AND ARRANGES THE SEQUENCE OF STATEMENTS IN ORDER TO SPEED UP THE PROGRAM EXECUTION WITHOUT WASTING RESOURCES (CPU, MEMORY).
  • 13. CODE GENERATION IN THIS PHASE, THE CODE GENERATOR TAKES THE OPTIMIZED REPRESENTATION OF THE INTERMEDIATE CODE AND MAPS IT TO THE TARGET MACHINE LANGUAGE. THE CODE GENERATOR TRANSLATES THE INTERMEDIATE CODE INTO A SEQUENCE OF (GENERALLY) RE-LOCATABLE MACHINE CODE. SEQUENCE OF INSTRUCTIONS OF MACHINE CODE PERFORMS THE TASK AS THE INTERMEDIATE CODE WOULD DO.
  • 14. SYMBOL TABLE IT IS A DATA-STRUCTURE MAINTAINED THROUGHOUT ALL THE PHASES OF A COMPILER. ALL THE IDENTIFIER'S NAMES ALONG WITH THEIR TYPES ARE STORED HERE. THE SYMBOL TABLE MAKES IT EASIER FOR THE COMPILER TO QUICKLY SEARCH THE IDENTIFIER RECORD AND RETRIEVE IT. THE SYMBOL TABLE IS ALSO USED FOR SCOPE MANAGEMENT.
  • 15. Thank you Q&A YOU MAY ASK