在OS X上使用Flex(词法分析器) [英] Using Flex (the lexical analizer) on OS X
问题描述
我有一个文件test.lex,我将其运行为
I've got a file, test.lex, which I run through as
$ flex test.lex
这给了我lex.yy.c,我尝试用它编译:
That gives me lex.yy.c, which I try to compile with:
$ gcc lex.yy.c -lfl
这给我错误ld:-lfl找不到库.我知道Flex规范是正确的,并且lex.yy.c在Linux机器上可以正常编译.有什么建议吗?
This gives me the error ld: library not found for -lfl. I know the Flex specification is correct and lex.yy.c compiles fine on a Linux machine. Any suggestions?
我正在使用Apple提供的flex.
I'm using the flex supplied by Apple.
推荐答案
某些系统将libfl与flex分开,这是很少需要的. libfl库仅包含两个函数:
Some systems make libfl a separate package from flex, as it is rarely needed. The libfl library just contains two functions:
int main() {
while (yylex());
return 0;
}
int yywrap() {
return 1;
}
通常,您将需要自己的main
函数,而不是libfl
中的函数,并且自己定义yywrap
是微不足道的.或者,您可以使用%option noyywrap
而不需要它.
Normally you'll want your own main
function rather than the one from libfl
, and defining yywrap
yourself is trivial. Alternately, you can use %option noyywrap
and not need it at all.
在您的情况下,请尝试摆脱-lfl
选项.如果您收到有关yywrap
的错误,请在test.lex
文件的第一部分中添加
%option noyywrap
.
In your case, try just getting rid of the -lfl
option. If you get an error about yywrap
, add%option noyywrap
to the first section of your test.lex
file.
这篇关于在OS X上使用Flex(词法分析器)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!