SlideShare a Scribd company logo
Recognition of Tokens
• We now know how to specify the tokens for our
language. But how do we write a program to
recognize them?
if -> if
then -> then
else -> else
relop -> < | <= | = | <> | > | >=
id -> letter ( letter | digit )*
num -> digit ( . digit )? ( E (+|-)? digit )?
Token recognition
• We also want to strip whitespace, so we need
definitions
delim -> blank | tab | newline
ws -> delim+
Attribute values
Regular Expression Token Attribute value
ws - -
if if -
then then -
else else -
id id ptr to sym table entry
num num ptr to sym table entry
< relop LT
<= relop LE
= relop EQ
<> relop NE
> relop GT
>= relop GE
Transition diagrams
• Transition diagrams are also called finite
automata.
• We have a collection of STATES drawn as
nodes in a graph.
• TRANSITIONS between states are represented
by directed edges in the graph.
• Each transition leaving a state s is labeled with
a set of input characters that can occur after
state s.
Transition diagrams (Conti…)
• For now, the transitions must be
DETERMINISTIC.
• Each transition diagram has a single START
state and a set of TERMINAL STATES.
• The label OTHER on an edge indicates all
possible inputs not handled by the other
transitions.
• Usually, when we recognize OTHER, we need
to put it back in the source stream since it is
part of the next token. This action is denoted
with a * next to the corresponding state.
0 6
8
7
Start
>
other
=
*
0 6
8
7
Start
>
other
=
For eg: >=
*
0 6
8
7Star
t
>
other
=
For eg: >=
*
0 6
8
7Star
t
>
other
=
For eg: >=
*
0 6
8
7Star
t
>
other
=
For eg: >=
*
0 6
8
7Star
t
>
other
=
For eg: >=
*
0 6
8
7Star
t
>
other
=
For eg: >=
*
0 6
8
7Star
t
>
other
=
For eg: >=
*
0 6
8
7
Start
>
other
=
For eg: abc > pqr
*
0 6
8
7Star
t
>
other
=
For eg: abc > pqr
*
0 6
8
7Star
t
>
other
=
For eg: abc > pqr
*
0 6
8
7Star
t
>
other
=
For eg: abc > pqr
*
0 6
8
7Star
t
>
other
=
For eg: abc > pqr
*
0 6
8
7Star
t
>
othe
r
=
For eg: abc > pqr
*
0 6
8
7Star
t
>
othe
r
=
For eg: abc > pqr
*
0 6
8
7Star
t
>
othe
r
=
For eg: abc > pqr
*
0 6
8
7Star
t
>
othe
r
=
For eg: abc > pqr
*
0 21
6
3
4
5
7
8
start
< =
>
other
return( relop, LE)
return( relop, NE)
return( relop, LT)
return( relop, EQ)
return( relop, GE)
return( relop, GT)
other
=
*
*=
>
0 21
6
3
4
5
7
8
start
< =
>
other
return( relop, LE)
return( relop, NE)
return( relop, LT)
return( relop, EQ)
return( relop, GE)
return( relop, GT)
other
=
*
*=
>
9 10 11
letter
letter or digit
other
*return(gettoken(), install_id())
start
25 26 27
digit
digit
other
*
start

More Related Content

PPTX
Specification-of-tokens
PDF
Lexical Analysis - Compiler design
PPT
TM - Techniques
PPTX
Structure of the compiler
PPTX
Compiler design syntax analysis
PDF
Lexical analysis - Compiler Design
PPT
context free language
PPT
Type Checking(Compiler Design) #ShareThisIfYouLike
Specification-of-tokens
Lexical Analysis - Compiler design
TM - Techniques
Structure of the compiler
Compiler design syntax analysis
Lexical analysis - Compiler Design
context free language
Type Checking(Compiler Design) #ShareThisIfYouLike

What's hot (20)

DOC
Time and space complexity
PDF
Syntax Directed Definition and its applications
PDF
Code optimization in compiler design
PPTX
Syntax Analysis in Compiler Design
PPTX
Types of Parser
PPTX
Assemblers
PDF
Issues in the design of Code Generator
PPTX
Loop optimization
PPTX
Graph coloring using backtracking
PPTX
Lexical analysis - Compiler Design
PPT
Intermediate code generation (Compiler Design)
PPTX
Principal Sources of Optimization in compiler design
PPTX
Peephole optimization techniques in compiler design
PPTX
Input-Buffering
PPTX
Congestion control
PDF
P, NP, NP-Complete, and NP-Hard
PPTX
Performance analysis(Time & Space Complexity)
PPTX
CLR AND LALR PARSER
PPTX
Mathematical Analysis of Non-Recursive Algorithm.
PPTX
Register allocation and assignment
Time and space complexity
Syntax Directed Definition and its applications
Code optimization in compiler design
Syntax Analysis in Compiler Design
Types of Parser
Assemblers
Issues in the design of Code Generator
Loop optimization
Graph coloring using backtracking
Lexical analysis - Compiler Design
Intermediate code generation (Compiler Design)
Principal Sources of Optimization in compiler design
Peephole optimization techniques in compiler design
Input-Buffering
Congestion control
P, NP, NP-Complete, and NP-Hard
Performance analysis(Time & Space Complexity)
CLR AND LALR PARSER
Mathematical Analysis of Non-Recursive Algorithm.
Register allocation and assignment
Ad

Similar to Recognition-of-tokens (20)

PDF
Assignment5
PPT
02. Chapter 3 - Lexical Analysis NLP.ppt
PPT
Lecture 1 - Lexical Analysis.ppt
PPT
Compiler Design ug semLexical Analysis.ppt
PPTX
A simple approach of lexical analyzers
PPT
02. chapter 3 lexical analysis
PPT
compiler Design course material chapter 2
PPT
52232.-Compiler-Design-Lexical-Analysis.ppt
PPTX
04LexicalAnalysissnsnjmsjsjmsbdjjdnd.pptx
PDF
Lexical analysis Compiler design pdf to read
PDF
Lexical analysis compiler design to read and study
PDF
Lex analysis
PPTX
Regular Expressions To Finite Automata
PDF
Lexical
PDF
lalr. fo engineering student those who to
PPT
PPT
Ch3.ppt
PPT
Lexical analysis, syntax analysis, semantic analysis. Ppt
PPTX
Theory of computing presentation
Assignment5
02. Chapter 3 - Lexical Analysis NLP.ppt
Lecture 1 - Lexical Analysis.ppt
Compiler Design ug semLexical Analysis.ppt
A simple approach of lexical analyzers
02. chapter 3 lexical analysis
compiler Design course material chapter 2
52232.-Compiler-Design-Lexical-Analysis.ppt
04LexicalAnalysissnsnjmsjsjmsbdjjdnd.pptx
Lexical analysis Compiler design pdf to read
Lexical analysis compiler design to read and study
Lex analysis
Regular Expressions To Finite Automata
Lexical
lalr. fo engineering student those who to
Ch3.ppt
Lexical analysis, syntax analysis, semantic analysis. Ppt
Theory of computing presentation
Ad

Recently uploaded (20)

PPTX
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
PPTX
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
PDF
Model Code of Practice - Construction Work - 21102022 .pdf
PPTX
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
PDF
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
PPTX
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
PPTX
Lesson 3_Tessellation.pptx finite Mathematics
PPTX
UNIT-1 - COAL BASED THERMAL POWER PLANTS
PPTX
CYBER-CRIMES AND SECURITY A guide to understanding
PPTX
additive manufacturing of ss316l using mig welding
PDF
composite construction of structures.pdf
PDF
Operating System & Kernel Study Guide-1 - converted.pdf
DOCX
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
PDF
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
PPTX
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
PDF
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
PPTX
Internet of Things (IOT) - A guide to understanding
PPT
Project quality management in manufacturing
PPTX
Lecture Notes Electrical Wiring System Components
PPT
Mechanical Engineering MATERIALS Selection
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
Model Code of Practice - Construction Work - 21102022 .pdf
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
Lesson 3_Tessellation.pptx finite Mathematics
UNIT-1 - COAL BASED THERMAL POWER PLANTS
CYBER-CRIMES AND SECURITY A guide to understanding
additive manufacturing of ss316l using mig welding
composite construction of structures.pdf
Operating System & Kernel Study Guide-1 - converted.pdf
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
Internet of Things (IOT) - A guide to understanding
Project quality management in manufacturing
Lecture Notes Electrical Wiring System Components
Mechanical Engineering MATERIALS Selection

Recognition-of-tokens