【发布时间】:2015-07-02 12:35:44
【问题描述】:
我有两个词法分析器 - shell.l 和 javascript.l,分别带有前缀(%option 前缀)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 帖子,但没有找到太多帮助。 对于解决这些问题,我将不胜感激!
谢谢!
【问题讨论】:
-
你用的是什么版本的 flex?
标签: c gcc flex-lexer