简体   繁体   中英

Bison/Yacc: yyparse not declared in this scope

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM