1 / 6

Lex Compiler

Lex Source Program. Lex Compiler. lex.yy.cc. lex.yy.cc. C Compiler. executable file. Input Stream. Exectuable File. Sequence of Tokens. Lex Source Program. Table of regular expressions and corresponding program fragments. Format:. { definitions} %% {rules} %% {user subroutines}.

zach
Download Presentation

Lex Compiler

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Lex Source Program Lex Compiler lex.yy.cc lex.yy.cc C Compiler 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 forpreprocessor statements that must begin in column 1, e.g. • %{ • #include <stdio.h> • %} • C code, in the form “blankspace code” e.g. • int students=0; • 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.lex2.3. you will find a new file generated by flex, named lex.yy.c2.4. compile by gcc lex.yy.c -lfl -o test.exe2.5. you should get your executable, test.exe2.6. create a text file (e.g. t.txt) containing your inputs2.7. execute test < t.txt2.8. you should be able to get what you expected

More Related