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

What's hot (20)

PPT
Syntax analysis
Chetan Mahawar
 
PPTX
A Role of Lexical Analyzer
Archana Gopinath
 
PPTX
Lexical analysis - Compiler Design
Muhammed Afsal Villan
 
PPT
2_2Specification of Tokens.ppt
Ratnakar Mikkili
 
PDF
Lexical analysis
Richa Sharma
 
PPTX
Syntax Analysis in Compiler Design
MAHASREEM
 
PPT
Lexical Analysis
Nayemid4676
 
PPT
Parsing
jayashri kolekar
 
PDF
Lexical
baran19901990
 
PDF
Syntax analysis
Akshaya Arunan
 
PPTX
3. Lexical analysis
Saeed Parsa
 
PDF
Syntactic analysis in NLP
kartikaVashisht
 
PPT
02. chapter 3 lexical analysis
raosir123
 
PPT
Syntax analysis
Binsent Ribera
 
PPTX
Lexical analyzer
Farzana Aktar
 
PPTX
role of lexical anaysis
Sudhaa Ravi
 
PPT
Chapter Three(2)
bolovv
 
PDF
Token, Pattern and Lexeme
A. S. M. Shafi
 
PDF
Lecture4 lexical analysis2
Mahesh Kumar Chelimilla
 
PPT
Chapter Two(1)
bolovv
 
Syntax analysis
Chetan Mahawar
 
A Role of Lexical Analyzer
Archana Gopinath
 
Lexical analysis - Compiler Design
Muhammed Afsal Villan
 
2_2Specification of Tokens.ppt
Ratnakar Mikkili
 
Lexical analysis
Richa Sharma
 
Syntax Analysis in Compiler Design
MAHASREEM
 
Lexical Analysis
Nayemid4676
 
Lexical
baran19901990
 
Syntax analysis
Akshaya Arunan
 
3. Lexical analysis
Saeed Parsa
 
Syntactic analysis in NLP
kartikaVashisht
 
02. chapter 3 lexical analysis
raosir123
 
Syntax analysis
Binsent Ribera
 
Lexical analyzer
Farzana Aktar
 
role of lexical anaysis
Sudhaa Ravi
 
Chapter Three(2)
bolovv
 
Token, Pattern and Lexeme
A. S. M. Shafi
 
Lecture4 lexical analysis2
Mahesh Kumar Chelimilla
 
Chapter Two(1)
bolovv
 

Similar to Compiler Designs (20)

PPT
atc 3rd module compiler and automata.ppt
ranjan317165
 
PPTX
Ch 2.pptx
woldu2
 
PPT
Compiler Design ug semLexical Analysis.ppt
ssuser6ba09a
 
PPTX
Chahioiuou9oioooooooooooooofffghfpterTwo.pptx
dejenehundaol91
 
PDF
3a. Context Free Grammar.pdf
TANZINTANZINA
 
DOC
Pcd question bank
Sumathi Gnanasekaran
 
PDF
Compilers Design
Akshaya Arunan
 
PPT
Lecture 1 - Lexical Analysis.ppt
NderituGichuki1
 
PPTX
Lexical Analyser PPTs for Third Lease Computer Sc. and Engineering
DrRajurkarArchanaMil
 
PDF
Lexical analysis Compiler design pdf to read
shubhamsingaal
 
PDF
Lexical analysis compiler design to read and study
shubhamsingaal
 
PPT
1.Role lexical Analyzer
Radhakrishnan Chinnusamy
 
PPT
Lecturer-05 lex anylser (1).pptrjyghsgst
engrsheikhmuhammadha
 
PDF
role of lexical parser compiler design1-181124035217.pdf
ranjan317165
 
PPT
02. Chapter 3 - Lexical Analysis NLP.ppt
charvivij
 
PPT
52232.-Compiler-Design-Lexical-Analysis.ppt
cujjal191
 
PPT
compiler Design course material chapter 2
gadisaAdamu
 
PPT
Lexical Analysis
Munni28
 
PPTX
Structure of the compiler
Sudhaa Ravi
 
DOCX
Compiler Design
Anujashejwal
 
atc 3rd module compiler and automata.ppt
ranjan317165
 
Ch 2.pptx
woldu2
 
Compiler Design ug semLexical Analysis.ppt
ssuser6ba09a
 
Chahioiuou9oioooooooooooooofffghfpterTwo.pptx
dejenehundaol91
 
3a. Context Free Grammar.pdf
TANZINTANZINA
 
Pcd question bank
Sumathi Gnanasekaran
 
Compilers Design
Akshaya Arunan
 
Lecture 1 - Lexical Analysis.ppt
NderituGichuki1
 
Lexical Analyser PPTs for Third Lease Computer Sc. and Engineering
DrRajurkarArchanaMil
 
Lexical analysis Compiler design pdf to read
shubhamsingaal
 
Lexical analysis compiler design to read and study
shubhamsingaal
 
1.Role lexical Analyzer
Radhakrishnan Chinnusamy
 
Lecturer-05 lex anylser (1).pptrjyghsgst
engrsheikhmuhammadha
 
role of lexical parser compiler design1-181124035217.pdf
ranjan317165
 
02. Chapter 3 - Lexical Analysis NLP.ppt
charvivij
 
52232.-Compiler-Design-Lexical-Analysis.ppt
cujjal191
 
compiler Design course material chapter 2
gadisaAdamu
 
Lexical Analysis
Munni28
 
Structure of the compiler
Sudhaa Ravi
 
Compiler Design
Anujashejwal
 
Ad

Recently uploaded (20)

PPTX
原版澳洲莫道克大学毕业证(MU毕业证书)如何办理
Taqyea
 
PPTX
英国学位证(PSU毕业证书)普利茅斯大学毕业证书如何办理
Taqyea
 
PPT
COMBINATIONAL LOGIC DESIGN SADSADASDASDASDASDASDASDA
phmthai2300
 
PPT
it_14.ppt using atharva college of engineering
shkzishan810
 
PPTX
英国学位证(LTU毕业证书)利兹三一大学毕业证书如何办理
Taqyea
 
PPTX
Pranjal Accountancy hhw ppt.pptxbnhxududjylitzitzyoxtosoysitztd
nishantrathore042
 
PPTX
diagnosisinfpdpart1-200628063900 (1).pptx
JayeshTaneja4
 
PPTX
哪里购买澳洲学历认证查询伊迪斯科文大学成绩单水印ECU录取通知书
Taqyea
 
PPTX
ualities-of-Quantitative-Research-1.pptx
jamjamkyong
 
PPTX
Flannel graphFlannel graphFlannel graphFlannel graphFlannel graph
shareesh25
 
PPTX
Series.pptxvvggghgufifudududydydydudyxyxyx
jasperbernaldo3
 
PDF
Utility Software hshdgsvcjdgvbdvcfkcdgdc
imeetrinidadfuertesa
 
PPT
Confined Space.ppth. Bbbb. Bbbbbbbbbbbbbbbbbbbbbbbnnnjjj
eshaiqbal7
 
PPT
Computer Hardware and Software Hw and SW .ppt
MuzaFar28
 
PDF
Elevator Maintenance Checklist with eAuditor Audits & Inspections
eAuditor Audits & Inspections
 
PPTX
Dock Line Organization Made Easy – Discover AMARREX, the Mooring Line Holder ...
Seawatt
 
PDF
Development of Portable Spectometer For MIlk Qulaity analysis
ppr9495
 
PPTX
一比一原版(UoB毕业证)布莱德福德大学毕业证如何办理
Taqyea
 
PPTX
西班牙维尔瓦大学电子版毕业证{UHU毕业完成信UHU水印成绩单}原版制作
Taqyea
 
PPT
(1) Chemotherapeutic drugs Antimicrobials.ppt
mkurdi133
 
原版澳洲莫道克大学毕业证(MU毕业证书)如何办理
Taqyea
 
英国学位证(PSU毕业证书)普利茅斯大学毕业证书如何办理
Taqyea
 
COMBINATIONAL LOGIC DESIGN SADSADASDASDASDASDASDASDA
phmthai2300
 
it_14.ppt using atharva college of engineering
shkzishan810
 
英国学位证(LTU毕业证书)利兹三一大学毕业证书如何办理
Taqyea
 
Pranjal Accountancy hhw ppt.pptxbnhxududjylitzitzyoxtosoysitztd
nishantrathore042
 
diagnosisinfpdpart1-200628063900 (1).pptx
JayeshTaneja4
 
哪里购买澳洲学历认证查询伊迪斯科文大学成绩单水印ECU录取通知书
Taqyea
 
ualities-of-Quantitative-Research-1.pptx
jamjamkyong
 
Flannel graphFlannel graphFlannel graphFlannel graphFlannel graph
shareesh25
 
Series.pptxvvggghgufifudududydydydudyxyxyx
jasperbernaldo3
 
Utility Software hshdgsvcjdgvbdvcfkcdgdc
imeetrinidadfuertesa
 
Confined Space.ppth. Bbbb. Bbbbbbbbbbbbbbbbbbbbbbbnnnjjj
eshaiqbal7
 
Computer Hardware and Software Hw and SW .ppt
MuzaFar28
 
Elevator Maintenance Checklist with eAuditor Audits & Inspections
eAuditor Audits & Inspections
 
Dock Line Organization Made Easy – Discover AMARREX, the Mooring Line Holder ...
Seawatt
 
Development of Portable Spectometer For MIlk Qulaity analysis
ppr9495
 
一比一原版(UoB毕业证)布莱德福德大学毕业证如何办理
Taqyea
 
西班牙维尔瓦大学电子版毕业证{UHU毕业完成信UHU水印成绩单}原版制作
Taqyea
 
(1) Chemotherapeutic drugs Antimicrobials.ppt
mkurdi133
 
Ad

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