Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/163.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ C+中的并集+;用于野牛的上下文_C++_Bison - Fatal编程技术网

C++ C+中的并集+;用于野牛的上下文

C++ C+中的并集+;用于野牛的上下文,c++,bison,C++,Bison,指的是 有一个定义如下的联合体: %union { Node *node; NBlock *block; NExpression *expr; NStatement *stmt; NIdentifier *ident; NVariableDeclaration *var_decl; std::vector<NVariableDeclaration*> *varvec; std::vector<NExpression

指的是

有一个定义如下的联合体:

%union {
    Node *node;
    NBlock *block;
    NExpression *expr;
    NStatement *stmt;
    NIdentifier *ident;
    NVariableDeclaration *var_decl;
    std::vector<NVariableDeclaration*> *varvec;
    std::vector<NExpression*> *exprvec;
    std::string *string;
    int token;
}
%union{
节点*节点;
NBlock*块;
下压*expr;
安装*stmt;
NIdentifier*ident;
无变量声明*var_decl;
std::vector*varvec;
std::vector*exprvec;
std::string*string;
int标记;
}

我的问题是:当这个union是匿名的时,如何使用它?它实际上是如何使用的?

不要把bison的
%union
指令与C/C++语法混淆起来

在bison生成的代码中,将有一个C/C++
union
,它的主体是从
%union
指令复制的,但它肯定不是匿名的:它的名称是
YYSTYPE
。但是,您几乎不需要知道这一点,因为该类型的唯一公开变量是
yylval
。(内部bison堆栈也由类型为
YYSTYPE
的元素组成,但不暴露于用户代码。)

如《野牛手册》所述,还有多种其他可能的方法来定义
YYSTYPE
。例如,您可以创建自己的C/C++
union
(或
struct
)类型,如下所述。但是,这些高级的bison
功能很少需要