首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >flex野牛视窗游戏攻略

flex野牛视窗游戏攻略
EN

Stack Overflow用户
提问于 2020-02-21 15:06:15
回答 1查看 200关注 0票数 0

由于我是lexer和parser的新手,所以我试图阅读和理解其他人的代码。

下面是我尝试使用的代码:https://gist.github.com/justjkk/436828

但它给了我错误。我该如何解决这个问题?

代码语言:javascript
复制
E:\flex_bison_test>gcc lex.yy.c y.tab.c -o json.exe
json.l: In function 'yylex':
json.l:34:11: warning: assignment to 'YYSTYPE' {aka 'int'} from 'char *' makes integer from pointer without a cast [-Wint-conversion]
     yylval=strclone(yytext);
           ^
json.l:38:11: warning: assignment to 'YYSTYPE' {aka 'int'} from 'char *' makes integer from pointer without a cast [-Wint-conversion]
     yylval=strclone(yytext);
           ^
json.l: In function 'strclone':
json.l:82:15: warning: implicit declaration of function 'strlen' [-Wimplicit-function-declaration]
     int len = strlen(str);
               ^~~~~~
json.l:82:15: warning: incompatible implicit declaration of built-in function 'strlen'
json.l:82:15: note: include '<string.h>' or provide a declaration of 'strlen'
json.l:79:1:
+#include <string.h>
 %%
json.l:82:15:
     int len = strlen(str);
               ^~~~~~
json.l:84:5: warning: implicit declaration of function 'strcpy' [-Wimplicit-function-declaration]
     strcpy(clone,str);
     ^~~~~~
json.l:84:5: warning: incompatible implicit declaration of built-in function 'strcpy'
json.l:84:5: note: include '<string.h>' or provide a declaration of 'strcpy'
y.tab.c: In function 'yyparse':
y.tab.c:627:16: warning: implicit declaration of function 'yylex' [-Wimplicit-function-declaration]
 # define YYLEX yylex ()
                ^~~~~
y.tab.c:1272:16: note: in expansion of macro 'YYLEX'
       yychar = YYLEX;
                ^~~~~
y.tab.c:1540:7: warning: implicit declaration of function 'yyerror'; did you mean 'yyerrok'? [-Wimplicit-function-declaration]
       yyerror (YY_("syntax error"));
       ^~~~~~~
       yyerrok
json.y: At top level:
json.y:80:6: warning: conflicting types for 'yyerror'
 void yyerror (char const *s) {
      ^~~~~~~
y.tab.c:1540:7: note: previous implicit declaration of 'yyerror' was here
       yyerror (YY_("syntax error"));
       ^~~~~~~

E:\flex_bison_test>

或者这些应该保持原样。

我已经给出了所有的命令:

代码语言:javascript
复制
flex json.l
bison -dy json.y
gcc lex.yy.c y.tab.c -o json.exe
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-02-21 15:23:42

简单地说:

代码语言:javascript
复制
#include <string.h>

在位于json.l之上的flex定义部分中,应该可以为您修复它。

在您指向的存储库中也有一个Makefile。也许你应该用这句话。您似乎没有正确生成解析器文件。请参阅下面的注释。

至于其余的警告:

代码语言:javascript
复制
warning: implicit declaration of function 'yyerror';
warning: implicit declaration of function 'yylex';

通过在json.y顶部的bison前言部分中添加yylex()yyerror声明,可以很容易地解决这些问题

代码语言:javascript
复制
%{
    int yylex();
    void yyerror(const char *s);
%}

至于这几个:

代码语言:javascript
复制
json.l:34:11: warning: assignment to 'YYSTYPE' {aka 'int'} from 'char *' makes integer from pointer without a cast [-Wint-conversion]
 yylval=strclone(yytext);
       ^
json.l:38:11: warning: assignment to 'YYSTYPE' {aka 'int'} from 'char *' makes integer from pointer without a cast [-Wint-conversion]
 yylval=strclone(yytext);
       ^

它们更微妙一点。我建议看看here,看看如何使用yylval将字符串从lex的标记正确传递到解析器的操作中。现在的问题是,yylval是一个纯int,但它最终被分配了用于NUMBERSTRING标记的char指针。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60333666

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档