tags:

views:

86

answers:

1

Hello :)

I'm trying to use Flex with Visual C++. However, the generated lexer (which is empty and has no rules) throws these errors while building:

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

The source file is:

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

%%


%%

//Lexer End

I'm building by adding this target to my Visual Studio project:

<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>

Is it possible to use Flex with MSVC?

EDIT: Made CW because I answered it myself and I'm not trying to be a rep whore.

+2  A: 

Well, it would be helpful if the bozo that is Bill would read the documentation:

-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'

which leads to:

-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' or -CF'. Using-Cr' can cause strange behavior if, for example, you read from yyin using stdio prior to calling the scanner (because the scanner will miss whatever text your previous reads left in the stdio input buffer). `-Cr' has no effect if you define YY_INPUT() (see Generated Scanner).

I turned off -F and now everything works as expected. For other reasons, I had to turn on --never-interactive. --always-interactive also works if you want an interactive scanner .... I don't.

Billy ONeal