首页 > 代码库 > flex自动生成工具用法

flex自动生成工具用法

该文章和源码        from :  http://blog.csdn.net/hczhiyue/article/details/20483209


edit :

 

  1 /*name : lizi.flex*/
  2 %option noyywrap
  3 %{
  4 int num_lines = 0, num_chars = 0;
  5 %}
  6 %%
  7 \n ++num_lines; ++num_chars;
  8 . ++num_chars;
  9 %%
 10 int main()
 11 {
 12     yylex();
 13     printf("# of lines = %d, # of chars = %d\n", num_lines, num_chars);
 14     return 0;
 15 }

生成yy.flex.c文件

# flex lizi.flex

complier:

#gcc -g lex.yy.c -o scan

run:

   ./scan <  file.txt

flex自动生成工具用法