A LANGUAGE FOR SPECIFYING LEXICAL ANALYZER
There is a wide range of tools for constructing lexical analyzers.
Lex
YACC
Lex is a computer program that generates lexical analyzers. Lex is commonly used with the yacc parser generator.
Creating a lexical analyzer
Lex Specification
A Lex program consists of three parts:
{ definitions }
%%
{ rules }
%%
{ user subroutines }
Definitions include declarations of variables, constants, and regular definitions
p1 {action1}
p2 {action2}
…
pn {actionn}
where pi is regular expression and actioni describes what action the lexical analyzer should take
when pattern pi matches a lexeme. Actions are written in C code.
YACC- YET ANOTHER COMPILER-COMPILER
Yacc provides a general tool for describing the input to a computer program. The Yacc user specifies the structures of his input, together with code to be invoked as each such structure is recognized.
Yacc turns such a specification into a subroutine that handles the input process; frequently, it is convenient and appropriate to have most of the flow of control in the user's application handled by this subroutine.
Finite Automata
Finite Automata is one of the mathematical models that consist of a number of states and edges. It is a transition diagram that recognizes a regular expression or grammar.
There are tow types of Finite Automata :
Deterministic Finite Automata
DFA is a special case of a NFA in which i) no state has an ε-transition.
ii) there is at most one transition from each state on any input.
DFA has five tuples denoted by
M = {Qd, Ʃ, δ, q0, fd}
Qd – finite set of states
Ʃ – finite set of input symbols
Construction of DFA from regular expression
The following steps are involved in the construction of DFA from regular expression:
Convert RE to NFA using Thomson’s rules
Convert NFA to DFA
Construct minimized DFA
1. What is a lexical analyzer? | ![]() |
2. What is the purpose of lexical analysis in computer science and IT engineering? | ![]() |
3. How does a lexical analyzer work? | ![]() |
4. What is the role of regular expressions in specifying a lexical analyzer? | ![]() |
5. How important is a lexical analyzer in the overall compilation process? | ![]() |