0

This question is similar to this one but for yyparse, not yylex.

I've been battling with this for hours now! I'm wanting to call yyparse from a C program (actually a C++ one but I ended up using the old flex/bison rather than the newer ones for C++ woops (didn't realise the C++ versions even existed)). The only error is that 'yyparse' was not declared in this scope. I've tried defining the variable as global but it doesn't seem to work.

In the Flex file I tried:

extern "C" {
  int yyparse();
}

and this in the Bison file:

extern int yyparse();

but it didn't do anything.

So.. I think I'm linking wrong. The problem is that I am using Qt which builds the make file automatically so I can't edit it without it just being overritten again. Is there any way of fixing the problem without changing the linking? If not, how is the linking meant to be done?

Community
  • 1
  • 1
ale
  • 11,636
  • 27
  • 92
  • 149
  • You should show the file names and the error messages which generate them. It is not clear from your question whether the problem is that you're compiling the Bison output with the C++ compiler and it is complaining that there is no prior definition of `yyparse()`, or whether the problem is in the code that is calling `yyparse()`. Where did you put the `extern int yyparse();` declaration in the Bison file? Was it in a `%{ ... %}` section at the top of the file, or somewhere else? – Jonathan Leffler Jul 11 '11 at 02:48

1 Answers1

2

The yyparse declaration should go in a header included by the C++ file that calls yyparse, rather than the flex or bison files, since the C++ file is the one that needs the declaration. bison will create the declarations it needs within the source file it generates.

outis
  • 75,655
  • 22
  • 151
  • 221