The Custom Build Rules that Jarda specifies are the easiest. The following is an alternative to the Custom Build Rules.
Don't use precompiled headers unless you know how to use them well enough to use them for this. I had a problem with it complaining about macro redefinitions and premature end-of-file, until I turned off use of precompiled headers.
Generate a "Win32 Console Application" and make it an empty project (no generated source code). For example, I am using "SimpleFlex" for my project name.
Optional: You can customize the filters for VS folders so that the Flex input file is shown in the Source Files folder. In the properties of the Source Files folder, add the extension ("l" or "lex") to the list of extensions.
Then create a file with a "l" (or "lex") extension for the project; for example, "SimpleFlex.l". In the file, use one of the samples from below. Then in the project settings, create a Custom Build Step. If you are not familiar with Custom Builds, then look for the "Custom Build Step" tab in the project settings. Use the following for the Custom Build Step:
Description: Generating lexical analyzer
Commands: C:\Software\FLEX252\flex.exe -o$(ProjDir)\$(InputName).cpp
$(InputPath)
Outputs: $(ProjDir)\$(InputName).cpp
Where:
Description is actually anything you want to use
Commands Consists of the path to Flex, the output file and the input file. You will need to change the path for Flex to whatever is correct for your system.
Outputs Specifies the filename of the output file.
After providing the code for the Flex input file creating the Custom Build Step, compile the file. You can use Ctrl-F7 to just compile. Actually, at this point, you can just build the project; there is nothing for the build to do except generate the scanner (the cpp file). The custom build should execute Flex, but the only way you will know it does is because the description is shown in the Build output. The cpp file should have been generated and then it can be added to the project. If you get the errors I describe above (macro redefinitions and premature end-of-file) then turn off precompiled headers for the project.
The procedure for Bison is very similar.