Bison/Yacc:在此范围内未声明yyparse [英] Bison/Yacc: yyparse not declared in this scope

查看:76
本文介绍了Bison/Yacc:在此范围内未声明yyparse的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题类似于这个问题,但是对于yyparse而不是yylex.

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

我已经为此战斗了几个小时!我想从C程序调用yyparse(实际上是C ++,但是我最终还是使用旧的flex/bison而不是较新的C ++低音扬声器(甚至没有意识到C ++版本存在)).唯一的错误是在此范围内未声明'yyparse'.我尝试将变量定义为全局变量,但似乎不起作用.

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.

在Flex文件中,我尝试过:

In the Flex file I tried:

extern "C" {
  int yyparse();
}

,并将其保存在Bison文件中:

and this in the Bison file:

extern int yyparse();

但是它什么也没做.

所以..我认为我的链接有误.问题是我使用的是Qt,它会自动生成make文件,因此,如果没有再次覆盖它,我将无法对其进行编辑.有什么方法可以解决问题而无需更改链接?如果没有,该如何链接?

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?

推荐答案

yyparse 声明应放在调用 yyparse 的C ++文件包含的标头中,而不是flex或bison文件,因为C ++文件是需要声明的文件.野牛将在其生成的源文件中创建所需的声明.

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.

这篇关于Bison/Yacc:在此范围内未声明yyparse的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆