Download presentation
Presentation is loading. Please wait.
Published byApril Blankenship Modified over 9 years ago
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
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.