SlideShare a Scribd company logo
Group 3
1. Piya Akter 37th
Batch
2. Rima Datta 36th
Batch
3. Shiren Akter 36th
Batch
4. Arman 36th
Batch
5. Md. Wasim 37th
Batch
Department of Computer Science & Engineering
The Subject of Discussion
The Role of lexical analyzer
Specification of tokens
Recognition of tokens
The Role of Lexical Analyzer
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.
The role of lexical analyzer
Why to separate Lexical analysis
and parsing
1. Simplicity of design
2. Improving compiler efficiency
3. Enhancing compiler portability
Lexical errors
Some errors are out of power of lexical analyzer to
recognize:
fi (a == f(x)) …
However it may be able to recognize errors like:
d = 2r
Such errors are recognized when no pattern for
tokens matches a character sequence
Error recovery
Panic mode: successive characters are ignored until
we reach to a well formed token
Delete one character from the remaining input
Insert a missing character into the remaining input
Replace a character by another character
Transpose two adjacent characters
Tokens
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.
Tokens Example
Token Informal description Sample lexemes
if
else
comparison
id
number
literal
Characters i, f
Characters e, l, s, e
< or > or <= or >= or == or !=
Letter followed by letter and digits
Any numeric constant
Anything but “ sorrounded by “
if
else
<=, !=
pi, score, D2
3.14159, 0, 6.02e23
“core dumped”
printf(“total = %dn”, score);
Specification of tokens
In theory of compilation regular expressions are used
to formalize the specification of tokens
Regular expressions are means for specifying regular
languages
Example:
 Letter_(letter_ | digit)*
Each regular expression is a pattern specifying the
form of strings
Regular expressions
Ɛ is a regular expression, L(Ɛ) = {Ɛ}
If a is a symbol in ∑then a is a regular expression, L(a)
= {a}
(r) | (s) is a regular expression denoting the language
L(r) ∪ L(s)
 (r)(s) is a regular expression denoting the language
L(r)L(s)
(r)* is a regular expression denoting (L9r))*
(r) is a regular expression denting L(r)
Regular definitions
d1 -> r1
d2 -> r2
…
dn -> rn
 Example:
letter_ -> A | B | … | Z | a | b | … | Z | _
digit -> 0 | 1 | … | 9
id -> letter_ (letter_ | digit)*
Recognition of tokens
Tokens can be recognized by Finite Automata A
Finite automaton(FA) is a simple idealized
machine used to recognize patterns within input
taken from some character set(or Alphabet) C.
The job of FA is to accept or reject an input
depending on whether the pattern defined by the
FA occurs in the input.
There are two notations for representing Finite
Automata. They are Transition Diagram
Transition Table
Recognition of tokens
Transition diagram is a directed labeled graph in
which it contains nodes and edges
Nodes represents the states and edges represents
the transition of a state
Every transition diagram is only one initial state
represented by an arrow mark (-->) and zero or
more final states are represented by double circle
Where state "1" is initial state and state 3 is final state.
Finite Automata for recognizing identifiers
The END
The END

More Related Content

PPTX
Language for specifying lexical Analyzer
PPTX
A simple approach of lexical analyzers
PPTX
Lecture 02 lexical analysis
PDF
Lexical Analysis - Compiler design
PPTX
Lexical analyzer
PDF
Compiler lec 8
PPT
Compier Design_Unit I_SRM.ppt
Language for specifying lexical Analyzer
A simple approach of lexical analyzers
Lecture 02 lexical analysis
Lexical Analysis - Compiler design
Lexical analyzer
Compiler lec 8
Compier Design_Unit I_SRM.ppt

What's hot (20)

PPT
Syntax analysis
PPTX
A Role of Lexical Analyzer
PPTX
Lexical analysis - Compiler Design
PPT
2_2Specification of Tokens.ppt
PDF
Lexical analysis
PPTX
Syntax Analysis in Compiler Design
PPT
Lexical Analysis
PPT
PDF
Lexical
PDF
Syntax analysis
PPTX
3. Lexical analysis
PDF
Syntactic analysis in NLP
PPT
02. chapter 3 lexical analysis
PPT
Syntax analysis
PPTX
Lexical analyzer
PPTX
role of lexical anaysis
PPT
Chapter Three(2)
PDF
Token, Pattern and Lexeme
PDF
Lecture4 lexical analysis2
PPT
Chapter Two(1)
Syntax analysis
A Role of Lexical Analyzer
Lexical analysis - Compiler Design
2_2Specification of Tokens.ppt
Lexical analysis
Syntax Analysis in Compiler Design
Lexical Analysis
Lexical
Syntax analysis
3. Lexical analysis
Syntactic analysis in NLP
02. chapter 3 lexical analysis
Syntax analysis
Lexical analyzer
role of lexical anaysis
Chapter Three(2)
Token, Pattern and Lexeme
Lecture4 lexical analysis2
Chapter Two(1)
Ad

Similar to Compiler Designs (20)

PPT
atc 3rd module compiler and automata.ppt
PPTX
Ch 2.pptx
PPT
Compiler Design ug semLexical Analysis.ppt
PPT
Chapter-2-lexical-analyser and its property lecture note.ppt
PPTX
Chahioiuou9oioooooooooooooofffghfpterTwo.pptx
PDF
3a. Context Free Grammar.pdf
DOC
Pcd question bank
PDF
Compilers Design
PPT
Lecture 1 - Lexical Analysis.ppt
PPTX
Lexical Analyser PPTs for Third Lease Computer Sc. and Engineering
PDF
Lexical analysis Compiler design pdf to read
PDF
Lexical analysis compiler design to read and study
PPT
1.Role lexical Analyzer
PPT
Lecturer-05 lex anylser (1).pptrjyghsgst
PDF
role of lexical parser compiler design1-181124035217.pdf
PPT
02. Chapter 3 - Lexical Analysis NLP.ppt
PPT
52232.-Compiler-Design-Lexical-Analysis.ppt
PPT
compiler Design course material chapter 2
PPT
Lexical Analysis
PPTX
Structure of the compiler
atc 3rd module compiler and automata.ppt
Ch 2.pptx
Compiler Design ug semLexical Analysis.ppt
Chapter-2-lexical-analyser and its property lecture note.ppt
Chahioiuou9oioooooooooooooofffghfpterTwo.pptx
3a. Context Free Grammar.pdf
Pcd question bank
Compilers Design
Lecture 1 - Lexical Analysis.ppt
Lexical Analyser PPTs for Third Lease Computer Sc. and Engineering
Lexical analysis Compiler design pdf to read
Lexical analysis compiler design to read and study
1.Role lexical Analyzer
Lecturer-05 lex anylser (1).pptrjyghsgst
role of lexical parser compiler design1-181124035217.pdf
02. Chapter 3 - Lexical Analysis NLP.ppt
52232.-Compiler-Design-Lexical-Analysis.ppt
compiler Design course material chapter 2
Lexical Analysis
Structure of the compiler
Ad

Recently uploaded (20)

PPT
chapter_1_a.ppthduushshwhwbshshshsbbsbsbsbsh
PPTX
Syllabus Computer Six class curriculum s
PPTX
title _yeOPC_Poisoning_Presentation.pptx
DOCX
fsdffdghjjgfxfdghjvhjvgfdfcbchghgghgcbjghf
PDF
-DIGITAL-INDIA.pdf one of the most prominent
PPTX
Sem-8 project ppt fortvfvmat uyyjhuj.pptx
PPTX
INFERTILITY (FEMALE FACTORS).pptxgvcghhfcg
PDF
Dynamic Checkweighers and Automatic Weighing Machine Solutions
PPTX
code of ethics.pptxdvhwbssssSAssscasascc
PPTX
KVL KCL ppt electrical electronics eee tiet
PPTX
Operating System Processes_Scheduler OSS
PPTX
Embedded for Artificial Intelligence 1.pptx
PDF
Cableado de Controladores Logicos Programables
PPTX
quadraticequations-111211090004-phpapp02.pptx
PPTX
Nanokeyer nano keyekr kano ketkker nano keyer
PDF
Smarter Security: How Door Access Control Works with Alarms & CCTV
PPTX
STEEL- intro-1.pptxhejwjenwnwnenemwmwmwm
PPTX
5. MEASURE OF INTERIOR AND EXTERIOR- MATATAG CURRICULUM.pptx
PPTX
Wireless and Mobile Backhaul Market.pptx
PPTX
Computers and mobile device: Evaluating options for home and work
chapter_1_a.ppthduushshwhwbshshshsbbsbsbsbsh
Syllabus Computer Six class curriculum s
title _yeOPC_Poisoning_Presentation.pptx
fsdffdghjjgfxfdghjvhjvgfdfcbchghgghgcbjghf
-DIGITAL-INDIA.pdf one of the most prominent
Sem-8 project ppt fortvfvmat uyyjhuj.pptx
INFERTILITY (FEMALE FACTORS).pptxgvcghhfcg
Dynamic Checkweighers and Automatic Weighing Machine Solutions
code of ethics.pptxdvhwbssssSAssscasascc
KVL KCL ppt electrical electronics eee tiet
Operating System Processes_Scheduler OSS
Embedded for Artificial Intelligence 1.pptx
Cableado de Controladores Logicos Programables
quadraticequations-111211090004-phpapp02.pptx
Nanokeyer nano keyekr kano ketkker nano keyer
Smarter Security: How Door Access Control Works with Alarms & CCTV
STEEL- intro-1.pptxhejwjenwnwnenemwmwmwm
5. MEASURE OF INTERIOR AND EXTERIOR- MATATAG CURRICULUM.pptx
Wireless and Mobile Backhaul Market.pptx
Computers and mobile device: Evaluating options for home and work

Compiler Designs

  • 1. Group 3 1. Piya Akter 37th Batch 2. Rima Datta 36th Batch 3. Shiren Akter 36th Batch 4. Arman 36th Batch 5. Md. Wasim 37th Batch Department of Computer Science & Engineering
  • 2. The Subject of Discussion The Role of lexical analyzer Specification of tokens Recognition of tokens
  • 3. The Role of Lexical Analyzer 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.
  • 4. The role of lexical analyzer
  • 5. Why to separate Lexical analysis and parsing 1. Simplicity of design 2. Improving compiler efficiency 3. Enhancing compiler portability
  • 6. Lexical errors Some errors are out of power of lexical analyzer to recognize: fi (a == f(x)) … However it may be able to recognize errors like: d = 2r Such errors are recognized when no pattern for tokens matches a character sequence
  • 7. Error recovery Panic mode: successive characters are ignored until we reach to a well formed token Delete one character from the remaining input Insert a missing character into the remaining input Replace a character by another character Transpose two adjacent characters
  • 8. Tokens 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.
  • 9. Tokens Example Token Informal description Sample lexemes if else comparison id number literal Characters i, f Characters e, l, s, e < or > or <= or >= or == or != Letter followed by letter and digits Any numeric constant Anything but “ sorrounded by “ if else <=, != pi, score, D2 3.14159, 0, 6.02e23 “core dumped” printf(“total = %dn”, score);
  • 10. Specification of tokens In theory of compilation regular expressions are used to formalize the specification of tokens Regular expressions are means for specifying regular languages Example:  Letter_(letter_ | digit)* Each regular expression is a pattern specifying the form of strings
  • 11. Regular expressions Ɛ is a regular expression, L(Ɛ) = {Ɛ} If a is a symbol in ∑then a is a regular expression, L(a) = {a} (r) | (s) is a regular expression denoting the language L(r) ∪ L(s)  (r)(s) is a regular expression denoting the language L(r)L(s) (r)* is a regular expression denoting (L9r))* (r) is a regular expression denting L(r)
  • 12. Regular definitions d1 -> r1 d2 -> r2 … dn -> rn  Example: letter_ -> A | B | … | Z | a | b | … | Z | _ digit -> 0 | 1 | … | 9 id -> letter_ (letter_ | digit)*
  • 13. Recognition of tokens Tokens can be recognized by Finite Automata A Finite automaton(FA) is a simple idealized machine used to recognize patterns within input taken from some character set(or Alphabet) C. The job of FA is to accept or reject an input depending on whether the pattern defined by the FA occurs in the input. There are two notations for representing Finite Automata. They are Transition Diagram Transition Table
  • 14. Recognition of tokens Transition diagram is a directed labeled graph in which it contains nodes and edges Nodes represents the states and edges represents the transition of a state Every transition diagram is only one initial state represented by an arrow mark (-->) and zero or more final states are represented by double circle Where state "1" is initial state and state 3 is final state. Finite Automata for recognizing identifiers