SlideShare a Scribd company logo
2
Most read
3
Most read
5
Most read
BY
S.SUDHAA
ASSISTANT PROFESSOR,
SELVAMM ARTS AND SCIENCE COLLEGE ,
NAMAKKAL
Structure of the compiler
 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>
 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.
 Intermediate Code Generation
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.
 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).
 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.
 It is a data-structure maintained throughout
all the phases of a compiler. All the
identifiers’ 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.
 Lexical analysis is the first phase of a compiler. It
takes the modified source code from language
preprocessors that are written in the form of
sentences. The lexical analyzer breaks these
syntaxes into a series of tokens, by removing any
whitespace or comments in the source code.
 If the lexical analyzer finds a token invalid, it
generates an error. The lexical analyzer works
closely with the syntax analyzer. It reads
character streams from the source code, checks
for legal tokens, and passes the data to the
syntax analyzer when it demands.
Structure of the compiler
 Lexemes are said to be a sequence of characters
(alphanumeric) in a token. There are some predefined
rules for every lexeme to be identified as a valid
token. These rules are defined by grammar rules, by
means of a pattern. A pattern explains what can be a
token, and these patterns are defined by means of
regular expressions.
 In programming language, keywords, constants,
identifiers, strings, numbers, operators, and
punctuations symbols can be considered as tokens.
 int value = 100;

For example, in C language, the variable declaration
line
 int value = 100;
contains the tokens:
 int (keyword), value (identifier), = (operator),
100 (constant) and ; (symbol).
Specifications of Tokens
 Let us understand how the language theory
undertakes the following terms:
Alphabets
 Any finite set of symbols {0,1} is a set of binary
alphabets, {0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F} is a
set of Hexadecimal alphabets, {a-z, A-Z} is a set
of English language alphabets.
 Any finite sequence of alphabets is called a
string. Length of the string is the total
number of occurrence of alphabets, e.g., the
length of the string A is 14 and is denoted by
 A = 14. A string having no alphabets, i.e. a
string of zero length is known as an empty
string and is denoted by ε (epsilon).
 A language is considered as a finite set of
strings over some finite set of alphabets.
Computer languages are considered as finite
sets, and mathematically set operations can
be performed on them. Finite languages can
be described by means of regular expressions
THANK
YOU…

More Related Content

PPTX
The Phases of a Compiler
PPT
Introduction to compiler
PPT
basics of compiler design
PPTX
Symbol table design (Compiler Construction)
PPT
Compiler Construction introduction
PDF
Parse Tree
PDF
Cs2303 theory of computation all anna University question papers
PPT
Code generator
The Phases of a Compiler
Introduction to compiler
basics of compiler design
Symbol table design (Compiler Construction)
Compiler Construction introduction
Parse Tree
Cs2303 theory of computation all anna University question papers
Code generator

What's hot (20)

PPTX
Phases of compiler
PPTX
Lexical Analysis - Compiler Design
PPT
Chapter 6 intermediate code generation
PPTX
Lexical analysis - Compiler Design
PPTX
Code generation
PPT
Intermediate code generation (Compiler Design)
PPT
phases of a compiler
PPT
Intermediate code generation
PDF
Formal Languages and Automata Theory Unit 1
PPTX
Top Down Parsing, Predictive Parsing
PPTX
Phases of Compiler
PPTX
Intermediate code generator
PPTX
A Role of Lexical Analyzer
PPT
Type Checking(Compiler Design) #ShareThisIfYouLike
PPTX
Loop optimization
PDF
Syntax analysis
PPTX
Syntax Analysis in Compiler Design
PDF
Syntax directed translation
PDF
Issues in the design of Code Generator
PPTX
Directed Acyclic Graph Representation of basic blocks
Phases of compiler
Lexical Analysis - Compiler Design
Chapter 6 intermediate code generation
Lexical analysis - Compiler Design
Code generation
Intermediate code generation (Compiler Design)
phases of a compiler
Intermediate code generation
Formal Languages and Automata Theory Unit 1
Top Down Parsing, Predictive Parsing
Phases of Compiler
Intermediate code generator
A Role of Lexical Analyzer
Type Checking(Compiler Design) #ShareThisIfYouLike
Loop optimization
Syntax analysis
Syntax Analysis in Compiler Design
Syntax directed translation
Issues in the design of Code Generator
Directed Acyclic Graph Representation of basic blocks
Ad

Similar to Structure of the compiler (20)

PPTX
role of lexical anaysis
PPT
Unit1.ppt
PPTX
Plc part 2
PPTX
Introduction to Compilers
PDF
An Introduction to the Compiler Designss
PPTX
Compiler Design Introduction With Design
PDF
compiler.pdfljdvgepitju4io3elkhldhyreyio4uw
DOCX
2-Design Issues, Patterns, Lexemes, Tokens-28-04-2023.docx
PPTX
ppt_cd.pptx ppt on phases of compiler of jntuk syllabus
PPTX
A Lecture of Compiler Design Subject.pptx
DOCX
Compiler Design
PDF
Compilers Design
PPTX
CD U1-5.pptx
PPT
Compiler Design in Computer Applications
PDF
Compiler_Lecture1.pdf
PPTX
Ss ui lecture 2
PPT
SS & CD Module 3
PPT
Module 2
PDF
Chapter#01 cc
PPTX
1._Introduction_.pptx
role of lexical anaysis
Unit1.ppt
Plc part 2
Introduction to Compilers
An Introduction to the Compiler Designss
Compiler Design Introduction With Design
compiler.pdfljdvgepitju4io3elkhldhyreyio4uw
2-Design Issues, Patterns, Lexemes, Tokens-28-04-2023.docx
ppt_cd.pptx ppt on phases of compiler of jntuk syllabus
A Lecture of Compiler Design Subject.pptx
Compiler Design
Compilers Design
CD U1-5.pptx
Compiler Design in Computer Applications
Compiler_Lecture1.pdf
Ss ui lecture 2
SS & CD Module 3
Module 2
Chapter#01 cc
1._Introduction_.pptx
Ad

More from Sudhaa Ravi (6)

PPTX
PPTX
Compiler design slide share
PDF
Ijsrdv9 i20118
PPTX
Fundamental of computer
PPTX
Classification of computers
PPTX
Compiler design slide share
Ijsrdv9 i20118
Fundamental of computer
Classification of computers

Recently uploaded (20)

PDF
O7-L3 Supply Chain Operations - ICLT Program
PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
A systematic review of self-coping strategies used by university students to ...
PPTX
GDM (1) (1).pptx small presentation for students
PDF
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
PDF
Microbial disease of the cardiovascular and lymphatic systems
PDF
VCE English Exam - Section C Student Revision Booklet
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PPTX
Pharma ospi slides which help in ospi learning
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
Yogi Goddess Pres Conference Studio Updates
PDF
01-Introduction-to-Information-Management.pdf
PDF
Anesthesia in Laparoscopic Surgery in India
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
RMMM.pdf make it easy to upload and study
PDF
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
Computing-Curriculum for Schools in Ghana
PDF
Trump Administration's workforce development strategy
O7-L3 Supply Chain Operations - ICLT Program
202450812 BayCHI UCSC-SV 20250812 v17.pptx
Supply Chain Operations Speaking Notes -ICLT Program
A systematic review of self-coping strategies used by university students to ...
GDM (1) (1).pptx small presentation for students
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
Microbial disease of the cardiovascular and lymphatic systems
VCE English Exam - Section C Student Revision Booklet
Final Presentation General Medicine 03-08-2024.pptx
Pharma ospi slides which help in ospi learning
FourierSeries-QuestionsWithAnswers(Part-A).pdf
Yogi Goddess Pres Conference Studio Updates
01-Introduction-to-Information-Management.pdf
Anesthesia in Laparoscopic Surgery in India
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
RMMM.pdf make it easy to upload and study
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Computing-Curriculum for Schools in Ghana
Trump Administration's workforce development strategy

Structure of the compiler

  • 1. BY S.SUDHAA ASSISTANT PROFESSOR, SELVAMM ARTS AND SCIENCE COLLEGE , NAMAKKAL
  • 3.  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>
  • 4.  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.
  • 5.  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.
  • 6.  Intermediate Code Generation 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.
  • 7.  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).
  • 8.  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.
  • 9.  It is a data-structure maintained throughout all the phases of a compiler. All the identifiers’ 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.
  • 10.  Lexical analysis is the first phase of a compiler. It takes the modified source code from language preprocessors that are written in the form of sentences. The lexical analyzer breaks these syntaxes into a series of tokens, by removing any whitespace or comments in the source code.  If the lexical analyzer finds a token invalid, it generates an error. The lexical analyzer works closely with the syntax analyzer. It reads character streams from the source code, checks for legal tokens, and passes the data to the syntax analyzer when it demands.
  • 12.  Lexemes are said to be a sequence of characters (alphanumeric) in a token. There are some predefined rules for every lexeme to be identified as a valid token. These rules are defined by grammar rules, by means of a pattern. A pattern explains what can be a token, and these patterns are defined by means of regular expressions.  In programming language, keywords, constants, identifiers, strings, numbers, operators, and punctuations symbols can be considered as tokens.  int value = 100;  For example, in C language, the variable declaration line
  • 13.  int value = 100; contains the tokens:  int (keyword), value (identifier), = (operator), 100 (constant) and ; (symbol). Specifications of Tokens  Let us understand how the language theory undertakes the following terms: Alphabets  Any finite set of symbols {0,1} is a set of binary alphabets, {0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F} is a set of Hexadecimal alphabets, {a-z, A-Z} is a set of English language alphabets.
  • 14.  Any finite sequence of alphabets is called a string. Length of the string is the total number of occurrence of alphabets, e.g., the length of the string A is 14 and is denoted by  A = 14. A string having no alphabets, i.e. a string of zero length is known as an empty string and is denoted by ε (epsilon).
  • 15.  A language is considered as a finite set of strings over some finite set of alphabets. Computer languages are considered as finite sets, and mathematically set operations can be performed on them. Finite languages can be described by means of regular expressions