我有两个lexers shell.l和javascript.l,分别带有前缀(%option prefix) shell和javascript ( shell.l中的%option prefix="shell“和javascript.l中的%option prefix="javascript”)。
我从另一个文件( main_file.c)中依次调用词法分析器,如下所示:
somefunc(){
.....
shelllex();
......
javascriptlex();
}为了调用它们,我在main_file.c中包含了这两个词法分析器的头文件:
#include <.....>
#include "lex.shell.h"
#include "lex.javascript.h" 并且,我在编译flex文件时创建了这些头文件,如下所示:
flex --header-file=lex.shell.h shell.l
flex --header-file=lex.javascript.h javascript.l
gcc -o lang lex.shell.c lex.javascript.c main_file.c -lfl当我编译main_file.c时,我得到如下重新定义的错误:
在code_detector.c:16:0包含的文件中:
lex.javascript.h:227:29: error: redefinition of ‘yy_nxt’
static yyconst flex_int16_t yy_nxt[][128] =
^
In file included from code_detector.c:15:0:
lex.shell.h:227:29: note: previous definition of ‘yy_nxt’ was here
static yyconst flex_int16_t yy_nxt[][128] =我已经浏览了其他几篇SO帖子,但没有找到太多帮助。如果能帮助我解决这些问题,我将非常感激!
谢谢!
发布于 2015-04-25 01:45:54
显然,存在一个错误,如果存在%option full,它会导致扫描仪转换表yy_nxt错误地写入头文件。这应该在最新版本的flex (2.5.39)中得到修复。
如果你不想升级你的flex版本,一个简单的变通办法是避免使用%option full。您可能会发现速度损失是不可测量的。
https://stackoverflow.com/questions/29838458
复制相似问题