Setting Up and Using Flex (Lex for Windows) with Visual C++ 6.0
Contributed by Stephen Seymour
I have written this HTML page for those who are interested in using the "lex" and "yacc" unix commands on Microsoft Windows machines. It is assumed that the reader has some knowledge (but not much) of the Visual C++ 6.0 integrated development environment.
The first thing you need to do is to download the necessary software. Although there are many clones available all over the web, the following link will download the files for you to build programs using Visual Studio 6.0: Click Here for Download the Flex and Bison Tools.
After you have downloaded the zip file from clicking the above link, extract all the files to a directory of your choice and then run the "setup.exe" file. This will install "Flex.exe" and "Bison.exe" on a Windows machine. The installation process will find the appropriate directories on your computer that house Visual Studio 6.0 and will install the necessary files into those directories.
Running the Lex Program:
For the sake of helpfulness, I will give an example assuming the "Flex.exe" program was installed in the "C:\Program Files\Microsoft Visual Studio\Common\Bin" directory. However, if you have a path to this directory predefined in your environmental variables, you won't need to type in the entire path to the "Flex.exe" program. Regardless of where the "Flex.exe" program is, if it is not defined as an environment variable then all you have to do is fill in the entire path to it in the appropriate places in the following example:
The above steps should have created a "lex.yy.c" file or a "lex.yy.cpp" file, which we will now use to compile into an executable using Visual Studio 6.0
Open up Visual Studio 6.0
Create an empty project, and place the "lex.yy.c" or "lex.yy.cpp" file we created above into the top-level project directory.
Add the "lex.yy.c" or "lex.yy.cpp" file to the project by clicking on "Project | Add to Project... | Add Files..." menu item, and then selecting the file.
Click on the "Project | Settings..." menu item, and then click on the "Link" tab in the dialog box that appears.
In the "Object/library modules:" text box, move the cursor to the end of the line, past all the other "lib" files, and add in the full path to the "LIBFLEX.lib" file that is found in the "lib" directory of the Flex and Bison installation you performed above. Surround the path with quotation marks to ensure that whitespaces in the path are taken into account.
Build the project. You might receive a LNK4098 warning if you are compiling for C, but disregard it. I haven't had the time to get rid of this warning, but it causes no harm.
HomeworkOne < C:\HomeworkOneParseFile.txt
I hope this helps!