C++ 正在尝试将类类型设置为Bison中的%parse param
我正在使用以下YaccC++ 正在尝试将类类型设置为Bison中的%parse param,c++,bison,C++,Bison,我正在使用以下Yacc %{ #include <stdio.h> extern int yylex(); static void yyerror(char **f, const char *s) { printf("%s\n", s); } #include "stv/stv.hpp" %parse-param {SingleTransferableVote::Election * e} ... %} yyparse函
%{
#include <stdio.h>
extern int yylex();
static void yyerror(char **f, const char *s) {
printf("%s\n", s);
}
#include "stv/stv.hpp"
%parse-param {SingleTransferableVote::Election * e}
...
%}
yyparse
函数的参数类型必须为类SingleTransferableVote::Election
。但是我得到一个错误,说没有声明SingleTransferableVote
,它指向yyparse
函数。这是“stv/stv.hpp”
#pragma一次
#包括
#包括
#包括
#包括
#包括
#包括
命名空间SingleTransferableVote{
班级候选人;
班级选举;
类调度项;
类VoteSet;
}
//有几个间接地包括“parser.h”和“lexer.h”
命名空间SingleTransferableVote{
//类型和函数声明
}
有人知道怎么回事吗?解析参数
%parse-param
需要在%{
之外。%}
。现在,它将被逐字复制到.tab.c文件中,并导致语法错误。
%option noyywrap
%{
#include "stv/stv.hpp"
#include "parser.h"
%}
#pragma once
#include <algorithm>
#include <cstdarg>
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
namespace SingleTransferableVote {
class Candidate;
class Election;
class ScheduleItem;
class VoteSet;
}
// A couple of includes, and indirectly, the "parser.h" and "lexer.h"
namespace SingleTransferableVote {
// Type and function declarations
}