Bison试图在解析器上使用免费的yylex()函数C++
Bison trying to use free yylex() function on C++ parser
我正在使用 Flex+Bison 生成一个C++扫描器/解析器,但遇到了生成的代码和包含的标头中缺少 flex 函数的问题。
使用 g++ 进行编译失败,并显示以下内容:
parser.cxx: In member function 'virtual int yy::parser::parse()':
parser.cxx:465:38: error: 'yylex' was not declared in this scope
symbol_type yylookahead (yylex (yylval, yylloc));
这是一个错误,因为它不应该使用全局自由函数yylex(...)
而是使用我的扫描仪的yy::scanner::yylex(...)
函数,实现如下:
#include <FlexLexer.h>
#include "parser.hxx"
#undef YY_DECL
#define YY_DECL yy::parser::symbol_type yy::scanner::yylex(yy::parser::semantic_type* yylval, yy::parser::location_type* yylloc)
namespace yy {
class scanner final: public yyFlexLexer
{
public:
scanner(std::istream *in, std::ostream* out): yyFlexLexer(in, out) {}
parser::symbol_type yylex(yy::parser::semantic_type* yylval, yy::parser::location_type* yylloc);
};
这些参数在 .y 文件中配置为:
%param {parser::semantic_type* yylval} {parser::location_type* yylloc}
flex (.l) 和 bison (.y) 文件都使用标志进行编译,以生成C++代码,并使用 g++ 编译为:
g++ -lfl parser.cxx scanner.cxx -o lang
生成的文件parser.cxx
和scanner.cxx
。我错过了什么,如何修复解析器应该调用而不是yylex()
函数?
答案如下
#undef yylex
#define yylex scanner.yylex // bison's parse() invokes scanner.yylex(),
相关文章:
- 为什么野牛仍在使用"int yylex(void)",却找不到"int yylex(YYS
- 如何在cpp中删除(免费)多维结构内存?
- 存储在堆分配向量中的指针的免费存储
- 如何在C++非托管/本机 DLL 中从注册免费 COM C# 托管 DLL 创建 COM 对象
- 应用地址清理器后,免费无效指针消失
- 使用未声明的标识符"yylex"和"yyin"?
- 为什么用绕道钩住堆免费对删除/免费不起作用?
- std::atomic中的任何内容都是免费等待的
- 免费图像写入像素
- 优点和缺点 在类内为大型项目定义的内联朋友助手免费函数
- 全球免费给出一个错误.调试器不解释
- 我应该只在免费商店上为一次调用创建对象吗?
- 由PostMessage发送的来自c++的C ++的免费HBITMAP
- 从命令行构建一个.sln / .vcxproj项目,并使用Visual C 的免费版本构建
- G++ flex 和 bison 'yylex' 未在此范围内声明
- C++自动内存 malloc 和免费覆盖问题
- 野牛没有使用正确的yylex参数
- 使用线程和静音时,双免费或损坏(!prev)错误
- 使用lambda在功能指针铸造时双免费
- Bison试图在解析器上使用免费的yylex()函数C++