我正在尝试生成一个编译器,以便可以将.c文件传递给它。
我从http://www.quut.com/c/ANSI-C-grammar-y.html下载了YACC和LEX语法,并将它们命名为clexyacc.l和clexyacc.y。
在终端上生成时我执行了以下命令:
yacc -d clexyacc.y
lex clexyacc.l
一切都进行得很顺利。当我进行最后一步时,出现了一些错误。
最后一步是:cc lex.yy.c y.tab.c -oclexyacc.exe
但我遇到了以下错误:
y.tab.c:2261:16: warning: implicit declaration of function 'yylex' is invalid in
C99 [-Wimplicit-function-declaration]
yychar = YYLEX;
^
y.tab.c:1617:16: note: expanded from macro 'YYLEX'
# define YYLEX yylex ()
^
y.tab.c:2379:7: warning: implicit declaration of function 'yyerror' is invalid
in C99 [-Wimplicit-function-declaration]
yyerror (YY_("syntax error"));
^
clexyacc.y:530:6: error: conflicting types for 'yyerror'
void yyerror(const char *s)
^
y.tab.c:2379:7: note: previous implicit declaration is here
yyerror (YY_("syntax error"));
^
2 warnings and 1 error generated.
yyerror
?请参见:https://dev59.com/ynDXa4cB1Zd3GeqP9Ce9 - Joe