Download deployment:
https://sourceforge.net/projects/winflexbison/download Win_flex_bison-latest.zip, unzip to C:\win_flex_bison
To edit a lex file:
Lex files use "percent" separated into three segments, namely: set a paragraph, the rules are short, user code section;
Here is a simple, ready-made example:
%{int num_lines = 0, num_chars = 0;%}%%\n ++num_lines; ++num_chars;. ++num_chars;%%int Yywrap () {return 1;}
View Code
Compile the Lex file:
>c:\win_flex_bison\win_flex.exe--wincompat a.l//Wincompat parameters cannot be saved
No news is good news, generated file lex.yy.c
Import VS2013 Project:
To create a new WIN32 console project using VS2013
Copy the lex.yy.c to the project and rename it to Lex.yy.cpp to join the project
Add in head: #include "stdafx.h"
The main function source file is as follows:
//testbench.cpp: Defines the entry point of the console application. //#include"stdafx.h"#include<stdio.h>extern intNum_lines;extern intNum_chars;externFILE *Yyin;extern intYylex (void);int_tmain (intARGC, _tchar*argv[]) {fopen_s (&yyin,"D:\\STUDY\\FLEXBISON\\LINECOUNTER\\A.L","R"); Yylex (); Fclose (Yyin); printf ("lines =%d, chars =%d\n", Num_lines, num_chars); return 0;}View Code
Compile and run, you are done.
Getting Started with Lex in the Windows environment