They are located in custom_build_rules sub-folder of the win_flex_bison archive. Or you can grab them here
Launch Visual Studio and open an VC++ project. Open context menu for project item in Solution Explorer panel and select "Build Customizations..." menu item.
In popup dialog "Visual C++ Build Customization Files" press "Find Existing..." button.
In Open File dialog select "win_flex_bison_custom_build.targets" file and press "Open".
You will see "Add Search Path?" message box, press "Yes"
In "Visual C++ Build Customization Files" dialog check just added item win_flex_bison_custom_build and press "OK"
Now you can add flex and bison files to the project and build.
In build output you should see something like this:
1>------ Rebuild All started: Project: ConsoleApplication1, Configuration: Debug Win32 ------
1> Process sample bison file
1> Process sample flex file
1> stdafx.cpp
1> ConsoleApplication1.cpp
1> Generating Code...
1> ConsoleApplication1.vcxproj -> C:\Users\ConsoleApplication1\Debug\ConsoleApplication1.exe
========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========
For sample.y bison file there are two output files: sample.tab.h and sample.tab.cpp. For sample.l flex file you'll got sample.flex.cpp. Now you can add them to the project and build. (Don't forget to exclude cpp files from using precompiled headers)
1>------ Build started: Project: ConsoleApplication1, Configuration: Debug Win32 ------
1> Process sample bison file
1> Process sample flex file
1> sample.tab.cpp
1> sample.flex.cpp
1> Generating Code...
1> ConsoleApplication1.vcxproj -> C:\Users\ConsoleApplication1\Debug\ConsoleApplication1.exe
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
If your flex/bison file is incorrect and you've got an error. But you don't see actual error message, something like this:
1>------ Build started: Project: ConsoleApplication2, Configuration: Debug Win32 ------
1> Process "grammar.y" bison file
1>C:...\custom_build_rules\win_flex_bison_custom_build.targets(55,5): error MSB3721: The command "
1>C:...\custom_build_rules\win_flex_bison_custom_build.targets(55,5): error MSB3721: start /B /WAIT /D "C:...\ConsoleApplication2\ConsoleApplication2\" win_bison.exe --output="grammar.tab.cpp" --defines="grammar.tab.h" --graph="1.dot" "grammar.y"
1>C:...\custom_build_rules\win_flex_bison_custom_build.targets(55,5): error MSB3721: exit /b %errorlevel%" exited with code 1.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
You can change Build Output Verbosity from "Minimal" to "Normal" in "Options" dialog
Then you will see more detailed output:
1>BisonTarget:
1> Process "grammar.y" bison file
1> grammar.y:51.1-4: error: invalid directive: '%sdw'
1>C:...\custom_build_rules\win_flex_bison_custom_build.targets(55,5): error MSB3721: The command "
1>C:...\custom_build_rules\win_flex_bison_custom_build.targets(55,5): error MSB3721: start /B /WAIT /D "C:...\ConsoleApplication2\" win_bison.exe --output="grammar.tab.cpp" --defines="grammar.tab.h" --graph="1.dot" "grammar.y"
1>C:...\custom_build_rules\win_flex_bison_custom_build.targets(55,5): error MSB3721: exit /b %errorlevel%" exited with code 1.
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:01.21
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Also you can tune some flex/bison options in files properties dialog:
To debug your scanner or parser you can set break points right into sample.y or sample.l code
Last edit: Tarek701 2015-05-16
How can I change the custom build rules to build "C" parser?
Thanks
It should generate "C" parser code now.
Do you mean generated files should be processed by "C" compiler (not "C++")?
In this case you should change extension of output files from .cpp to .c, so VS will recognize these files as pure "C" source code and will use "C" compiler.
I generated lexer in a plain c file and let the bison generate a c++ code. I had to extern "C" the definitions of lexer functions i.e. yylex(), yylineno etc.
But still flex generated code gives linking error for yylval. I checked the generated file by parser, which is c++ file, and it has defined yylval.
There is a linking error. The lex generated file can't find the definition of yylval. Both the lex and bison generated files are in the same project (MS Visual Studio 2010).
Any ideas, what is wrong here.
I have not been working with VS 2010 for a long time.
I can only guess if YYSTYPE is different for lexer and for parser.
Please show all errors as they appear in VS Studio output window.
It is just this one.
Anyway, I have moved on to using .cpp files. They work fine.