SlideShare a Scribd company logo
4
Most read
7
Most read
10
Most read
The Language for Specifying Lexical
Analyzer
Myself Archana R
Assistant Professor In
Department Of Computer Science
SACWC.
I am here because I love to
give presentations.
 Compiler design principles provide an in-depth view of translation
and optimization process.
 Compiler design covers basic translation mechanism and error
detection & recovery.
 It includes lexical, syntax, and semantic analysis as front end, and
code generation and optimization as back-end.
COMPILER DESIGN
The Language for Specifying Lexical Analyzer
A LEX source program is a specification of a lexical analyzer, consisting of a set of
regular expressions together with an action for each regular expression.
The action is a piece of code which is to be executed whenever a token specified by the
corresponding regular expression is recognized.
The output of LEX is a lexical analyzer program constructed from the LEX source
specification.
LEX
Unlike most programming languages, a source program for LEX does not supply all the
details of the intended computation.
Rather, LEX itself supplies with its output a program that simulates a finite automaton.
This program takes a transition table as data.
The transition table is that portion of LEX's output that stems directly from LEX's input.
where the lexical analyzer L is the transition table plus the program to simulate an
arbitrary finite automaton expressed as a transition table.
Only L is to be included in the compiler being built.
(cont)
Input Text Sequence of tokens
Lexical
Analyzer L
LEX Source Lexical Analyzer L
LEX
Compiler
THE ROLE OF LEX
A LEX source program consists of two parts, a sequence of auxiliary definition
followed by a sequence of translation rules.
AUXILIARY DEFINITIONS:
The auxiliary definitions are statements of the form:
D1=R1
D2=R2
…..
Dn=Rn
Where each Di is a distinct name, and each Ri is a regular expression whose
symbol are chosen from Σ ∪ {D1, D2, Di-1}, i.e., characters or previously defined
names. The Di's are shorthand names for regular expressions. Σ Is our input symbol
alphabet.
We can define the class of identifiers for a typical programming language with the
sequence of auxiliary definitions.
Letter = A|B|…|Z
Digit = 0|1|…|9
Identifier = Letter (Letter|Digit)*
Example:
The translation rules of a LEX program are statements of the form:-
P1 {A1}
P2 {A2}
……
Pm {Am}
Where each Pi is a regular expression called a pattern, over the alphabet consisting
of Σ and the auxiliary definition names.
The patterns describe the form of the tokens. Each Ai is a program fragment
describing what action the lexical analyzer should take when token Pi is found.
The Ai's are written in a conventional programming language, rather than any
particular language, we use pseudo language.
To create the lexical analyzer L, each of the Ai's must be compiled into machine
code.
Translation Rules
The lexical analyzer L created by LEX behaves in the following manner:
L read its input, one characters at a time, until it has found the longest prefix of the input
which matches one of the regular expressions, Pi.
Once L has found that prefix, L removes it from the input and places it in a buffer called
TOKEN.
(Actually, TOKEN may be a pair of pointers to the beginning and end of the matched
string in the input buffer itself.).
L then executes the action Ai.
It is possible, that non of the regular expressions denoting the tokens
matches any prefix of the input.
In that case, an error has occurred, and L transfers control to some
error handling routine. It is also possible that two or more patterns match
the same longest prefix of the remaining input.
If that is . . . the case, L will break the tie in favor of that token which
came first in the list of translation rules.
Example:
AUXILIARY DEFINITION
Letter= A|B|…|Z
Digit= 0|1|…|9
BEGIN {return 1}
END {return 2}
IF {return 3}
THEN {return 4}
ELSE {return 5}
letter(letter|digit)* {LEX VAL:= INSTALL( ); return
6}
digit+ {LEX VAL:= INSTALL( ); return
7}
< {LEX VAL := 1; return 8}
<= {LEX VAL := 2; return 8}
= {LEX VAL := 3; return 8}
< > {LEX VAL := 4; return 8}
> {LEX VAL := 5; return 8}
>= {LEX VAL := 6; return 8}
TRANSLATION RULES :
Suppose the lexical analyzer resulting from the above rules is given input
BEGIN followed by blank.
Both the first and sixth pattern matches BEGIN, and no pattern matches a longer
string.
Since the pattern for keyword BEGIN precedes the pattern for identifier in the
above list, the conflict is resolved in favor of the keyword.
For another example,
suppose <= are the first two characters read.
While pattern < matches the first character, it is not the longest pattern matching
a prefix of the input.
Thus LEX's strategy that the longest prefix matching a pattern is selected makes
it easy to resolve the conflict between < and <=, by choosing <= as the next
tokens.
Lexical analyzer method is used by programs like compilers which can use the parsed
data from a programmer’s code to create a compiled binary executable code
It is used by web browsers to format and display a web page with the help of parsed
data from JavaScript, HTML, CSS
A separate lexical analyzer helps you to construct a specialized and potentially more
efficient processor for the task
Advantages of Lexical analysis
Language for specifying lexical Analyzer

More Related Content

What's hot (20)

PPTX
Inductive analytical approaches to learning
swapnac12
 
PPTX
8 queen problem
NagajothiN1
 
PPTX
Decision tree induction
thamizh arasi
 
PDF
Symbol table in compiler Design
Kuppusamy P
 
PPTX
Multicastingand multicast routing protocols
Iffat Anjum
 
PDF
I. AO* SEARCH ALGORITHM
vikas dhakane
 
PPTX
Specification-of-tokens
Dattatray Gandhmal
 
PPTX
Pattern recognition UNIT 5
Dr. SURBHI SAROHA
 
PPTX
Routing algorithm
Bushra M
 
PPTX
Dag representation of basic blocks
Jothi Lakshmi
 
PPTX
Lecture 06 production system
Hema Kashyap
 
PDF
Vc dimension in Machine Learning
VARUN KUMAR
 
PPTX
computer network OSI layer
Sangeetha Rangarajan
 
PPT
TCP/IP Network ppt
extraganesh
 
PPT
Introduction to Compiler design
Dr. C.V. Suresh Babu
 
PPTX
Logics for non monotonic reasoning-ai
ShaishavShah8
 
PPTX
Loop optimization
Vivek Gandhi
 
PDF
Network security & cryptography full notes
gangadhar9989166446
 
PPTX
Three address code In Compiler Design
Shine Raj
 
Inductive analytical approaches to learning
swapnac12
 
8 queen problem
NagajothiN1
 
Decision tree induction
thamizh arasi
 
Symbol table in compiler Design
Kuppusamy P
 
Multicastingand multicast routing protocols
Iffat Anjum
 
I. AO* SEARCH ALGORITHM
vikas dhakane
 
Specification-of-tokens
Dattatray Gandhmal
 
Pattern recognition UNIT 5
Dr. SURBHI SAROHA
 
Routing algorithm
Bushra M
 
Dag representation of basic blocks
Jothi Lakshmi
 
Lecture 06 production system
Hema Kashyap
 
Vc dimension in Machine Learning
VARUN KUMAR
 
computer network OSI layer
Sangeetha Rangarajan
 
TCP/IP Network ppt
extraganesh
 
Introduction to Compiler design
Dr. C.V. Suresh Babu
 
Logics for non monotonic reasoning-ai
ShaishavShah8
 
Loop optimization
Vivek Gandhi
 
Network security & cryptography full notes
gangadhar9989166446
 
Three address code In Compiler Design
Shine Raj
 

Similar to Language for specifying lexical Analyzer (20)

DOCX
Compiler Design
Anujashejwal
 
PPTX
Ch 2.pptx
woldu2
 
PPT
Module4 lex and yacc.ppt
ProddaturNagaVenkata
 
PPT
Chapter-2-lexical-analyser and its property lecture note.ppt
anwarkade1
 
PDF
Handout#02
Sunita Milind Dol
 
PPTX
A Role of Lexical Analyzer
Archana Gopinath
 
DOC
Pcd question bank
Sumathi Gnanasekaran
 
PPT
Lexical analyzer
Ashwini Sonawane
 
PPTX
Chapter 2.pptx compiler design lecture note
adugnanegero
 
PPT
module 4_ Lex_new.ppt
leyobi6147
 
PPTX
Chahioiuou9oioooooooooooooofffghfpterTwo.pptx
dejenehundaol91
 
PDF
LANGUAGE PROCESSOR
EZIOAUDITORE15070
 
PPT
atc 3rd module compiler and automata.ppt
ranjan317165
 
PDF
COMPILER DESIGN.pdf
ManishBej3
 
PPT
LexicalAnalysis in Compiler design .pt
Sannidhanapuharika
 
PPTX
Chapter-3 compiler.pptx course materials
gadisaAdamu
 
PDF
11700220036.pdf
SouvikRoy149
 
PDF
Lexical Analysis - Compiler design
Aman Sharma
 
PPTX
Compiler Design_LEX Tool for Lexical Analysis.pptx
RushaliDeshmukh2
 
PPTX
Parser
Ghufran Hashmi
 
Compiler Design
Anujashejwal
 
Ch 2.pptx
woldu2
 
Module4 lex and yacc.ppt
ProddaturNagaVenkata
 
Chapter-2-lexical-analyser and its property lecture note.ppt
anwarkade1
 
Handout#02
Sunita Milind Dol
 
A Role of Lexical Analyzer
Archana Gopinath
 
Pcd question bank
Sumathi Gnanasekaran
 
Lexical analyzer
Ashwini Sonawane
 
Chapter 2.pptx compiler design lecture note
adugnanegero
 
module 4_ Lex_new.ppt
leyobi6147
 
Chahioiuou9oioooooooooooooofffghfpterTwo.pptx
dejenehundaol91
 
LANGUAGE PROCESSOR
EZIOAUDITORE15070
 
atc 3rd module compiler and automata.ppt
ranjan317165
 
COMPILER DESIGN.pdf
ManishBej3
 
LexicalAnalysis in Compiler design .pt
Sannidhanapuharika
 
Chapter-3 compiler.pptx course materials
gadisaAdamu
 
11700220036.pdf
SouvikRoy149
 
Lexical Analysis - Compiler design
Aman Sharma
 
Compiler Design_LEX Tool for Lexical Analysis.pptx
RushaliDeshmukh2
 
Ad

More from Archana Gopinath (20)

PDF
The Graph Abstract Data Type-DATA STRUCTURE.pdf
Archana Gopinath
 
PPTX
Introduction-to-Binary-Tree-Traversal.pptx
Archana Gopinath
 
PPTX
DNS-Translates domain names into IP addresses.pptx
Archana Gopinath
 
PPTX
Data Transfer & Manipulation.pptx
Archana Gopinath
 
PPTX
DP _ CO Instruction Format.pptx
Archana Gopinath
 
PPTX
Implementation of lexical analyser
Archana Gopinath
 
PPTX
A simple approach of lexical analyzers
Archana Gopinath
 
PPTX
minimization the number of states of DFA
Archana Gopinath
 
PPTX
Regular Expression to Finite Automata
Archana Gopinath
 
PPTX
Fundamentals of big data analytics and Hadoop
Archana Gopinath
 
PPTX
Map reduce in Hadoop BIG DATA ANALYTICS
Archana Gopinath
 
PPTX
Business intelligence
Archana Gopinath
 
PPTX
Hadoop
Archana Gopinath
 
PPTX
Programming with R in Big Data Analytics
Archana Gopinath
 
PPTX
If statements in c programming
Archana Gopinath
 
PPT
un Guided media
Archana Gopinath
 
PPT
Guided media Transmission Media
Archana Gopinath
 
PPTX
Main Memory RAM and ROM
Archana Gopinath
 
PDF
Java thread life cycle
Archana Gopinath
 
PPTX
PCSTt11 overview of java
Archana Gopinath
 
The Graph Abstract Data Type-DATA STRUCTURE.pdf
Archana Gopinath
 
Introduction-to-Binary-Tree-Traversal.pptx
Archana Gopinath
 
DNS-Translates domain names into IP addresses.pptx
Archana Gopinath
 
Data Transfer & Manipulation.pptx
Archana Gopinath
 
DP _ CO Instruction Format.pptx
Archana Gopinath
 
Implementation of lexical analyser
Archana Gopinath
 
A simple approach of lexical analyzers
Archana Gopinath
 
minimization the number of states of DFA
Archana Gopinath
 
Regular Expression to Finite Automata
Archana Gopinath
 
Fundamentals of big data analytics and Hadoop
Archana Gopinath
 
Map reduce in Hadoop BIG DATA ANALYTICS
Archana Gopinath
 
Business intelligence
Archana Gopinath
 
Programming with R in Big Data Analytics
Archana Gopinath
 
If statements in c programming
Archana Gopinath
 
un Guided media
Archana Gopinath
 
Guided media Transmission Media
Archana Gopinath
 
Main Memory RAM and ROM
Archana Gopinath
 
Java thread life cycle
Archana Gopinath
 
PCSTt11 overview of java
Archana Gopinath
 
Ad

Recently uploaded (20)

PPTX
Basics and rules of probability with real-life uses
ravatkaran694
 
PPT
DRUGS USED IN THERAPY OF SHOCK, Shock Therapy, Treatment or management of shock
Rajshri Ghogare
 
PPTX
INTESTINALPARASITES OR WORM INFESTATIONS.pptx
PRADEEP ABOTHU
 
PDF
Tips for Writing the Research Title with Examples
Thelma Villaflores
 
PPTX
TOP 10 AI TOOLS YOU MUST LEARN TO SURVIVE IN 2025 AND ABOVE
digilearnings.com
 
PDF
Virat Kohli- the Pride of Indian cricket
kushpar147
 
DOCX
Modul Ajar Deep Learning Bahasa Inggris Kelas 11 Terbaru 2025
wahyurestu63
 
PPTX
Digital Professionalism and Interpersonal Competence
rutvikgediya1
 
PPTX
I INCLUDED THIS TOPIC IS INTELLIGENCE DEFINITION, MEANING, INDIVIDUAL DIFFERE...
parmarjuli1412
 
PPTX
K-Circle-Weekly-Quiz12121212-May2025.pptx
Pankaj Rodey
 
PPTX
Electrophysiology_of_Heart. Electrophysiology studies in Cardiovascular syste...
Rajshri Ghogare
 
PPTX
Translation_ Definition, Scope & Historical Development.pptx
DhatriParmar
 
PPTX
LDP-2 UNIT 4 Presentation for practical.pptx
abhaypanchal2525
 
PPTX
Python-Application-in-Drug-Design by R D Jawarkar.pptx
Rahul Jawarkar
 
PPTX
Applied-Statistics-1.pptx hardiba zalaaa
hardizala899
 
PPTX
The Future of Artificial Intelligence Opportunities and Risks Ahead
vaghelajayendra784
 
PPTX
Top 10 AI Tools, Like ChatGPT. You Must Learn In 2025
Digilearnings
 
PPTX
Continental Accounting in Odoo 18 - Odoo Slides
Celine George
 
PPTX
Introduction to Probability(basic) .pptx
purohitanuj034
 
PDF
BÀI TẬP TEST BỔ TRỢ THEO TỪNG CHỦ ĐỀ CỦA TỪNG UNIT KÈM BÀI TẬP NGHE - TIẾNG A...
Nguyen Thanh Tu Collection
 
Basics and rules of probability with real-life uses
ravatkaran694
 
DRUGS USED IN THERAPY OF SHOCK, Shock Therapy, Treatment or management of shock
Rajshri Ghogare
 
INTESTINALPARASITES OR WORM INFESTATIONS.pptx
PRADEEP ABOTHU
 
Tips for Writing the Research Title with Examples
Thelma Villaflores
 
TOP 10 AI TOOLS YOU MUST LEARN TO SURVIVE IN 2025 AND ABOVE
digilearnings.com
 
Virat Kohli- the Pride of Indian cricket
kushpar147
 
Modul Ajar Deep Learning Bahasa Inggris Kelas 11 Terbaru 2025
wahyurestu63
 
Digital Professionalism and Interpersonal Competence
rutvikgediya1
 
I INCLUDED THIS TOPIC IS INTELLIGENCE DEFINITION, MEANING, INDIVIDUAL DIFFERE...
parmarjuli1412
 
K-Circle-Weekly-Quiz12121212-May2025.pptx
Pankaj Rodey
 
Electrophysiology_of_Heart. Electrophysiology studies in Cardiovascular syste...
Rajshri Ghogare
 
Translation_ Definition, Scope & Historical Development.pptx
DhatriParmar
 
LDP-2 UNIT 4 Presentation for practical.pptx
abhaypanchal2525
 
Python-Application-in-Drug-Design by R D Jawarkar.pptx
Rahul Jawarkar
 
Applied-Statistics-1.pptx hardiba zalaaa
hardizala899
 
The Future of Artificial Intelligence Opportunities and Risks Ahead
vaghelajayendra784
 
Top 10 AI Tools, Like ChatGPT. You Must Learn In 2025
Digilearnings
 
Continental Accounting in Odoo 18 - Odoo Slides
Celine George
 
Introduction to Probability(basic) .pptx
purohitanuj034
 
BÀI TẬP TEST BỔ TRỢ THEO TỪNG CHỦ ĐỀ CỦA TỪNG UNIT KÈM BÀI TẬP NGHE - TIẾNG A...
Nguyen Thanh Tu Collection
 

Language for specifying lexical Analyzer

  • 1. The Language for Specifying Lexical Analyzer Myself Archana R Assistant Professor In Department Of Computer Science SACWC. I am here because I love to give presentations.
  • 2.  Compiler design principles provide an in-depth view of translation and optimization process.  Compiler design covers basic translation mechanism and error detection & recovery.  It includes lexical, syntax, and semantic analysis as front end, and code generation and optimization as back-end. COMPILER DESIGN
  • 3. The Language for Specifying Lexical Analyzer
  • 4. A LEX source program is a specification of a lexical analyzer, consisting of a set of regular expressions together with an action for each regular expression. The action is a piece of code which is to be executed whenever a token specified by the corresponding regular expression is recognized. The output of LEX is a lexical analyzer program constructed from the LEX source specification. LEX
  • 5. Unlike most programming languages, a source program for LEX does not supply all the details of the intended computation. Rather, LEX itself supplies with its output a program that simulates a finite automaton. This program takes a transition table as data. The transition table is that portion of LEX's output that stems directly from LEX's input. where the lexical analyzer L is the transition table plus the program to simulate an arbitrary finite automaton expressed as a transition table. Only L is to be included in the compiler being built. (cont)
  • 6. Input Text Sequence of tokens Lexical Analyzer L LEX Source Lexical Analyzer L LEX Compiler THE ROLE OF LEX
  • 7. A LEX source program consists of two parts, a sequence of auxiliary definition followed by a sequence of translation rules. AUXILIARY DEFINITIONS: The auxiliary definitions are statements of the form: D1=R1 D2=R2 ….. Dn=Rn Where each Di is a distinct name, and each Ri is a regular expression whose symbol are chosen from Σ ∪ {D1, D2, Di-1}, i.e., characters or previously defined names. The Di's are shorthand names for regular expressions. Σ Is our input symbol alphabet.
  • 8. We can define the class of identifiers for a typical programming language with the sequence of auxiliary definitions. Letter = A|B|…|Z Digit = 0|1|…|9 Identifier = Letter (Letter|Digit)* Example:
  • 9. The translation rules of a LEX program are statements of the form:- P1 {A1} P2 {A2} …… Pm {Am} Where each Pi is a regular expression called a pattern, over the alphabet consisting of Σ and the auxiliary definition names. The patterns describe the form of the tokens. Each Ai is a program fragment describing what action the lexical analyzer should take when token Pi is found. The Ai's are written in a conventional programming language, rather than any particular language, we use pseudo language. To create the lexical analyzer L, each of the Ai's must be compiled into machine code. Translation Rules
  • 10. The lexical analyzer L created by LEX behaves in the following manner: L read its input, one characters at a time, until it has found the longest prefix of the input which matches one of the regular expressions, Pi. Once L has found that prefix, L removes it from the input and places it in a buffer called TOKEN. (Actually, TOKEN may be a pair of pointers to the beginning and end of the matched string in the input buffer itself.). L then executes the action Ai.
  • 11. It is possible, that non of the regular expressions denoting the tokens matches any prefix of the input. In that case, an error has occurred, and L transfers control to some error handling routine. It is also possible that two or more patterns match the same longest prefix of the remaining input. If that is . . . the case, L will break the tie in favor of that token which came first in the list of translation rules.
  • 13. BEGIN {return 1} END {return 2} IF {return 3} THEN {return 4} ELSE {return 5} letter(letter|digit)* {LEX VAL:= INSTALL( ); return 6} digit+ {LEX VAL:= INSTALL( ); return 7} < {LEX VAL := 1; return 8} <= {LEX VAL := 2; return 8} = {LEX VAL := 3; return 8} < > {LEX VAL := 4; return 8} > {LEX VAL := 5; return 8} >= {LEX VAL := 6; return 8} TRANSLATION RULES :
  • 14. Suppose the lexical analyzer resulting from the above rules is given input BEGIN followed by blank. Both the first and sixth pattern matches BEGIN, and no pattern matches a longer string. Since the pattern for keyword BEGIN precedes the pattern for identifier in the above list, the conflict is resolved in favor of the keyword. For another example, suppose <= are the first two characters read. While pattern < matches the first character, it is not the longest pattern matching a prefix of the input. Thus LEX's strategy that the longest prefix matching a pattern is selected makes it easy to resolve the conflict between < and <=, by choosing <= as the next tokens.
  • 15. Lexical analyzer method is used by programs like compilers which can use the parsed data from a programmer’s code to create a compiled binary executable code It is used by web browsers to format and display a web page with the help of parsed data from JavaScript, HTML, CSS A separate lexical analyzer helps you to construct a specialized and potentially more efficient processor for the task Advantages of Lexical analysis