Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Steps to use Flex Ravi Chotrani New York University Reviewed By Prof. Mohamed Zahran.

Similar presentations


Presentation on theme: "1 Steps to use Flex Ravi Chotrani New York University Reviewed By Prof. Mohamed Zahran."— Presentation transcript:

1 1 Steps to use Flex Ravi Chotrani New York University Reviewed By Prof. Mohamed Zahran

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

3 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 4 What is Flex(Contd.)

5 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 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 lexer and prints out the token and lexeme pairs. Compile this file by running the following command flex lexicalAnalyzer.l

7 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: gcc lex.yy.c to generate a.out executable. Test the executable using :./a.out < "lexer_test.pas"

8 8 Example

9 9 Example(Contd.)

10 10 Example(Contd.)

11 11 Example(Contd.)

12 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


Download ppt "1 Steps to use Flex Ravi Chotrani New York University Reviewed By Prof. Mohamed Zahran."

Similar presentations


Ads by Google