【发布时间】:2013-11-10 15:54:06
【问题描述】:
我已将 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
但无论我在哪里使用令牌 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;
}
我认为这与联合内部的联合概念有关。
怎么办?
【问题讨论】: