SlideShare a Scribd company logo
1 of 18
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 & PatternBharat Rathore
 
Top Down Parsing, Predictive Parsing
Top Down Parsing, Predictive ParsingTop Down Parsing, Predictive Parsing
Top Down Parsing, Predictive ParsingTanzeela_Hussain
 
Operator Precedence Grammar
Operator Precedence GrammarOperator Precedence Grammar
Operator Precedence GrammarHarisonFekadu
 
Three Address code
Three Address code Three Address code
Three Address code Pooja Dixit
 
Lexical Analysis - Compiler design
Lexical Analysis - Compiler design Lexical Analysis - Compiler design
Lexical Analysis - Compiler design Aman Sharma
 
Ll(1) Parser in Compilers
Ll(1) Parser in CompilersLl(1) Parser in Compilers
Ll(1) Parser in CompilersMahbubur Rahman
 
Lexical Analysis - Compiler Design
Lexical Analysis - Compiler DesignLexical Analysis - Compiler Design
Lexical Analysis - Compiler DesignAkhil Kaushik
 
Polygon filling algorithm
Polygon filling algorithmPolygon filling algorithm
Polygon filling algorithmAparna Joshi
 
Polygon filling
Polygon fillingPolygon filling
Polygon fillingAnkit Garg
 
Bottom - Up Parsing
Bottom - Up ParsingBottom - Up Parsing
Bottom - Up Parsingkunj desai
 
Window to viewport transformation
Window to viewport transformationWindow to viewport transformation
Window to viewport transformationAnkit Garg
 
Compiler design syntax analysis
Compiler design syntax analysisCompiler design syntax analysis
Compiler design syntax analysisRicha Sharma
 
Error detection recovery
Error detection recoveryError detection recovery
Error detection recoveryTech_MX
 
Intermediate code generation in Compiler Design
Intermediate code generation in Compiler DesignIntermediate code generation in Compiler Design
Intermediate code generation in Compiler DesignKuppusamy P
 

What's hot (20)

Relationship Among Token, Lexeme & Pattern
Relationship Among Token, Lexeme & PatternRelationship Among Token, Lexeme & Pattern
Relationship Among Token, Lexeme & Pattern
 
Type Checking(Compiler Design) #ShareThisIfYouLike
Type Checking(Compiler Design) #ShareThisIfYouLikeType Checking(Compiler Design) #ShareThisIfYouLike
Type Checking(Compiler Design) #ShareThisIfYouLike
 
Top Down Parsing, Predictive Parsing
Top Down Parsing, Predictive ParsingTop Down Parsing, Predictive Parsing
Top Down Parsing, Predictive Parsing
 
Operator Precedence Grammar
Operator Precedence GrammarOperator Precedence Grammar
Operator Precedence Grammar
 
Three Address code
Three Address code Three Address code
Three Address code
 
Lexical Analysis - Compiler design
Lexical Analysis - Compiler design Lexical Analysis - Compiler design
Lexical Analysis - Compiler design
 
Predicate logic
 Predicate logic Predicate logic
Predicate logic
 
Ll(1) Parser in Compilers
Ll(1) Parser in CompilersLl(1) Parser in Compilers
Ll(1) Parser in Compilers
 
Lexical Analysis - Compiler Design
Lexical Analysis - Compiler DesignLexical Analysis - Compiler Design
Lexical Analysis - Compiler Design
 
Polygon filling algorithm
Polygon filling algorithmPolygon filling algorithm
Polygon filling algorithm
 
Polygon filling
Polygon fillingPolygon filling
Polygon filling
 
Bottom - Up Parsing
Bottom - Up ParsingBottom - Up Parsing
Bottom - Up Parsing
 
Window to viewport transformation
Window to viewport transformationWindow to viewport transformation
Window to viewport transformation
 
1.Role lexical Analyzer
1.Role lexical Analyzer1.Role lexical Analyzer
1.Role lexical Analyzer
 
Code Optimization
Code OptimizationCode Optimization
Code Optimization
 
Compiler design syntax analysis
Compiler design syntax analysisCompiler design syntax analysis
Compiler design syntax analysis
 
Polygon filling
Polygon fillingPolygon filling
Polygon filling
 
Predictive parser
Predictive parserPredictive parser
Predictive parser
 
Error detection recovery
Error detection recoveryError detection recovery
Error detection recovery
 
Intermediate code generation in Compiler Design
Intermediate code generation in Compiler DesignIntermediate code generation in Compiler Design
Intermediate code generation in Compiler Design
 

Similar to A SIMPLE APPROACH TO DESIGNING LEXICAL ANALYZERS

Similar to A SIMPLE APPROACH TO DESIGNING 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
 
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
 
Compilers Design
Compilers DesignCompilers Design
Compilers Design
 
Compiler Designs
Compiler DesignsCompiler Designs
Compiler Designs
 
8-Practice problems on operator precedence parser-24-05-2023.docx
8-Practice problems on operator precedence parser-24-05-2023.docx8-Practice problems on operator precedence parser-24-05-2023.docx
8-Practice problems on operator precedence parser-24-05-2023.docx
 
Chapter Three(2)
Chapter Three(2)Chapter Three(2)
Chapter Three(2)
 

More from Archana Gopinath

Data Transfer & Manipulation.pptx
Data Transfer & Manipulation.pptxData Transfer & Manipulation.pptx
Data Transfer & Manipulation.pptxArchana Gopinath
 
DP _ CO Instruction Format.pptx
DP _ CO Instruction Format.pptxDP _ CO Instruction Format.pptx
DP _ CO Instruction Format.pptxArchana Gopinath
 
Language for specifying lexical Analyzer
Language for specifying lexical AnalyzerLanguage for specifying lexical Analyzer
Language for specifying lexical AnalyzerArchana Gopinath
 
Implementation of lexical analyser
Implementation of lexical analyserImplementation of lexical analyser
Implementation of lexical analyserArchana Gopinath
 
A Role of Lexical Analyzer
A Role of Lexical AnalyzerA Role of Lexical Analyzer
A Role of Lexical AnalyzerArchana 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 DFAArchana 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 HadoopArchana 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 ANALYTICSArchana Gopinath
 
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 AnalyticsArchana Gopinath
 
If statements in c programming
If statements in c programmingIf statements in c programming
If statements in c programmingArchana Gopinath
 
Guided media Transmission Media
Guided media Transmission MediaGuided media Transmission Media
Guided media Transmission MediaArchana 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

How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,Virag Sontakke
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...jaredbarbolino94
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxEyham Joco
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupJonathanParaisoCruz
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxsocialsciencegdgrohi
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 

Recently uploaded (20)

How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptx
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized Group
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 

A SIMPLE APPROACH TO DESIGNING 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.