Flex Bison Reentrant C++Parser:yyscanner未声明的标识符



我正试图使用带有flex和bison的C++创建一个可重入解析器。我还使用了一个驱动程序类Driver。我在lex方面得到了错误'yyscanner' : undeclared identifier。我认为这与flex中的可重入选项有关,这很奇怪,因为我假设driver会在它的位置上使用,因为我在driver.h中将yylex声明为yylex(Driver& driver)。为了得到这个错误消息,我在下面的代码中有没有做错什么?任何帮助都将不胜感激。

parser.y

%require "3.2"
%define parse.error verbose
%locations
%param { Driver& driver }
%language "c++"
%define api.value.type variant

%code requires {
class Driver;
}
%code {
#include "driver.h"
}
...

lexer.l


%option noyywrap noinput nounput
%option nodefault
%option nounistd
%option reentrant
%{
#include <iostream>
#include <string>
#include "driver.h"
#include "parser.tab.h"
%}

%%
%{
yy::location& loc = driver.location;
%}
...

driver.h

#ifndef DRIVER_HH
#include "parser.tab.h"
#define YY_DECL 
int yylex(Driver& driver)
YY_DECL;
class Driver
{
public:
Driver()  {}
yy::location location;
};
#endif // ! DRIVER_HH

如果生成可重入扫描程序,则必须将其原型定义为包含yyscan_t类型的名为yyscanner的参数。你需要用这个参数调用扫描仪。您不能替换为yyscan_t参数定义的某些类型,因为您的类型不包括flex生成的扫描程序使用的数据成员。您必须使用名称yyscanner,因为Flex生成的代码就是这样引用数据成员的。

如果你想要一个只需要一个参数的CCD_;官方的";这样做的方法是将您的数据成员(或指向它们的指针(放入";额外数据";在CCD_ 12中。但只使用两个参数可能会更容易。

最新更新