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

PPTX
Assembly and Machine Code
PPTX
Interfacing With High Level Programming Language
PPT
Machine language
PPT
Language translator
PPTX
Interpreter
PPTX
Compiler vs Interpreter-Compiler design ppt.
PPTX
Programming Languages / Translators
PPT
Computer languages
Assembly and Machine Code
Interfacing With High Level Programming Language
Machine language
Language translator
Interpreter
Compiler vs Interpreter-Compiler design ppt.
Programming Languages / Translators
Computer languages

What's hot (20)

PPTX
BASIC Programming Language
PPTX
Chapter 5
PPTX
Features of machine language, assembly language, high level language & their ...
PPTX
Computer programming languages
PPT
Computer languages 11
PPTX
FIT-Unit3 chapter2- Computer Languages
PPTX
History of Programming Language
DOC
PDF
Assignment on basic programming language
PPSX
Programming languages
PPT
La 5 Pl Translator
PPT
What is Compiler?
PPTX
Rajesh ppt
PPTX
Language Translator ( Compiler)
PPTX
High Level Language (HLL)
PPTX
Programming languages,compiler,interpreter,softwares
PPT
software development and programming languages
PPTX
Computer Language Translator
PPTX
Programming languages
BASIC Programming Language
Chapter 5
Features of machine language, assembly language, high level language & their ...
Computer programming languages
Computer languages 11
FIT-Unit3 chapter2- Computer Languages
History of Programming Language
Assignment on basic programming language
Programming languages
La 5 Pl Translator
What is Compiler?
Rajesh ppt
Language Translator ( Compiler)
High Level Language (HLL)
Programming languages,compiler,interpreter,softwares
software development and programming languages
Computer Language Translator
Programming languages
Ad

Similar to Introduction to compiler development (20)

PDF
2 Programming Language.pdf
PDF
Compiler_Lecture1.pdf
PPTX
Chapter 2 Program language translation.pptx
PDF
Chapter1.pdf
PPTX
computerprogramminglanguages-201216152310.pptx
PDF
Language translators
PPTX
Insight into progam execution ppt
PPTX
Compiler design slide share
PPTX
Chapter 1 Introduction.pptxhjgjghjghjhjhjhgjmjkhgk
DOC
Assembler
PPTX
Unit2_CD.pptx more about compilation of the day
PDF
Unit 1
PPTX
Compiler Construction Lecture One .pptx
PPTX
Software programming and development
PPT
basics of compiler design
PPTX
Introduction to Programming Concepts By Aamir Saleem Ansari
PPTX
Chapter 1.pptx compiler design lecture note
PDF
Introduction to computer programming
PPTX
COMPILER DESIGN OPTIONS
PPTX
1. C_Introductionnnnnnnnnnnnnnnnnnnnn.pptx
2 Programming Language.pdf
Compiler_Lecture1.pdf
Chapter 2 Program language translation.pptx
Chapter1.pdf
computerprogramminglanguages-201216152310.pptx
Language translators
Insight into progam execution ppt
Compiler design slide share
Chapter 1 Introduction.pptxhjgjghjghjhjhjhgjmjkhgk
Assembler
Unit2_CD.pptx more about compilation of the day
Unit 1
Compiler Construction Lecture One .pptx
Software programming and development
basics of compiler design
Introduction to Programming Concepts By Aamir Saleem Ansari
Chapter 1.pptx compiler design lecture note
Introduction to computer programming
COMPILER DESIGN OPTIONS
1. C_Introductionnnnnnnnnnnnnnnnnnnnn.pptx
Ad

Recently uploaded (20)

PDF
AI.gov: A Trojan Horse in the Age of Artificial Intelligence
PDF
Introduction to c language from lecture slides
PPTX
Build automations faster and more reliably with UiPath ScreenPlay
PDF
Internet of Things (IoT) – Definition, Types, and Uses
PDF
Connector Corner: Transform Unstructured Documents with Agentic Automation
PPT
Storage Area Network Best Practices from HP
PDF
Ebook - The Future of AI A Comprehensive Guide.pdf
PPTX
Information-Technology-in-Human-Society (2).pptx
PPTX
maintenance powerrpoint for adaprive and preventive
PDF
CCUS-as-the-Missing-Link-to-Net-Zero_AksCurious.pdf
PDF
Fitaura: AI & Machine Learning Powered Fitness Tracker
PDF
CEH Module 2 Footprinting CEH V13, concepts
PPTX
From XAI to XEE through Influence and Provenance.Controlling model fairness o...
PPTX
How to Convert Tickets Into Sales Opportunity in Odoo 18
PPTX
Rise of the Digital Control Grid Zeee Media and Hope and Tivon FTWProject.com
PDF
Introduction to MCP and A2A Protocols: Enabling Agent Communication
PDF
Intravenous drug administration application for pediatric patients via augmen...
PPTX
CRM(Customer Relationship Managmnet) Presentation
PDF
Optimizing bioinformatics applications: a novel approach with human protein d...
PDF
Decision Optimization - From Theory to Practice
AI.gov: A Trojan Horse in the Age of Artificial Intelligence
Introduction to c language from lecture slides
Build automations faster and more reliably with UiPath ScreenPlay
Internet of Things (IoT) – Definition, Types, and Uses
Connector Corner: Transform Unstructured Documents with Agentic Automation
Storage Area Network Best Practices from HP
Ebook - The Future of AI A Comprehensive Guide.pdf
Information-Technology-in-Human-Society (2).pptx
maintenance powerrpoint for adaprive and preventive
CCUS-as-the-Missing-Link-to-Net-Zero_AksCurious.pdf
Fitaura: AI & Machine Learning Powered Fitness Tracker
CEH Module 2 Footprinting CEH V13, concepts
From XAI to XEE through Influence and Provenance.Controlling model fairness o...
How to Convert Tickets Into Sales Opportunity in Odoo 18
Rise of the Digital Control Grid Zeee Media and Hope and Tivon FTWProject.com
Introduction to MCP and A2A Protocols: Enabling Agent Communication
Intravenous drug administration application for pediatric patients via augmen...
CRM(Customer Relationship Managmnet) Presentation
Optimizing bioinformatics applications: a novel approach with human protein d...
Decision Optimization - From Theory to Practice

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