LEX
LEX
LEX
A LEX source program is a requirement of a lexical analyzer, consisting of a set of regular
expressions together with an action for each regular expression.
The action is a part of code which is to be executed when a token specified by the equivalent regular
expression is recognized.
LEX is a tool generally used to specify lexical analyzers for a variety of languages.
LEX tool require a Lex compiler, specification for the LEX tool is the Lex language.
Using a Scanner Generator: Lex
Lex is a lexical analyzer generator developed by Lesk and Schmidt of AT&T Bell Lab, written in C,
running under UNIX.
Lex produces an entire scanner module that can be compiled and linked with other compiler modules.
Lex associates regular expressions with arbitrary code fragments. When an expression is matched,
the code segment is executed.
A typical lex program contains three sections separated by %% delimiters.
Role of LEX:
Where each P1is 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 action 1is a program fragment describing what action the lexical analyzer should take when
token P’s found. The actions 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 actions must be compiled into machine code.
Auxiliary procedures:
The third section holds whatever auxiliary procedures are needed by the actions. Alternatively,
these procedures can be compiled separately and loaded with the lexical analyzer. The auxiliary procedures
are written in C language.
Input:
Enter Some string
Rohini College of Engineering and Technology
Output:
RECT