Getting Started with Lex in the Windows environment

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.