小编Cha*_*ars的帖子

从lex和yacc语法生成编译器

我正在尝试生成一个编译器,所以我可以在之后传递一个.c文件.

我从http://www.quut.com/c/ANSI-C-grammar-y.html下载了YACC和LEX语法,并将它们命名为clexyacc.l和clexyacc.y

在终端上生成它时我做了:

yacc -d clexyacc.y
lex clexyacc.l
Run Code Online (Sandbox Code Playgroud)

一切都很好.当我继续到最后一部分时,我得到了一些错误.

最后一部分是: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 …
Run Code Online (Sandbox Code Playgroud)

c yacc lex

7
推荐指数
1
解决办法
1万
查看次数

标签 统计

c ×1

lex ×1

yacc ×1