FLEX Installation and Setup Guide
What is FLEX ?
FLEX (Fast LEXical analyzer generator) is a tool for generating scanners. Instead of
writing a scanner from scratch, you only need to identify the vocabulary of a certain
language (e.g. Simple), write a specification of patterns using regular expressions
(e.g. DIGIT [0-9]), and FLEX will construct a scanner for you.
How to use FLEX ?
FLEX is generally used in the manner depicted here:
Software Required
1. FLEX Compiler
2. Editor for writing codes ( Dev C++ has been used in this tutorial)
3. C/C++ Compiler
Hardware Requirements
1. Operating System: Windows 7/8/9/10, Ubuntu.
2. RAM: At least 4GB Preferred
3. 64-bit operating system, x64-based processor (Works perfectly with 32-bit
system as well).
FLEX Installation Manual
1. Download FLEX Setup (Visit: [Link]
Click here
Downloaded File
2. Follow the below steps for installing downloaded flex setup file.
1 2
3 4
5 6
7 8
Installed
Successfully
3. Download Dev C++ ([Link]
Downloaded File
4. Follow the below steps for installing downloaded Dev-C++ setup file.
1 2
3 4
Installed
Successfully
5
5. Setting Environment Variable for FLEX and Dev-C++.
1) Open Settings ------------→ Advanced System Settings
2) Click on environment variables.
3) Click “New”.
4) Give variable name and in Variable Value give path of bin folder as shown in Image below and then
Save everything.
Testing FLEX
1. Open Command Prompt, Type FLEX and press Enter. If your installation was done successfully
command prompt will switch into FLEX Mode.
2. Open Your Editor and Paste below Code and save the file with .l extension.
Example for checking whether token is digit or letter.
%{
#define A 100
%}
WS [\t]+
letter [A-Za-z]
digit [0-9]
op_plus "+"
%%
^[0-9]+ {printf("digit");};
^[A-Za-z]+ {printf("letter");};
%%
main(){
yylex();
}
yywrap(void)
{
return 0;
}
3. Open command prompt and switch to directory where your .l file is saved and run following
command.
4. After successful execution of command C file will be created.
5. Execute the generated C File.
6. Provide Input and check the output.