How can I use flex & bison in Visual Studio 2010?

sky picture sky · May 3, 2011 · Viewed 9.6k times · Source

I've read http://msdn.microsoft.com/en-us/library/aa730877%28vs.80%29.aspx but this document was for VS 2005. I stuck on the part 'Importing a .rules File in Visual C++' in the document. It seems that VS 2010 does not support .rules file, instead, it seems to use .targets file for custom build rules.

Does anyone know how to use flex & bison in VS 2010? Thanks.

Answer

Bob_Gneu picture Bob_Gneu · May 18, 2011

The good news is, that targets file works after a conversion to 2010.

  • Install the example. Open it with the vs2010 converter and it will do the conversion from the 2005 *.rules to 2010 *.targets, *.props and *.xml file
  • install cygwin, and include flex, its sourcecode, Bison and its source code
  • Add the cygwin path to the end of your Executable paths list and the path to the source to the end of your include paths list

Although the example wont run because of dependencies you are now able to create your own project and build your own lexer and parser. The only issue you will have is the use of unistd.h being included. Add this and it wont:

#define YY_NO_UNISTD_H 

I think you can get the rest of the things you need to build your parser in 2010 in the flex & bison book.