How to execute Lex (Flex) under Unix or Windows
Unix
The easiest is to access the Unix server of EECS and execute Lex there. It is already installed. (See also Steps for doing this Lab)
- Connect to linux.site.uottawa.ca throught the SSH protocol. (There is a software for that already installed in the labs, It is also freely available).
- NB: for clients offcampus, we should connect to ugate.site.uottawa.ca . I guess the same applies for laptops.
- From the command line of the linux server, we run flex and run gcc . Both of them are installed.
- To run the generated lexical analyser, assume that it is stored in parser1.exe, simply type "./parser1.exe" . This will not have an input though. In order to run it with an input file, you should type: "./parser1.exe < input_file.txt"
Windows
- Download Flex setup program for Windows: http://gnuwin32.sourceforge.net/packages/flex.htm
- Add string “C:\Program Files (x86)\GnuWin32\bin“ to the System‘s Environment “Path“ variable. (do not replace the existing path strings, rather add the new string and separate it with a semicolon).
- Download and install “Orwell Dev-C++” program: http://sourceforge.net/projects/orwelldevcpp/
- Write your lex code in Notepad and save it in “C:\temp” directory for example. At the top of your lex files make sure to add: %option noyywrap
- Open Command shell in “C:\temp” and compile the lex file as follows: Flex YourLexFileName.lex
- Open the generated lex.yy.c file in Dev-C and compile it to obtain the lex.yy.exe executable (after successful compilation, the executable will be produced in the same “C:\temp” directory.)
- Create a text file “t.txt” in “C:/temp” containing all the input strings for your lex program
- Open Command shell in “C:\temp” and run the executable as follows: lex.yy < t.txt
Page created: February 15, 2013 - Thanks to Mahfujur Rahman and Ahmed Jeddah