1 / 12

Steps to use Flex

Steps to use Flex. Ravi Chotrani New York University Reviewed By Prof. Mohamed Zahran. Outline. What is Flex Structure of a Flex File Steps to use Flex Example Summary. What is Flex. Flex (The Fast Lexical Analyzer)

chakra
Download Presentation

Steps to use Flex

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. Steps to use Flex Ravi Chotrani New York University Reviewed By Prof. Mohamed Zahran

  2. Outline • What is Flex • Structure of a Flex File • Steps to use Flex • Example • Summary

  3. What is Flex • Flex (The Fast Lexical Analyzer) • It is a tool for generating programs that perform pattern-matching on text. • Flex is a free implementation of the original Unix lex program.

  4. What is Flex(Contd.)

  5. Structure of a Flex File • Format: • The definitions section: "name definition"The rules section: "pattern action"The user code section: "yylex() routine" definitions %% rules %% user code Required Optional

  6. Steps to use Flex • Create a lex file which has lexical specification rules for the lexer generator. It also has a main method within the file itself which repeatedly invokes the lexerand prints out the token and lexeme pairs. • Compile this file by running the following command flex lexicalAnalyzer.l

  7. Steps to use Flex(Contd.) • A new file called lex.yy.c will be created in the same folder in which the above file was present. • Compile this file by running the command: gcclex.yy.c to generate a.out executable. • Test the executable using : ./a.out < "lexer_test.pas"

  8. Example

  9. Example(Contd.)

  10. Example(Contd.)

  11. Example(Contd.)

  12. Summary • Tool for generating programs that perform pattern-matching on text • Input file is a lex file(.l file) and output file is a c file. • Input file is divided into 3 sections: • Definitions • Rules • User Code

More Related