我已将YYSTYPE联合声明为
%union
{
char* stringValue;
union int_double_string* ids;
}
int_double_string
被声明为
union int_double_string
{
short type; //0:int 1:double 2:string
int intValue;
double doubleValue;
char* stringValue;
};
一些代币
%token <stringValue> KEY
%token <int_double_string> VALUE
%token <stringValue> COMMENT
%type <stringValue> pair
%type <int_double_string> key_expr
但是无论我在哪里使用token VALUE
,它都会给我带来常见错误。
‘YYSTYPE’ has no member named ‘int_double_string’
pair:
KEY ws '=' ws VALUE {
char S5[15];
addPair($1, $5); //Error here and where-ever I use $5 in this function
...
为什么这样,尽管我已经正确声明了?我也在lex文件中使用了变量。它在那里显示没有错误。
lex文件
{integer} {
yylval.ids = malloc(sizeof(union int_double_string));
yylval.ids->type = 0;
yylval.ids->intValue = atoi(yytext);
return VALUE;
}
我认为这与工会内部工会的概念有关。
该怎么办?
‘YYSTYPE’ has no member named ‘int_double_string’
在ID%type <id>
和%token <id>
需求是在一个领域yyunion
。
因此,定义为int_double_string类型的令牌必须为ID类型
%token <int_double_string> VALUE
%type <int_double_string> key_expr
像这样
%token <ids> VALUE
%type <ids> key_expr
第二个参数addPair
应该是union int_double_string*
在典型的yacc用法中,您应该输入以下所有字段:
short type; //0:int 1:double 2:string
int intValue;
double doubleValue;
char *stringVal;
进入yyunion本身,并且在yyunion中没有联合字段。我并不是说不能,但这很不寻常。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句