SlideShare a Scribd company logo
4
Most read
10
Most read
15
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

PPTX
Finite automata-for-lexical-analysis
PDF
Code optimization in compiler design
PPTX
Image encryption and decryption
PPTX
Assemblers
PPTX
A simple approach of lexical analyzers
PPTX
Recognition-of-tokens
PPTX
Unit 3 sp assembler
PPT
Coupling and cohesion
Finite automata-for-lexical-analysis
Code optimization in compiler design
Image encryption and decryption
Assemblers
A simple approach of lexical analyzers
Recognition-of-tokens
Unit 3 sp assembler
Coupling and cohesion

What's hot (20)

PPTX
Syntax Analysis in Compiler Design
PPTX
Decision properties of reular languages
PPTX
And or graph
PPTX
Context free grammar
PPT
Multi Head, Multi Tape Turing Machine
PPT
Agile Development | Agile Process Models
PDF
Introduction to systems programming
PDF
Algorithmic problem solving
PDF
Deterministic Finite Automata (DFA)
PPTX
Loaders ( system programming )
PPT
pipelining
PDF
Semaphores
PPTX
Linker and Loader
PPT
1.Role lexical Analyzer
PPTX
Language processing activity
PPTX
Daa unit 1
PPTX
Common Standards in Cloud Computing
PDF
Lecture 01 introduction to compiler
PPT
Intermediate code generation (Compiler Design)
PPT
Introduction to Compiler design
Syntax Analysis in Compiler Design
Decision properties of reular languages
And or graph
Context free grammar
Multi Head, Multi Tape Turing Machine
Agile Development | Agile Process Models
Introduction to systems programming
Algorithmic problem solving
Deterministic Finite Automata (DFA)
Loaders ( system programming )
pipelining
Semaphores
Linker and Loader
1.Role lexical Analyzer
Language processing activity
Daa unit 1
Common Standards in Cloud Computing
Lecture 01 introduction to compiler
Intermediate code generation (Compiler Design)
Introduction to Compiler design
Ad

Similar to Language for specifying lexical Analyzer (20)

PDF
role of lexical parser compiler design1-181124035217.pdf
PPT
Module4 lex and yacc.ppt
PPTX
Cd ch2 - lexical analysis
PPTX
automata theroy and compiler designc.pptx
DOCX
Compiler Design
PDF
11700220036.pdf
PPTX
Compiler Design_LEX Tool for Lexical Analysis.pptx
PPT
Chapter-2-lexical-analyser and its property lecture note.ppt
PPTX
Lexical Analyzer Implementation
PPT
module 4_ Lex_new.ppt
PPT
Data design and analysis of computing tools
PPT
LEX Intrduction Compiler Construction_VIET.ppt
PPTX
"Lexical Analysis for GATE and CS Exams"
PDF
Handout#02
PPTX
Chapter 2.pptx compiler design lecture note
PDF
Compiler_Design_Introduction_Unit_2_IIT.pdf
PDF
An Introduction to the Compiler Designss
PPTX
CD UNIT-1.3 LEX PPT.pptx
PPTX
Valuable Information on Lexical Analysis in Compiler Design
role of lexical parser compiler design1-181124035217.pdf
Module4 lex and yacc.ppt
Cd ch2 - lexical analysis
automata theroy and compiler designc.pptx
Compiler Design
11700220036.pdf
Compiler Design_LEX Tool for Lexical Analysis.pptx
Chapter-2-lexical-analyser and its property lecture note.ppt
Lexical Analyzer Implementation
module 4_ Lex_new.ppt
Data design and analysis of computing tools
LEX Intrduction Compiler Construction_VIET.ppt
"Lexical Analysis for GATE and CS Exams"
Handout#02
Chapter 2.pptx compiler design lecture note
Compiler_Design_Introduction_Unit_2_IIT.pdf
An Introduction to the Compiler Designss
CD UNIT-1.3 LEX PPT.pptx
Valuable Information on Lexical Analysis in Compiler Design
Ad

More from Archana Gopinath (20)

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

Recently uploaded (20)

PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PPTX
Pharma ospi slides which help in ospi learning
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
Computing-Curriculum for Schools in Ghana
PDF
Insiders guide to clinical Medicine.pdf
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PPTX
Institutional Correction lecture only . . .
PDF
TR - Agricultural Crops Production NC III.pdf
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PPTX
Lesson notes of climatology university.
PDF
01-Introduction-to-Information-Management.pdf
PDF
RMMM.pdf make it easy to upload and study
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
102 student loan defaulters named and shamed – Is someone you know on the list?
Pharma ospi slides which help in ospi learning
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Computing-Curriculum for Schools in Ghana
Insiders guide to clinical Medicine.pdf
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Renaissance Architecture: A Journey from Faith to Humanism
Institutional Correction lecture only . . .
TR - Agricultural Crops Production NC III.pdf
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Microbial diseases, their pathogenesis and prophylaxis
Abdominal Access Techniques with Prof. Dr. R K Mishra
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
Module 4: Burden of Disease Tutorial Slides S2 2025
human mycosis Human fungal infections are called human mycosis..pptx
Lesson notes of climatology university.
01-Introduction-to-Information-Management.pdf
RMMM.pdf make it easy to upload and study
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...

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