Title: Lex Compiler
1Lex Source Program
Lex Compiler
lex.yy.cc
C Compiler
lex.yy.cc
executable file
Input Stream
Exectuable File
Sequence of Tokens
2Lex Source Program
Table of regular expressions and corresponding
program fragments
Format
definitions rules user subroutines
3Definitions section contains a combination of
- C code, in the form
-
- code
-
- used for preprocessor statements that must
begin in column 1, e.g. -
- include ltstdio.hgt
-
- C code, in the form blankspace code e.g.
- int students0
- Definitions, in the form name blankspace
substitute - e.g.
- DIGIT 0-9
4RULES
This section is Lex Action section. When an
expression is matched, Lex executes the
corresponding action. The form of this section
is pattern action
Where pattern Lex Regular Expressions action
Corresponding C code
5Lex Regular Expressions
- Refer to
- the documentation written by by M. E. Lesk and E.
Schmidt - http//www.site.uottawa.ca/jyzhao/courses/seg2101
/lab5/lex-docs.txt - Part 3 (Lex Regular Expressions) and Part 12
(Source Format) - The Unix manual page of FLEX
- http//www.site.uottawa.ca/jyzhao/courses/seg2101
/lab5/lex_manpage.pdf - Page 6 (Patterns)
62. You need follow the following steps 2.1.
create a lex source file (e.g. test.lex)
containing the patterns and actions, by following
the required format. Refer to lex_manpage.pdf.
2.2. compile test.lex by using flex test.lex
2.3. you will find a new file generated by flex,
named lex.yy.c 2.4. compile by gcc lex.yy.c
-lfl -o test.exe 2.5. you should get your
executable, test.exe 2.6. create a text file
(e.g. t.txt) containing your inputs 2.7.
execute test lt t.txt 2.8. you should be able
to get what you expected