Lex Compiler - PowerPoint PPT Presentation

1 / 6
About This Presentation
Title:

Lex Compiler

Description:

Table of regular expressions and corresponding ... Part 3 (Lex Regular Expressions) and Part 12 (Source Format) The Unix ... compile test.lex by using ... – PowerPoint PPT presentation

Number of Views:219
Avg rating:3.0/5.0
Slides: 7
Provided by: hong168
Category:

less

Transcript and Presenter's Notes

Title: Lex Compiler


1
Lex Source Program
Lex Compiler
lex.yy.cc
C Compiler
lex.yy.cc
executable file
Input Stream
Exectuable File
Sequence of Tokens
2
Lex Source Program
Table of regular expressions and corresponding
program fragments
Format
definitions rules user subroutines
3
Definitions 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

4
RULES
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
5
Lex 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)

6
2. 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
Write a Comment
User Comments (0)
About PowerShow.com