1

我正在尝试将 Flex 与 Visual C++ 一起使用。但是,生成的词法分析器(它是空的并且没有规则)在构建时会抛出这些错误:

configurationlexer.cpp(967): error C3861: 'read' identifier not found
configurationlexer.cpp(967): fatal error C1903: unable to recover from previous error(s); stopping compilation

源文件是:

%{
#include <string>
%}
%option yylineno

%%


%%

//Lexer End

我正在通过将此目标添加到我的 Visual Studio 项目中进行构建:

<Target Name="Flex" Inputs="$(MSBuildProjectDirectory)\ConfigurationLexer.l" Outputs="$(MSBuildProjectDirectory)\ConfigurationLexer.cpp;$(MSBuildProjectDirectory)\ConfigurationLexer.hpp">
  <Exec Command="C:\Cygwin\bin\flex.exe --nounistd -f -o &quot;$(MSBuildProjectDirectory)\ConfigurationLexer.cpp&quot; &quot;--header=$(MSBuildProjectDirectory)\ConfigurationLexer.hpp&quot; &quot;$(MSBuildProjectDirectory)\ConfigurationLexer.l&quot;" />
</Target>

是否可以将 Flex 与 MSVC 一起使用?

4

1 回答 1

2

好吧,如果比尔这个笨蛋会阅读文档会很有帮助:

-f, --full, %option full' specifies fast scanner. No table compression is done and stdio is bypassed. The result is large but fast. This option is equivalent to--Cfr'

这导致:

-Cr, --read, %option read' causes the generated scanner to bypass use of the standard I/O library (stdio) for input. Instead of calling fread() or getc(), the scanner will use the read() system call, resulting in a performance gain which varies from system to system, but in general is probably negligible unless you are also using-Cf' 或-CF'. Using-Cr' 可能会导致奇怪的行为,例如,如果您在调用扫描仪之前使用 stdio 从 yyin 读取(因为扫描仪将丢失您之前读取的任何文本留在 stdio 输入缓冲区中)。如果您定义 YY_INPUT(),则 `-Cr' 无效(请参阅生成的扫描器)。

我关闭了 -F,现在一切都按预期工作。由于其他原因,我不得不打开 --never-interactive。--always-interactive 如果您想要交互式扫描仪也可以使用....我不喜欢。

于 2010-07-24T23:54:09.610 回答