野牛与yyerror的冲突类型

我正在尝试从flex和bison制作计算器,但我在编译期间发现了一个错误。

这是错误:

C:\GnuWin32\src>gcc lex.yy.c y.tab.c -o tugas tugas.y:51: error: conflicting types for 'yyerror' y.tab.c:1433: error: previous implicit declaration of 'yyerror' was here 

这是我的.l代码:

 %{ #include  #include "y.tab.h" YYSTYPE yylval; %} plus [+] semi [;] minus [-] var [az] digit [0-1]+ equal [:=] %% {var} {yylval = *yytext - 'a'; return VAR;} {digit} {yylval = atoi(yytext); return DIGIT;} {plus} {return PLUS;} {minus} {return MINUS;} {equal} {return EQUAL;} {semi} {return SEMI;} . { return *yytext; } %% int main(void) { yyparse(); return 0; } int yywrap(void) { return 0; } int yyerror(void) { printf("Error\n"); exit(1); } 

这是我的.y代码:

 %{ int sym[26]; %} %token DIGIT VAR %token MINUS PLUS EQUAL %token SEMI %% program: dlist SEMI slist ; dlist: /* nothing */ | decl SEMI dlist ; decl: 'VAR' VAR {printf("deklarasi variable accepted");} ; slist: stmt | slist SEMI stmt ; stmt: VAR EQUAL expr {sym[$1] = $3;} | 'PRINT' VAR {printf("%d",sym[$2]);} ; expr: term {$$ = $1;} | expr PLUS term { $$ = $1 + $3;} | expr MINUS term { $$ = $1 - $3; } ; term: int {$$ = $1;} | VAR {$$ = sym[$1]; } ; int: DIGIT {$$ = $1;} | int DIGIT ; 

为什么我收到此错误? 任何克服这个问题的建议。
提前致谢

yyerror应该有这个签名:

 int yyerror(char *); 

因为它应该接受在错误消息中使用的字符串(对于const char *可能会更好,但是你可能会得到额外的(可忽略的)警告……

你需要改变

 int yyerror(void) 

 int yyerror(char*) 

换句话说, yyerror()必须使用单个c字符串参数来描述发生的错误。