0% found this document useful (0 votes)
8 views12 pages

Unit 1 Part 3

Unit 1 Part 3 for cse 3rd year
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views12 pages

Unit 1 Part 3

Unit 1 Part 3 for cse 3rd year
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

LEX TOOL

allows one to specify a lexical analyzer by specifying regular


expressions to describe patterns for tokens
Working
● The input notation for the Lex tool is referred to as the Lex language and the
tool itself is the Lex compiler.
● the Lex compiler transforms the input patterns into a transition diagram and
generates code, in a file called lex.yy.c, that simulates this transition diagram.
1. An input file, which we call lex.l, is written in the Lex language and describes
the lexical analyzer to be generated.
2. The Lex compiler transforms lex.l to a C program, in a file that is always
named lex.yy.c.
3. The latter file is compiled by the C compiler into a file called a.out, as always.
4. The C-compiler output is a working lexical analyzer that can take a stream of
input characters and produce a stream of tokens.
Structure of Lex Program
Example
Lookahead Operator

Lex automatically reads one character ahead of the last character that forms the
selected lexeme, but consumes only the part that matches.

Match based on subsequent characters too using /:

● Slash in a pattern indicates the end of the part of the pattern that matches the
lexeme.
● What follows / is additional pattern that must be matched before we can
decide that the token in question was seen, but what matches this second
pattern is not part of the lexeme.
THANK YOU

You might also like