Sunday, March 4, 2012

Flex (lexical analyser generator) and Microsoft Visual Studio (2010 Express)

(1) download dev-tools and binaries from  http://gnuwin32.sourceforge.net/packages/flex.htm
use the headers from the source files, and use the flex.exe or flex++.exe from the binaries file.

(2)  create sample file
Note:  we are defining    yywrap(),  so we no longer need the library  libfl.a

======== begin code ========

%{
#include <iostream>
using std::cout;
%}

%%

adre {cout<<"ADRE"<<std::endl;}
guapo {cout<<"GUAPO"<<std::endl;}

%%

int yywrap()
{
 return 1;
}

int main()
{
   yylex();
   
   return 0;
}


======== end code ========


(3)  do the command, note: the output should have .cpp as extension.
flex  -o.cpp

(4) you can now work with it in Microsoft Visual Studio 2010 Express Edition