该文章和源码 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
时间: 2024-10-11 23:31:00