SlideShare a Scribd company logo
A SIMPLE APPROACH TO THE DESIGN OF
LEXICAL ANALYZERS
Myself Archana R
Assistant Professor In
Department Of Computer Science
SACWC.
I am here because I love to give presentations.
Simple Approach
Construct a diagram that illustrates the structure of the tokens of the
source language , and then to hand-translate the diagram
the diagram into a program for finding tokens.
Notes:
Efficient lexical analyzers can be produced in this manner.
Simple Approaches To Implement A
Lexical Analyzer
Pattern-directed programming approach
 Pattern Matching technique.
 Specify and design program that execute actions triggered by
patterns in strings.
 Introduce a pattern-action language called Lexical for specifying
lexical analyzers .
 Patterns are specified by regular expressions .
 A compiler for Lexical can generate an efficient finite
automation recognizer for the regular expressions.
First phase of a compiler
1. Main task
- To read the input characters.
- To produce a sequence of tokens used by the parser for
syntax analysis.
- As an assistant of parser.
 Lexical analyzer
 Parser
 Symbol table
 Source program
 token
 Get next token
Interaction of lexical analyzer with parser
Processes in lexical analyzers
 Scanning
*Pre-processing
-Strip out comments and white space
-Macro functions
 Correlating error messages from compiler with source
program
*A line number can be associated with an error
message.
 Lexical analysis
Regular Expression & Regular language
 Regular Expression
A notation that allows us to define a pattern in a high
level language.
 Regular language
Each regular expression r denotes language L(r) (the
set of sentences relating to the regular expression r) .
Notes:
Each word in a program can be expressed in a regular
expression.
Specification of Tokens
1) The rule of regular expression over alphabet ∑
* ε is a regular expression that denote {ε}
ε is regular expression .
{ε} is the related regular language.
2) If a is a symbol in ∑, then a is a regular expression that
denotes {a}
a is regular expression .
{a} is the related regular language.
3) Suppose α and β are regular expressions, then α| β, α β, α * , β *
is also a regular expression.
Notes : Rules 1) and 2) form the basis of the definition; rule 3)
provides the inductive step.
4) Algebraic laws of regular expressions
1) α| β = β | α 2) α |(β |γ)=(α | β)| γ α(β γ) =(α β) γ
3)εα = αε= α 5)(α *)*= α *
6) α *= α +|ε α + = α α * = α * α
7) (α | β)*= (α * | β *)*= (α * β *)*
Notational Short-hands
a)One or more instances
( r ) digit+
b)Zero or one instance
r? is a shorthand for r| (E(+|-)?digits)?
c)Character classes
[a-z] denotes a|b|c|…|z
[A-Za-z] [A-Za-z0-9]
Implementing a Transition Diagram
 Each state gets a segment of code.
 If there are edges leaving a state, then its code reads a character and
selects an edge to follow, if possible.
 Use next char() to read next character from the input buffer.
A generalized transition diagram Finite Automation
 Deterministic or non-deterministic FA.
 Non-deterministic means that more than one transition out of a state
may be possible on the same input symbol.
The model of recognition of
tokens
INPUT BUFFER
Lexeme being
FA simulator
i f d 2 =……..
The FA simulator for Identifiers is
Letter
Letter
digit
Which represent the rule:
identifier=letter(letter | digit)*
Deterministic FA (DFA)
1) In a DFA, no state has an transition.
2)In a DFA, for each state s and input symbol a,
there is at most one edge labeled a leaving s.
3)To describe a FA , we use the transition graph or
transition table .
4)A DFA accepts an input string x if and only if
there is some path in the transition graph from start
state to some accepting state.
So ,the DFA is
M=({0,1,2,3,},{a,b,c}, move,0,{1,2,3})
move:move(0,a)=1
move(0,b)=1 move(0,c)=1
move(1,a)=1 move(1,b)=1
move(1,c)=1 move(2,a)=3
move(2,b)=2 move(2,c)=2
move(3,b)=3 move(3,c)=3 32
A generalized transition diagram
 Finite Automation
Deterministic or non-deterministic FA
Non-deterministic means that
more than one transition out of a state may be
possible on the same input symbol.
Non-deterministic FA (NFA)
1) In a NFA the same character can label two or more transitions out
of one state.
2) In a NFA is a legal input symbol.
3) A DFA is a special case of a NFA.
4)A NFA accepts an input string x if and only if there is some path in
the transition graph from start state to some accepting state. A
path can be represented by a sequence of state transitions called
moves.
5) It accepts the language defined by a NFA is the set of input strings.
Thank you

More Related Content

What's hot

Relationship Among Token, Lexeme & Pattern
Relationship Among Token, Lexeme & PatternRelationship Among Token, Lexeme & Pattern
Relationship Among Token, Lexeme & Pattern
Bharat Rathore
 
Unit 4
Unit 4Unit 4
Semantics analysis
Semantics analysisSemantics analysis
Semantics analysis
Bilalzafar22
 
Ll(1) Parser in Compilers
Ll(1) Parser in CompilersLl(1) Parser in Compilers
Ll(1) Parser in Compilers
Mahbubur Rahman
 
Recognition-of-tokens
Recognition-of-tokensRecognition-of-tokens
Recognition-of-tokens
Dattatray Gandhmal
 
Bottom - Up Parsing
Bottom - Up ParsingBottom - Up Parsing
Bottom - Up Parsing
kunj desai
 
Types of Parser
Types of ParserTypes of Parser
Types of Parser
SomnathMore3
 
Parsing
ParsingParsing
Parsing
khush_boo31
 
Input-Buffering
Input-BufferingInput-Buffering
Input-Buffering
Dattatray Gandhmal
 
Type Checking(Compiler Design) #ShareThisIfYouLike
Type Checking(Compiler Design) #ShareThisIfYouLikeType Checking(Compiler Design) #ShareThisIfYouLike
Type Checking(Compiler Design) #ShareThisIfYouLike
United International University
 
Data structures and algorithms
Data structures and algorithmsData structures and algorithms
Data structures and algorithms
Julie Iskander
 
Storage organization and stack allocation of space
Storage organization and stack allocation of spaceStorage organization and stack allocation of space
Storage organization and stack allocation of space
Muhammad Haroon
 
Performance analysis(Time & Space Complexity)
Performance analysis(Time & Space Complexity)Performance analysis(Time & Space Complexity)
Performance analysis(Time & Space Complexity)
swapnac12
 
FUNCTION DEPENDENCY AND TYPES & EXAMPLE
FUNCTION DEPENDENCY  AND TYPES & EXAMPLEFUNCTION DEPENDENCY  AND TYPES & EXAMPLE
FUNCTION DEPENDENCY AND TYPES & EXAMPLE
Vraj Patel
 
stack & queue
stack & queuestack & queue
stack & queue
manju rani
 
Object Oriented Analysis and Design
Object Oriented Analysis and DesignObject Oriented Analysis and Design
Object Oriented Analysis and Design
Haitham El-Ghareeb
 
Top down parsing
Top down parsingTop down parsing
Top down parsing
ASHOK KUMAR REDDY
 
Parsing
ParsingParsing
Parsing in Compiler Design
Parsing in Compiler DesignParsing in Compiler Design
Parsing in Compiler Design
Akhil Kaushik
 
Slr parser
Slr parserSlr parser

What's hot (20)

Relationship Among Token, Lexeme & Pattern
Relationship Among Token, Lexeme & PatternRelationship Among Token, Lexeme & Pattern
Relationship Among Token, Lexeme & Pattern
 
Unit 4
Unit 4Unit 4
Unit 4
 
Semantics analysis
Semantics analysisSemantics analysis
Semantics analysis
 
Ll(1) Parser in Compilers
Ll(1) Parser in CompilersLl(1) Parser in Compilers
Ll(1) Parser in Compilers
 
Recognition-of-tokens
Recognition-of-tokensRecognition-of-tokens
Recognition-of-tokens
 
Bottom - Up Parsing
Bottom - Up ParsingBottom - Up Parsing
Bottom - Up Parsing
 
Types of Parser
Types of ParserTypes of Parser
Types of Parser
 
Parsing
ParsingParsing
Parsing
 
Input-Buffering
Input-BufferingInput-Buffering
Input-Buffering
 
Type Checking(Compiler Design) #ShareThisIfYouLike
Type Checking(Compiler Design) #ShareThisIfYouLikeType Checking(Compiler Design) #ShareThisIfYouLike
Type Checking(Compiler Design) #ShareThisIfYouLike
 
Data structures and algorithms
Data structures and algorithmsData structures and algorithms
Data structures and algorithms
 
Storage organization and stack allocation of space
Storage organization and stack allocation of spaceStorage organization and stack allocation of space
Storage organization and stack allocation of space
 
Performance analysis(Time & Space Complexity)
Performance analysis(Time & Space Complexity)Performance analysis(Time & Space Complexity)
Performance analysis(Time & Space Complexity)
 
FUNCTION DEPENDENCY AND TYPES & EXAMPLE
FUNCTION DEPENDENCY  AND TYPES & EXAMPLEFUNCTION DEPENDENCY  AND TYPES & EXAMPLE
FUNCTION DEPENDENCY AND TYPES & EXAMPLE
 
stack & queue
stack & queuestack & queue
stack & queue
 
Object Oriented Analysis and Design
Object Oriented Analysis and DesignObject Oriented Analysis and Design
Object Oriented Analysis and Design
 
Top down parsing
Top down parsingTop down parsing
Top down parsing
 
Parsing
ParsingParsing
Parsing
 
Parsing in Compiler Design
Parsing in Compiler DesignParsing in Compiler Design
Parsing in Compiler Design
 
Slr parser
Slr parserSlr parser
Slr parser
 

Similar to A simple approach of lexical analyzers

Chapter Two(1)
Chapter Two(1)Chapter Two(1)
Chapter Two(1)
bolovv
 
Lecture 1 - Lexical Analysis.ppt
Lecture 1 - Lexical Analysis.pptLecture 1 - Lexical Analysis.ppt
Lecture 1 - Lexical Analysis.ppt
NderituGichuki1
 
The Theory of Finite Automata.pptx
The Theory of Finite Automata.pptxThe Theory of Finite Automata.pptx
The Theory of Finite Automata.pptx
ssuser039bf6
 
Chapter Three(1)
Chapter Three(1)Chapter Three(1)
Chapter Three(1)
bolovv
 
Regular Expression to Finite Automata
Regular Expression to Finite AutomataRegular Expression to Finite Automata
Regular Expression to Finite Automata
Archana Gopinath
 
Compiler lec 8
Compiler lec 8Compiler lec 8
Compiler lec 8
Ramadan Babers, PhD
 
02. chapter 3 lexical analysis
02. chapter 3   lexical analysis02. chapter 3   lexical analysis
02. chapter 3 lexical analysis
raosir123
 
compiler design course focus of chapter 3 and 4 part
compiler design course focus of chapter 3 and 4 partcompiler design course focus of chapter 3 and 4 part
compiler design course focus of chapter 3 and 4 part
abel185080
 
COMPILER DESIGN LECTURES -UNIT-2 ST.pptx
COMPILER DESIGN LECTURES -UNIT-2 ST.pptxCOMPILER DESIGN LECTURES -UNIT-2 ST.pptx
COMPILER DESIGN LECTURES -UNIT-2 ST.pptx
Ranjeet Reddy
 
Lecture 02 lexical analysis
Lecture 02 lexical analysisLecture 02 lexical analysis
Lecture 02 lexical analysis
Iffat Anjum
 
Syntax analysis
Syntax analysisSyntax analysis
Module 11
Module 11Module 11
Module 11
bittudavis
 
Lec1.pptx
Lec1.pptxLec1.pptx
Lec1.pptx
ziadk6872
 
Ch 2.pptx
Ch 2.pptxCh 2.pptx
Ch 2.pptx
woldu2
 
Ch3.ppt
Ch3.pptCh3.ppt
Ch3.ppt
MDSayem35
 
compiler Design course material chapter 2
compiler Design course material chapter 2compiler Design course material chapter 2
compiler Design course material chapter 2
gadisaAdamu
 
Lexicalanalyzer
LexicalanalyzerLexicalanalyzer
Lexicalanalyzer
Royalzig Luxury Furniture
 
Lexicalanalyzer
LexicalanalyzerLexicalanalyzer
Lexicalanalyzer
Royalzig Luxury Furniture
 
Lexical Analysis - Compiler design
Lexical Analysis - Compiler design Lexical Analysis - Compiler design
Lexical Analysis - Compiler design
Aman Sharma
 
Compilers Design
Compilers DesignCompilers Design
Compilers Design
Akshaya Arunan
 

Similar to A simple approach of lexical analyzers (20)

Chapter Two(1)
Chapter Two(1)Chapter Two(1)
Chapter Two(1)
 
Lecture 1 - Lexical Analysis.ppt
Lecture 1 - Lexical Analysis.pptLecture 1 - Lexical Analysis.ppt
Lecture 1 - Lexical Analysis.ppt
 
The Theory of Finite Automata.pptx
The Theory of Finite Automata.pptxThe Theory of Finite Automata.pptx
The Theory of Finite Automata.pptx
 
Chapter Three(1)
Chapter Three(1)Chapter Three(1)
Chapter Three(1)
 
Regular Expression to Finite Automata
Regular Expression to Finite AutomataRegular Expression to Finite Automata
Regular Expression to Finite Automata
 
Compiler lec 8
Compiler lec 8Compiler lec 8
Compiler lec 8
 
02. chapter 3 lexical analysis
02. chapter 3   lexical analysis02. chapter 3   lexical analysis
02. chapter 3 lexical analysis
 
compiler design course focus of chapter 3 and 4 part
compiler design course focus of chapter 3 and 4 partcompiler design course focus of chapter 3 and 4 part
compiler design course focus of chapter 3 and 4 part
 
COMPILER DESIGN LECTURES -UNIT-2 ST.pptx
COMPILER DESIGN LECTURES -UNIT-2 ST.pptxCOMPILER DESIGN LECTURES -UNIT-2 ST.pptx
COMPILER DESIGN LECTURES -UNIT-2 ST.pptx
 
Lecture 02 lexical analysis
Lecture 02 lexical analysisLecture 02 lexical analysis
Lecture 02 lexical analysis
 
Syntax analysis
Syntax analysisSyntax analysis
Syntax analysis
 
Module 11
Module 11Module 11
Module 11
 
Lec1.pptx
Lec1.pptxLec1.pptx
Lec1.pptx
 
Ch 2.pptx
Ch 2.pptxCh 2.pptx
Ch 2.pptx
 
Ch3.ppt
Ch3.pptCh3.ppt
Ch3.ppt
 
compiler Design course material chapter 2
compiler Design course material chapter 2compiler Design course material chapter 2
compiler Design course material chapter 2
 
Lexicalanalyzer
LexicalanalyzerLexicalanalyzer
Lexicalanalyzer
 
Lexicalanalyzer
LexicalanalyzerLexicalanalyzer
Lexicalanalyzer
 
Lexical Analysis - Compiler design
Lexical Analysis - Compiler design Lexical Analysis - Compiler design
Lexical Analysis - Compiler design
 
Compilers Design
Compilers DesignCompilers Design
Compilers Design
 

More from Archana Gopinath

Data Transfer & Manipulation.pptx
Data Transfer & Manipulation.pptxData Transfer & Manipulation.pptx
Data Transfer & Manipulation.pptx
Archana Gopinath
 
DP _ CO Instruction Format.pptx
DP _ CO Instruction Format.pptxDP _ CO Instruction Format.pptx
DP _ CO Instruction Format.pptx
Archana Gopinath
 
Language for specifying lexical Analyzer
Language for specifying lexical AnalyzerLanguage for specifying lexical Analyzer
Language for specifying lexical Analyzer
Archana Gopinath
 
Implementation of lexical analyser
Implementation of lexical analyserImplementation of lexical analyser
Implementation of lexical analyser
Archana Gopinath
 
A Role of Lexical Analyzer
A Role of Lexical AnalyzerA Role of Lexical Analyzer
A Role of Lexical Analyzer
Archana Gopinath
 
minimization the number of states of DFA
minimization the number of states of DFAminimization the number of states of DFA
minimization the number of states of DFA
Archana Gopinath
 
Fundamentals of big data analytics and Hadoop
Fundamentals of big data analytics and HadoopFundamentals of big data analytics and Hadoop
Fundamentals of big data analytics and Hadoop
Archana Gopinath
 
Map reduce in Hadoop BIG DATA ANALYTICS
Map reduce in Hadoop BIG DATA ANALYTICSMap reduce in Hadoop BIG DATA ANALYTICS
Map reduce in Hadoop BIG DATA ANALYTICS
Archana Gopinath
 
Business intelligence
Business intelligenceBusiness intelligence
Business intelligence
Archana Gopinath
 
Hadoop
HadoopHadoop
Programming with R in Big Data Analytics
Programming with R in Big Data AnalyticsProgramming with R in Big Data Analytics
Programming with R in Big Data Analytics
Archana Gopinath
 
If statements in c programming
If statements in c programmingIf statements in c programming
If statements in c programming
Archana Gopinath
 
un Guided media
un Guided mediaun Guided media
un Guided media
Archana Gopinath
 
Guided media Transmission Media
Guided media Transmission MediaGuided media Transmission Media
Guided media Transmission Media
Archana Gopinath
 
Main Memory RAM and ROM
Main Memory RAM and ROMMain Memory RAM and ROM
Main Memory RAM and ROM
Archana Gopinath
 
Java thread life cycle
Java thread life cycleJava thread life cycle
Java thread life cycle
Archana Gopinath
 
PCSTt11 overview of java
PCSTt11 overview of javaPCSTt11 overview of java
PCSTt11 overview of java
Archana Gopinath
 

More from Archana Gopinath (17)

Data Transfer & Manipulation.pptx
Data Transfer & Manipulation.pptxData Transfer & Manipulation.pptx
Data Transfer & Manipulation.pptx
 
DP _ CO Instruction Format.pptx
DP _ CO Instruction Format.pptxDP _ CO Instruction Format.pptx
DP _ CO Instruction Format.pptx
 
Language for specifying lexical Analyzer
Language for specifying lexical AnalyzerLanguage for specifying lexical Analyzer
Language for specifying lexical Analyzer
 
Implementation of lexical analyser
Implementation of lexical analyserImplementation of lexical analyser
Implementation of lexical analyser
 
A Role of Lexical Analyzer
A Role of Lexical AnalyzerA Role of Lexical Analyzer
A Role of Lexical Analyzer
 
minimization the number of states of DFA
minimization the number of states of DFAminimization the number of states of DFA
minimization the number of states of DFA
 
Fundamentals of big data analytics and Hadoop
Fundamentals of big data analytics and HadoopFundamentals of big data analytics and Hadoop
Fundamentals of big data analytics and Hadoop
 
Map reduce in Hadoop BIG DATA ANALYTICS
Map reduce in Hadoop BIG DATA ANALYTICSMap reduce in Hadoop BIG DATA ANALYTICS
Map reduce in Hadoop BIG DATA ANALYTICS
 
Business intelligence
Business intelligenceBusiness intelligence
Business intelligence
 
Hadoop
HadoopHadoop
Hadoop
 
Programming with R in Big Data Analytics
Programming with R in Big Data AnalyticsProgramming with R in Big Data Analytics
Programming with R in Big Data Analytics
 
If statements in c programming
If statements in c programmingIf statements in c programming
If statements in c programming
 
un Guided media
un Guided mediaun Guided media
un Guided media
 
Guided media Transmission Media
Guided media Transmission MediaGuided media Transmission Media
Guided media Transmission Media
 
Main Memory RAM and ROM
Main Memory RAM and ROMMain Memory RAM and ROM
Main Memory RAM and ROM
 
Java thread life cycle
Java thread life cycleJava thread life cycle
Java thread life cycle
 
PCSTt11 overview of java
PCSTt11 overview of javaPCSTt11 overview of java
PCSTt11 overview of java
 

Recently uploaded

Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
National Information Standards Organization (NISO)
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
chanes7
 
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UPLAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
RAHUL
 
Life upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for studentLife upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for student
NgcHiNguyn25
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
Priyankaranawat4
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
Jean Carlos Nunes Paixão
 
Walmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdfWalmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdf
TechSoup
 
How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
Celine George
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
adhitya5119
 
How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17
Celine George
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Dr. Vinod Kumar Kanvaria
 
Cognitive Development Adolescence Psychology
Cognitive Development Adolescence PsychologyCognitive Development Adolescence Psychology
Cognitive Development Adolescence Psychology
paigestewart1632
 
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
IreneSebastianRueco1
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
Nicholas Montgomery
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
David Douglas School District
 
World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024
ak6969907
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
Israel Genealogy Research Association
 
How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
Celine George
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
heathfieldcps1
 
Smart-Money for SMC traders good time and ICT
Smart-Money for SMC traders good time and ICTSmart-Money for SMC traders good time and ICT
Smart-Money for SMC traders good time and ICT
simonomuemu
 

Recently uploaded (20)

Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
 
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UPLAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
 
Life upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for studentLife upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for student
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
 
Walmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdfWalmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdf
 
How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
 
How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
 
Cognitive Development Adolescence Psychology
Cognitive Development Adolescence PsychologyCognitive Development Adolescence Psychology
Cognitive Development Adolescence Psychology
 
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
 
World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
 
How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
 
Smart-Money for SMC traders good time and ICT
Smart-Money for SMC traders good time and ICTSmart-Money for SMC traders good time and ICT
Smart-Money for SMC traders good time and ICT
 

A simple approach of lexical analyzers

  • 1. A SIMPLE APPROACH TO THE DESIGN OF LEXICAL ANALYZERS Myself Archana R Assistant Professor In Department Of Computer Science SACWC. I am here because I love to give presentations.
  • 2. Simple Approach Construct a diagram that illustrates the structure of the tokens of the source language , and then to hand-translate the diagram the diagram into a program for finding tokens. Notes: Efficient lexical analyzers can be produced in this manner.
  • 3. Simple Approaches To Implement A Lexical Analyzer Pattern-directed programming approach  Pattern Matching technique.  Specify and design program that execute actions triggered by patterns in strings.  Introduce a pattern-action language called Lexical for specifying lexical analyzers .  Patterns are specified by regular expressions .  A compiler for Lexical can generate an efficient finite automation recognizer for the regular expressions.
  • 4. First phase of a compiler 1. Main task - To read the input characters. - To produce a sequence of tokens used by the parser for syntax analysis. - As an assistant of parser.
  • 5.  Lexical analyzer  Parser  Symbol table  Source program  token  Get next token Interaction of lexical analyzer with parser
  • 6. Processes in lexical analyzers  Scanning *Pre-processing -Strip out comments and white space -Macro functions  Correlating error messages from compiler with source program *A line number can be associated with an error message.  Lexical analysis
  • 7. Regular Expression & Regular language  Regular Expression A notation that allows us to define a pattern in a high level language.  Regular language Each regular expression r denotes language L(r) (the set of sentences relating to the regular expression r) . Notes: Each word in a program can be expressed in a regular expression.
  • 8. Specification of Tokens 1) The rule of regular expression over alphabet ∑ * ε is a regular expression that denote {ε} ε is regular expression . {ε} is the related regular language. 2) If a is a symbol in ∑, then a is a regular expression that denotes {a} a is regular expression . {a} is the related regular language.
  • 9. 3) Suppose α and β are regular expressions, then α| β, α β, α * , β * is also a regular expression. Notes : Rules 1) and 2) form the basis of the definition; rule 3) provides the inductive step. 4) Algebraic laws of regular expressions 1) α| β = β | α 2) α |(β |γ)=(α | β)| γ α(β γ) =(α β) γ 3)εα = αε= α 5)(α *)*= α * 6) α *= α +|ε α + = α α * = α * α 7) (α | β)*= (α * | β *)*= (α * β *)*
  • 10. Notational Short-hands a)One or more instances ( r ) digit+ b)Zero or one instance r? is a shorthand for r| (E(+|-)?digits)? c)Character classes [a-z] denotes a|b|c|…|z [A-Za-z] [A-Za-z0-9]
  • 11. Implementing a Transition Diagram  Each state gets a segment of code.  If there are edges leaving a state, then its code reads a character and selects an edge to follow, if possible.  Use next char() to read next character from the input buffer. A generalized transition diagram Finite Automation  Deterministic or non-deterministic FA.  Non-deterministic means that more than one transition out of a state may be possible on the same input symbol.
  • 12. The model of recognition of tokens INPUT BUFFER Lexeme being FA simulator i f d 2 =……..
  • 13. The FA simulator for Identifiers is Letter Letter digit Which represent the rule: identifier=letter(letter | digit)*
  • 14. Deterministic FA (DFA) 1) In a DFA, no state has an transition. 2)In a DFA, for each state s and input symbol a, there is at most one edge labeled a leaving s. 3)To describe a FA , we use the transition graph or transition table . 4)A DFA accepts an input string x if and only if there is some path in the transition graph from start state to some accepting state.
  • 15. So ,the DFA is M=({0,1,2,3,},{a,b,c}, move,0,{1,2,3}) move:move(0,a)=1 move(0,b)=1 move(0,c)=1 move(1,a)=1 move(1,b)=1 move(1,c)=1 move(2,a)=3 move(2,b)=2 move(2,c)=2 move(3,b)=3 move(3,c)=3 32
  • 16. A generalized transition diagram  Finite Automation Deterministic or non-deterministic FA Non-deterministic means that more than one transition out of a state may be possible on the same input symbol.
  • 17. Non-deterministic FA (NFA) 1) In a NFA the same character can label two or more transitions out of one state. 2) In a NFA is a legal input symbol. 3) A DFA is a special case of a NFA. 4)A NFA accepts an input string x if and only if there is some path in the transition graph from start state to some accepting state. A path can be represented by a sequence of state transitions called moves. 5) It accepts the language defined by a NFA is the set of input strings.