一个最简单的可以在vc++ 6上使用的lex的例子
这是一个最简单的可以在vc++ 6上使用的lex的例子。
输入文件名:string.l
用flex.exe 生成 lex.yy.c
%{
/* filename=string.l */
/* mafeitao http://www.18ie.com/ */
//使用方法:
//d:flex.exe string.l
//flexe.exe生成 了lex.yy.c
//然后,用vc++ 6,就可以直接编译lex.yy.c了
//flex生成的代码总是不能通过编译,说缺少yywrap的定义。
//后来多方查找反复试验终于发现,在前面加个%option noyywrap就好了
//软件目的:找出数字
%}
%option noyywrap
number [0-9]+
%%
{number} { printf("number=%sn",yytext); }
. {printf("");}
%%
main()
{ yylex();
return 0;
}
使用的更详细方法,可以看附图

运行程序,用手随意敲击一些字符,然后回车,如果输入的字符串里,有数字的话,就会被识别出来。
飞涛软件工作室
2006-10-03 21:22:04
Warning: MkDir failed (Disc quota exceeded) in /z1/18ie/public_html/count/html/count.php on line 12
Warning: fopen("/z1/18ie/public_html/count/html/2008_07/06_every.txt", "a+") - No such file or directory in /z1/18ie/public_html/count/html/count.php on line 42
Warning: Supplied argument is not a valid File-Handle resource in /z1/18ie/public_html/count/html/count.php on line 43
Warning: Supplied argument is not a valid File-Handle resource in /z1/18ie/public_html/count/html/count.php on line 46
Warning: Supplied argument is not a valid File-Handle resource in /z1/18ie/public_html/count/html/count.php on line 48
Warning: Supplied argument is not a valid File-Handle resource in /z1/18ie/public_html/count/html/count.php on line 49