简单的 yacc 语法报错 [英] Simple yacc grammars give an error

查看:66
本文介绍了简单的 yacc 语法报错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个关于 yacc 编译器的问题.我不编译简单的 yacc 语法.这是代码部分:

I have a question for yacc compiler. I do not compile simple yacc grammar. Here is the code section :

/*anbn_0.y */
%token A B
%%
start: anbn '\n' {printf(" is in anbn_0\n");
return 0;}
anbn: empty
| A anbn B
;
empty: ;
%%
#include "lex.yy.c"
yyerror(s)
char *s;
{ printf("%s, it is not in anbn_0\n", s);

我使用 mac os x,我尝试使用 yo 命令;$ yacc anbn_0.y 然后$ gcc -o anbn_0 y.tab.c -ll 并给我错误.这是错误;

I use mac os x and, i try yo command; $ yacc anbn_0.y and then $ gcc -o anbn_0 y.tab.c -ll and give me error. Here is the error ;

warning: implicit declaration of function 'yylex' is invalid in C99 [-Wimplicit-function-declaration]
      yychar = YYLEX;

为什么会出现错误?

推荐答案

这是一个警告,而不是一个错误,所以如果你忽略它应该没问题.但如果你真的想摆脱警告,你可以添加

Its a warning, not an error, so you should be fine if you ignore it. But if you really want to get rid of the warning, you could add

%{
int yylex();
%}

.y 文件的顶部

这篇关于简单的 yacc 语法报错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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