“首次登场'”的错误$1;没有声明类型Bison/Yacc
我对Yacc/野牛有问题。 这是我的代码:“首次登场'”的错误$1;没有声明类型Bison/Yacc,bison,yacc,Bison,Yacc,我对Yacc/野牛有问题。 这是我的代码: %{ #include <stdio.h> %} %union{ double val; } %start debut %token <val> nombre %left PLUS %% debut : | ADDITION {printf('%f \n',$1);} ; ADDITION : nombre PLUS nombre {$$=$1+$3;} ; %% void yyerror(char *s){
%{
#include <stdio.h>
%}
%union{
double val;
}
%start debut
%token <val> nombre
%left PLUS
%%
debut :
| ADDITION {printf('%f \n',$1);}
;
ADDITION : nombre PLUS nombre {$$=$1+$3;}
;
%%
void yyerror(char *s){
printf("%s \n",s);
}
int main(void){
return yyparse();
}
%{
#包括
%}
%联合{
双val;
}
%首发
%标记名
%左加
%%
首次亮相:
|加法{printf('%f\n',$1);}
;
加法:nombre加nombre{$$=$1+$3;}
;
%%
无效错误(字符*s){
printf(“%s\n”,s);
}
内部主(空){
返回yyparse();
}
我得到这个错误类型:
$1的“首次登场”没有声明类型
$1的首次登场
是首次登场
制作的第一个符号,即添加符号。由于添加符号没有声明的类型,yacc无法将$1
占位符扩展为任何有意义的内容
要解决此问题,请将%type ADDITION
添加到定义列表中(第一个%%
之前的部分)