1

Here is my lex file

 %%
 .|\n    ECHO;
 %%

How to run this program in windows? How to compile this?

Please help me

Thorin Oakenshield
  • 14,232
  • 33
  • 106
  • 146
  • 1
    You don't "run" a lex file. You feed it to a program like [flex](http://flex.sourceforge.net/), which generates C or C++ code for you, and then you incorporate that in your project. – cHao Dec 04 '11 at 07:07
  • ok how do i do that... please help me – Thorin Oakenshield Dec 04 '11 at 07:23
  • 1
    Step 0: [Download flex](http://gnuwin32.sourceforge.net/packages/flex.htm) and install it (adding to %PATH% if necessary). Step 1: `flex "the file's name"` (adding the `-+` option if you want C++ code rather than C). Step 2: take lex.yy.c* and add it to your project. It's pretty simple, really. – cHao Dec 04 '11 at 07:53

1 Answers1

2

Use this procedure to compile:

How to compile LEX/YACC files on Windows?

Basically:

flex olex.l
gcc lex.yy.c -o olex.exe

And this modified file:

%%

.|"\n"  { ECHO; }

%%

int yywrap(void)
{
    return 0;
}

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

I hope this works for you.

Community
  • 1
  • 1
DrBeco
  • 11,237
  • 9
  • 59
  • 76