SlideShare a Scribd company logo
1 of 20
By : Kiran Acharya
inspireray.blogspot.in
Introduction to lexical Analyzer
Input buffering
Specifications of tokens
Regular expressions
inspireray.blogspot.in
There are two basic rules in regular
expression.
1. ɛ is a regular expression and L(ɛ), that is
the language whose sole number is an
empty string.
2. If a is a symbol in Ʃ , then a is a regular
expression with one string of length one ,
with a at its first position.
inspireray.blogspot.in
(r)|(s) is a regular expression denoting
L(r)ỤL(s).
(r)(s) is a regular expression means L(r)L(s).
(r)* means regular expression(L(r)).
inspireray.blogspot.in
Unary operator * has the highest precedence
and its left associative.
Concatenation has second and its left
associative.
| has the lowest and left associative.
inspireray.blogspot.in
Language that can be defined by regular
expression is called regular set
if regular expression r and s are from same
set they are equivalent.
(a|b)=(b|a)
inspireray.blogspot.in
It’s a sequence of definitions of the form:
d1→r1;
d2→r2;
each d is a new symbol
r is regular expression over alphabets.
inspireray.blogspot.in
Kleene closure extended in 50’s
One or more instances
Zero or one instance.
Character class.
inspireray.blogspot.in
Taking the patterns from tokens and build
piece of code that examines the input find
the prefix that is the lexeme matching one of
the pattern.
Methods:
1. Transition Diagrams
2. Recognition of reverse words and identifier
3. Completion of running example.
inspireray.blogspot.in
These are first flow charts.
Conversion from patterns to transition
diagram.
It has states.
Edges
input
inspireray.blogspot.in
First and final state
Accepting state
Start state
inspireray.blogspot.in
Finding keywords and identifiers are the
problem.
Return(gettoken(),installid())
0 10 11
start
letter
Letter
or digit
othe
r
inspireray.blogspot.in
Tool lex
Input is lex language tool itself is a lex
compiler.
Input file is lex.l
Compiler transform it into c program
Lex.yy.c
And later the file is compiled by c to a.out
inspireray.blogspot.in
Declarations: %%
Translation rules %%
Auxiliary functions
inspireray.blogspot.in
Always prefer a longer prefix over the
shorter
It longer matches the two or more patterns
then prefer the pattern listed first.
Look Ahead operator: / is inserted to know
the end of the part of lexeme.
inspireray.blogspot.in
The heart of the transition of lex turning
input program to lexical analyzer is finite
automata.
Finite automata are recognizers they just say
yes or no.
Two types:
1. Non deterministic
2. Deterministic
inspireray.blogspot.in
No restrictions to the edges from the same
state.
Finite state of state s
Input alphabet Ʃ
Transition function
Start state
Final state
inspireray.blogspot.in
State a b ɛ
0 {0,1} {0} ф
1 ф {2} ф
2 ф {3} ф
3 ф ф Ф
inspireray.blogspot.in
aabb
(a|b)* abb
inspireray.blogspot.in
There is exactly one edge form the input to
the next state.
inspireray.blogspot.in

More Related Content

What's hot (20)

Lexical analyzer
Lexical analyzerLexical analyzer
Lexical analyzer
 
Lexical analysis - Compiler Design
Lexical analysis - Compiler DesignLexical analysis - Compiler Design
Lexical analysis - Compiler Design
 
Lexical Analyzer Implementation
Lexical Analyzer ImplementationLexical Analyzer Implementation
Lexical Analyzer Implementation
 
A Role of Lexical Analyzer
A Role of Lexical AnalyzerA Role of Lexical Analyzer
A Role of Lexical Analyzer
 
Syntax analysis
Syntax analysisSyntax analysis
Syntax analysis
 
1.Role lexical Analyzer
1.Role lexical Analyzer1.Role lexical Analyzer
1.Role lexical Analyzer
 
Syntax analysis
Syntax analysisSyntax analysis
Syntax analysis
 
Lecture3 lexical analysis
Lecture3 lexical analysisLecture3 lexical analysis
Lecture3 lexical analysis
 
Compiler design and lexical analyser
Compiler design and lexical analyserCompiler design and lexical analyser
Compiler design and lexical analyser
 
Role-of-lexical-analysis
Role-of-lexical-analysisRole-of-lexical-analysis
Role-of-lexical-analysis
 
Compier Design_Unit I_SRM.ppt
Compier Design_Unit I_SRM.pptCompier Design_Unit I_SRM.ppt
Compier Design_Unit I_SRM.ppt
 
Chapter Three(1)
Chapter Three(1)Chapter Three(1)
Chapter Three(1)
 
3. Lexical analysis
3. Lexical analysis3. Lexical analysis
3. Lexical analysis
 
Lecture 04 syntax analysis
Lecture 04 syntax analysisLecture 04 syntax analysis
Lecture 04 syntax analysis
 
Token, Pattern and Lexeme
Token, Pattern and LexemeToken, Pattern and Lexeme
Token, Pattern and Lexeme
 
4 lexical and syntax analysis
4 lexical and syntax analysis4 lexical and syntax analysis
4 lexical and syntax analysis
 
Compiler lec 8
Compiler lec 8Compiler lec 8
Compiler lec 8
 
Lexical analysis
Lexical analysisLexical analysis
Lexical analysis
 
Lexical Analyzers and Parsers
Lexical Analyzers and ParsersLexical Analyzers and Parsers
Lexical Analyzers and Parsers
 
Lex
LexLex
Lex
 

Similar to Lexical analyzer

Lex and Yacc Tool M1.ppt
Lex and Yacc Tool M1.pptLex and Yacc Tool M1.ppt
Lex and Yacc Tool M1.pptMohitJain296729
 
Compiler design important questions
Compiler design   important questionsCompiler design   important questions
Compiler design important questionsakila viji
 
Ch 2.pptx
Ch 2.pptxCh 2.pptx
Ch 2.pptxwoldu2
 
Compiler Designs
Compiler DesignsCompiler Designs
Compiler Designswasim liam
 
Chapter-3 compiler.pptx course materials
Chapter-3 compiler.pptx course materialsChapter-3 compiler.pptx course materials
Chapter-3 compiler.pptx course materialsgadisaAdamu
 
The role of the parser and Error recovery strategies ppt in compiler design
The role of the parser and Error recovery strategies ppt in compiler designThe role of the parser and Error recovery strategies ppt in compiler design
The role of the parser and Error recovery strategies ppt in compiler designSadia Akter
 
The Theory of Finite Automata.pptx
The Theory of Finite Automata.pptxThe Theory of Finite Automata.pptx
The Theory of Finite Automata.pptxssuser039bf6
 
LVEE 2014: Text parsing with Python and PLY
LVEE 2014: Text parsing with Python and PLYLVEE 2014: Text parsing with Python and PLY
LVEE 2014: Text parsing with Python and PLYdmbaturin
 
Ch3 4 regular expression and grammar
Ch3 4 regular expression and grammarCh3 4 regular expression and grammar
Ch3 4 regular expression and grammarmeresie tesfay
 
Python Programming Basics for begginners
Python Programming Basics for begginnersPython Programming Basics for begginners
Python Programming Basics for begginnersAbishek Purushothaman
 

Similar to Lexical analyzer (20)

Compiler Design
Compiler DesignCompiler Design
Compiler Design
 
Pcd question bank
Pcd question bank Pcd question bank
Pcd question bank
 
Lex and Yacc Tool M1.ppt
Lex and Yacc Tool M1.pptLex and Yacc Tool M1.ppt
Lex and Yacc Tool M1.ppt
 
Compiler design important questions
Compiler design   important questionsCompiler design   important questions
Compiler design important questions
 
Ch 2.pptx
Ch 2.pptxCh 2.pptx
Ch 2.pptx
 
Introduction to R for beginners
Introduction to R for beginnersIntroduction to R for beginners
Introduction to R for beginners
 
Compilers Design
Compilers DesignCompilers Design
Compilers Design
 
LR PARSE.pptx
LR PARSE.pptxLR PARSE.pptx
LR PARSE.pptx
 
Compiler Designs
Compiler DesignsCompiler Designs
Compiler Designs
 
LANGUAGE PROCESSOR
LANGUAGE PROCESSORLANGUAGE PROCESSOR
LANGUAGE PROCESSOR
 
Handout#02
Handout#02Handout#02
Handout#02
 
COMPILER DESIGN- Introduction & Lexical Analysis:
COMPILER DESIGN- Introduction & Lexical Analysis: COMPILER DESIGN- Introduction & Lexical Analysis:
COMPILER DESIGN- Introduction & Lexical Analysis:
 
Chapter-3 compiler.pptx course materials
Chapter-3 compiler.pptx course materialsChapter-3 compiler.pptx course materials
Chapter-3 compiler.pptx course materials
 
Module4 lex and yacc.ppt
Module4 lex and yacc.pptModule4 lex and yacc.ppt
Module4 lex and yacc.ppt
 
The role of the parser and Error recovery strategies ppt in compiler design
The role of the parser and Error recovery strategies ppt in compiler designThe role of the parser and Error recovery strategies ppt in compiler design
The role of the parser and Error recovery strategies ppt in compiler design
 
The Theory of Finite Automata.pptx
The Theory of Finite Automata.pptxThe Theory of Finite Automata.pptx
The Theory of Finite Automata.pptx
 
LVEE 2014: Text parsing with Python and PLY
LVEE 2014: Text parsing with Python and PLYLVEE 2014: Text parsing with Python and PLY
LVEE 2014: Text parsing with Python and PLY
 
Ch3 4 regular expression and grammar
Ch3 4 regular expression and grammarCh3 4 regular expression and grammar
Ch3 4 regular expression and grammar
 
module 4.pptx
module 4.pptxmodule 4.pptx
module 4.pptx
 
Python Programming Basics for begginners
Python Programming Basics for begginnersPython Programming Basics for begginners
Python Programming Basics for begginners
 

Recently uploaded

2022 AWS DNA Hackathon 장애 대응 솔루션 jarvis.
2022 AWS DNA Hackathon 장애 대응 솔루션 jarvis.2022 AWS DNA Hackathon 장애 대응 솔루션 jarvis.
2022 AWS DNA Hackathon 장애 대응 솔루션 jarvis.elesangwon
 
Immutable Image-Based Operating Systems - EW2024.pdf
Immutable Image-Based Operating Systems - EW2024.pdfImmutable Image-Based Operating Systems - EW2024.pdf
Immutable Image-Based Operating Systems - EW2024.pdfDrew Moseley
 
Paper Tube : Shigeru Ban projects and Case Study of Cardboard Cathedral .pdf
Paper Tube : Shigeru Ban projects and Case Study of Cardboard Cathedral .pdfPaper Tube : Shigeru Ban projects and Case Study of Cardboard Cathedral .pdf
Paper Tube : Shigeru Ban projects and Case Study of Cardboard Cathedral .pdfNainaShrivastava14
 
Artificial Intelligence in Power System overview
Artificial Intelligence in Power System overviewArtificial Intelligence in Power System overview
Artificial Intelligence in Power System overviewsandhya757531
 
"Exploring the Essential Functions and Design Considerations of Spillways in ...
"Exploring the Essential Functions and Design Considerations of Spillways in ..."Exploring the Essential Functions and Design Considerations of Spillways in ...
"Exploring the Essential Functions and Design Considerations of Spillways in ...Erbil Polytechnic University
 
Python Programming for basic beginners.pptx
Python Programming for basic beginners.pptxPython Programming for basic beginners.pptx
Python Programming for basic beginners.pptxmohitesoham12
 
High Voltage Engineering- OVER VOLTAGES IN ELECTRICAL POWER SYSTEMS
High Voltage Engineering- OVER VOLTAGES IN ELECTRICAL POWER SYSTEMSHigh Voltage Engineering- OVER VOLTAGES IN ELECTRICAL POWER SYSTEMS
High Voltage Engineering- OVER VOLTAGES IN ELECTRICAL POWER SYSTEMSsandhya757531
 
Ch10-Global Supply Chain - Cadena de Suministro.pdf
Ch10-Global Supply Chain - Cadena de Suministro.pdfCh10-Global Supply Chain - Cadena de Suministro.pdf
Ch10-Global Supply Chain - Cadena de Suministro.pdfChristianCDAM
 
CME 397 - SURFACE ENGINEERING - UNIT 1 FULL NOTES
CME 397 - SURFACE ENGINEERING - UNIT 1 FULL NOTESCME 397 - SURFACE ENGINEERING - UNIT 1 FULL NOTES
CME 397 - SURFACE ENGINEERING - UNIT 1 FULL NOTESkarthi keyan
 
Cost estimation approach: FP to COCOMO scenario based question
Cost estimation approach: FP to COCOMO scenario based questionCost estimation approach: FP to COCOMO scenario based question
Cost estimation approach: FP to COCOMO scenario based questionSneha Padhiar
 
multiple access in wireless communication
multiple access in wireless communicationmultiple access in wireless communication
multiple access in wireless communicationpanditadesh123
 
Input Output Management in Operating System
Input Output Management in Operating SystemInput Output Management in Operating System
Input Output Management in Operating SystemRashmi Bhat
 
『澳洲文凭』买麦考瑞大学毕业证书成绩单办理澳洲Macquarie文凭学位证书
『澳洲文凭』买麦考瑞大学毕业证书成绩单办理澳洲Macquarie文凭学位证书『澳洲文凭』买麦考瑞大学毕业证书成绩单办理澳洲Macquarie文凭学位证书
『澳洲文凭』买麦考瑞大学毕业证书成绩单办理澳洲Macquarie文凭学位证书rnrncn29
 
signals in triangulation .. ...Surveying
signals in triangulation .. ...Surveyingsignals in triangulation .. ...Surveying
signals in triangulation .. ...Surveyingsapna80328
 
Gravity concentration_MI20612MI_________
Gravity concentration_MI20612MI_________Gravity concentration_MI20612MI_________
Gravity concentration_MI20612MI_________Romil Mishra
 
TEST CASE GENERATION GENERATION BLOCK BOX APPROACH
TEST CASE GENERATION GENERATION BLOCK BOX APPROACHTEST CASE GENERATION GENERATION BLOCK BOX APPROACH
TEST CASE GENERATION GENERATION BLOCK BOX APPROACHSneha Padhiar
 
Energy Awareness training ppt for manufacturing process.pptx
Energy Awareness training ppt for manufacturing process.pptxEnergy Awareness training ppt for manufacturing process.pptx
Energy Awareness training ppt for manufacturing process.pptxsiddharthjain2303
 
Prach: A Feature-Rich Platform Empowering the Autism Community
Prach: A Feature-Rich Platform Empowering the Autism CommunityPrach: A Feature-Rich Platform Empowering the Autism Community
Prach: A Feature-Rich Platform Empowering the Autism Communityprachaibot
 
Module-1-(Building Acoustics) Noise Control (Unit-3). pdf
Module-1-(Building Acoustics) Noise Control (Unit-3). pdfModule-1-(Building Acoustics) Noise Control (Unit-3). pdf
Module-1-(Building Acoustics) Noise Control (Unit-3). pdfManish Kumar
 

Recently uploaded (20)

2022 AWS DNA Hackathon 장애 대응 솔루션 jarvis.
2022 AWS DNA Hackathon 장애 대응 솔루션 jarvis.2022 AWS DNA Hackathon 장애 대응 솔루션 jarvis.
2022 AWS DNA Hackathon 장애 대응 솔루션 jarvis.
 
Designing pile caps according to ACI 318-19.pptx
Designing pile caps according to ACI 318-19.pptxDesigning pile caps according to ACI 318-19.pptx
Designing pile caps according to ACI 318-19.pptx
 
Immutable Image-Based Operating Systems - EW2024.pdf
Immutable Image-Based Operating Systems - EW2024.pdfImmutable Image-Based Operating Systems - EW2024.pdf
Immutable Image-Based Operating Systems - EW2024.pdf
 
Paper Tube : Shigeru Ban projects and Case Study of Cardboard Cathedral .pdf
Paper Tube : Shigeru Ban projects and Case Study of Cardboard Cathedral .pdfPaper Tube : Shigeru Ban projects and Case Study of Cardboard Cathedral .pdf
Paper Tube : Shigeru Ban projects and Case Study of Cardboard Cathedral .pdf
 
Artificial Intelligence in Power System overview
Artificial Intelligence in Power System overviewArtificial Intelligence in Power System overview
Artificial Intelligence in Power System overview
 
"Exploring the Essential Functions and Design Considerations of Spillways in ...
"Exploring the Essential Functions and Design Considerations of Spillways in ..."Exploring the Essential Functions and Design Considerations of Spillways in ...
"Exploring the Essential Functions and Design Considerations of Spillways in ...
 
Python Programming for basic beginners.pptx
Python Programming for basic beginners.pptxPython Programming for basic beginners.pptx
Python Programming for basic beginners.pptx
 
High Voltage Engineering- OVER VOLTAGES IN ELECTRICAL POWER SYSTEMS
High Voltage Engineering- OVER VOLTAGES IN ELECTRICAL POWER SYSTEMSHigh Voltage Engineering- OVER VOLTAGES IN ELECTRICAL POWER SYSTEMS
High Voltage Engineering- OVER VOLTAGES IN ELECTRICAL POWER SYSTEMS
 
Ch10-Global Supply Chain - Cadena de Suministro.pdf
Ch10-Global Supply Chain - Cadena de Suministro.pdfCh10-Global Supply Chain - Cadena de Suministro.pdf
Ch10-Global Supply Chain - Cadena de Suministro.pdf
 
CME 397 - SURFACE ENGINEERING - UNIT 1 FULL NOTES
CME 397 - SURFACE ENGINEERING - UNIT 1 FULL NOTESCME 397 - SURFACE ENGINEERING - UNIT 1 FULL NOTES
CME 397 - SURFACE ENGINEERING - UNIT 1 FULL NOTES
 
Cost estimation approach: FP to COCOMO scenario based question
Cost estimation approach: FP to COCOMO scenario based questionCost estimation approach: FP to COCOMO scenario based question
Cost estimation approach: FP to COCOMO scenario based question
 
multiple access in wireless communication
multiple access in wireless communicationmultiple access in wireless communication
multiple access in wireless communication
 
Input Output Management in Operating System
Input Output Management in Operating SystemInput Output Management in Operating System
Input Output Management in Operating System
 
『澳洲文凭』买麦考瑞大学毕业证书成绩单办理澳洲Macquarie文凭学位证书
『澳洲文凭』买麦考瑞大学毕业证书成绩单办理澳洲Macquarie文凭学位证书『澳洲文凭』买麦考瑞大学毕业证书成绩单办理澳洲Macquarie文凭学位证书
『澳洲文凭』买麦考瑞大学毕业证书成绩单办理澳洲Macquarie文凭学位证书
 
signals in triangulation .. ...Surveying
signals in triangulation .. ...Surveyingsignals in triangulation .. ...Surveying
signals in triangulation .. ...Surveying
 
Gravity concentration_MI20612MI_________
Gravity concentration_MI20612MI_________Gravity concentration_MI20612MI_________
Gravity concentration_MI20612MI_________
 
TEST CASE GENERATION GENERATION BLOCK BOX APPROACH
TEST CASE GENERATION GENERATION BLOCK BOX APPROACHTEST CASE GENERATION GENERATION BLOCK BOX APPROACH
TEST CASE GENERATION GENERATION BLOCK BOX APPROACH
 
Energy Awareness training ppt for manufacturing process.pptx
Energy Awareness training ppt for manufacturing process.pptxEnergy Awareness training ppt for manufacturing process.pptx
Energy Awareness training ppt for manufacturing process.pptx
 
Prach: A Feature-Rich Platform Empowering the Autism Community
Prach: A Feature-Rich Platform Empowering the Autism CommunityPrach: A Feature-Rich Platform Empowering the Autism Community
Prach: A Feature-Rich Platform Empowering the Autism Community
 
Module-1-(Building Acoustics) Noise Control (Unit-3). pdf
Module-1-(Building Acoustics) Noise Control (Unit-3). pdfModule-1-(Building Acoustics) Noise Control (Unit-3). pdf
Module-1-(Building Acoustics) Noise Control (Unit-3). pdf
 

Lexical analyzer

  • 1. By : Kiran Acharya inspireray.blogspot.in
  • 2. Introduction to lexical Analyzer Input buffering Specifications of tokens Regular expressions inspireray.blogspot.in
  • 3. There are two basic rules in regular expression. 1. ɛ is a regular expression and L(ɛ), that is the language whose sole number is an empty string. 2. If a is a symbol in Ʃ , then a is a regular expression with one string of length one , with a at its first position. inspireray.blogspot.in
  • 4. (r)|(s) is a regular expression denoting L(r)ỤL(s). (r)(s) is a regular expression means L(r)L(s). (r)* means regular expression(L(r)). inspireray.blogspot.in
  • 5. Unary operator * has the highest precedence and its left associative. Concatenation has second and its left associative. | has the lowest and left associative. inspireray.blogspot.in
  • 6. Language that can be defined by regular expression is called regular set if regular expression r and s are from same set they are equivalent. (a|b)=(b|a) inspireray.blogspot.in
  • 7. It’s a sequence of definitions of the form: d1→r1; d2→r2; each d is a new symbol r is regular expression over alphabets. inspireray.blogspot.in
  • 8. Kleene closure extended in 50’s One or more instances Zero or one instance. Character class. inspireray.blogspot.in
  • 9. Taking the patterns from tokens and build piece of code that examines the input find the prefix that is the lexeme matching one of the pattern. Methods: 1. Transition Diagrams 2. Recognition of reverse words and identifier 3. Completion of running example. inspireray.blogspot.in
  • 10. These are first flow charts. Conversion from patterns to transition diagram. It has states. Edges input inspireray.blogspot.in
  • 11. First and final state Accepting state Start state inspireray.blogspot.in
  • 12. Finding keywords and identifiers are the problem. Return(gettoken(),installid()) 0 10 11 start letter Letter or digit othe r inspireray.blogspot.in
  • 13. Tool lex Input is lex language tool itself is a lex compiler. Input file is lex.l Compiler transform it into c program Lex.yy.c And later the file is compiled by c to a.out inspireray.blogspot.in
  • 14. Declarations: %% Translation rules %% Auxiliary functions inspireray.blogspot.in
  • 15. Always prefer a longer prefix over the shorter It longer matches the two or more patterns then prefer the pattern listed first. Look Ahead operator: / is inserted to know the end of the part of lexeme. inspireray.blogspot.in
  • 16. The heart of the transition of lex turning input program to lexical analyzer is finite automata. Finite automata are recognizers they just say yes or no. Two types: 1. Non deterministic 2. Deterministic inspireray.blogspot.in
  • 17. No restrictions to the edges from the same state. Finite state of state s Input alphabet Ʃ Transition function Start state Final state inspireray.blogspot.in
  • 18. State a b ɛ 0 {0,1} {0} ф 1 ф {2} ф 2 ф {3} ф 3 ф ф Ф inspireray.blogspot.in
  • 20. There is exactly one edge form the input to the next state. inspireray.blogspot.in