Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

yacc and bison in visual studio

I am going to port the C project that was for unix into windows. So far, I could make it compile but not build . The problem I am getting is , some of the functions which are declared in the header files are defined in the yacc files.so I am getting the following errors:

 error LNK2001: unresolved external symbol function_name

I am adding .y and .l files in the source directory of the project.I think I could not port yacc files into windows version or am I doing something stupid.I search it on web but could not get proper tutorial for it.Could you please let me know

  1. How could I add .y or .l files in the project.
  2. How would I make those file compatible to the windows?
  3. How can I link them with other object files.

EDIT

I tried with changing the the .l files into the .yy.c files using the flex.exe.Following is the command for it

     c:\> flex.exe name.l

Supposing that both the flex.exe and name.l are in C;>.And I loaded those all those files .l .y(previously present for parsing in unix system) .yy.c(corrsonding yacc file for windows) in the solution of previously exisiting project. Once I compile,I get the following

 Can't read the header file  parserheaderfile.h 

This is the header file which needs to be generated by the bison in the unix system. So I think I am not able to make the bison compatible for windows .So please him me how can I solve this problem?

Thanks in advance.

like image 316
thetna Avatar asked Jul 03 '11 14:07

thetna


People also ask

What is the difference between Yacc and bison?

Bison is the GNU implementation/extension of Yacc, Flex is the successor of Lex. In either case, it's fine (and recommended) to use bison / flex. Additionally, byacc, the Berkeley implementation of yacc, is widely available (I see it in my Debian repository list). flex is called that because it is (was?)

What do you mean by Flex lex Yacc and bison?

Lex and Yacc were the first popular and efficient lexers and parsers generators, flex and Bison were the first widespread open-source versions compatible with the original software. Each of these software has more than 30 years of history, which is an achievement in itself.

What is Flex and Bison used for?

Flex and Bison are tools for building programs that handle structured input. They were originally tools for building compilers, but they have proven to be useful in many other areas.


1 Answers

You need to add custom build rules for your .y and .l files. To do this, you need to

  1. create one dummy .c file for the .l file and the .y file
  2. add the .l, .y and both .c files to the project
  3. right click on the .l file and select properties
  4. Configuration->All Configurations
  5. General->Item Type->Custom Build Tool
  6. Apply
  7. Custom Build Tool->General->Command Line->flex -olexer.c lexer.l
  8. Custom Build Tool->General->Outputs->lexer.c
  9. Custom Build Tool->General->Additional Dependencies->parser.y parser.c
  10. Apply
  11. select the .y file in the solution explorer
  12. Configuration->All Configurations
  13. General->Item Type->Custom Build Tool
  14. Apply
  15. Custom Build Tool->General->Command Line->bison -oparser.c parser.y
  16. Custom Build Tool->General->Outputs->parser.c parser.h

Also you need to have flex.exe, bison.exe and m4.exe in the system search path. Another drawback is that VS does not get the dependencies right, so when you change something in the parser or lexer files, you need to manually rebuild the project.

like image 58
Rudi Avatar answered Oct 19 '22 14:10

Rudi