【发布时间】:2009-06-18 19:08:10
【问题描述】:
在这个文件上运行 Bison:
%{
#include <iostream>
int yylex();
void yyerror(const char*);
%}
%union
{
char name[100];
int val;
}
%token NUM ID
%right '='
%left '+' '-'
%left '*'
%%
exp : NUM {$$.val = $1.val;}
| ID {$$.val = vars[$1.name];}
| exp '+' exp {$$.val = $1.val + $3.val;}
| ID '=' exp {$$.val = vars[$1.name] = $3.val;}
;
%%
导致以下警告:
警告:'exp' 的 $$ 没有声明类型。
这是什么意思,我该如何解决?
【问题讨论】:
-
+1:在谷歌搜索时首先出现
bison error has no declared type -
只是一个小细节。我有
%union { int intValue; int floatValue; },但它不允许我使用$$.intValue或$1.intValue。它说error: request for member ‘floatValue’ in something not a structure or union。为什么会这样?
标签: bison