野牛冲突的类型的yyerror [英] Bison conflicting type for yyerror

查看:411
本文介绍了野牛冲突的类型的yyerror的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让从flex和野牛一个计算器,但我在编译过程中发现了一个错误。

I'm trying to make a calculator from flex and bison, but I found an error during the compile.

以下是错误:

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 code:

Here is my .l code :

%{
#include <stdio.h>
#include "y.tab.h"
YYSTYPE yylval;
%}
plus    [+]
semi    [;]
minus   [-]
var [a-z]
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 code:

And here is my .y code :

%{
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
;

为什么我得到这个错误?任何建议,以解决这个问题。结果在此先感谢

Why I am getting this error? any suggestion to overcome this issue.
Thanks in advance

推荐答案

的yyerror 应该有这样的签名:

int yyerror(char *);

由于希望接受字符串中的错误信息被使用(很可能会以为const char * 更好,但你可能会得到额外的(忽略)与警告...

Since it is expected to accept a string to be used in the error message (would probably be better with a const char *, but you might get additional (ignorable) warnings with that...

这篇关于野牛冲突的类型的yyerror的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆