flex 词法分析
fb.l
1 %option noyywrap 2 %{ 3 #include <stdio.h> 4 int chars = 0; 5 int words = 0; 6 int lines = 0; 7 %} 8 9 %% 10 11 [a-zA-Z]+ { words++; chars += strlen(yytext); } 12 { chars++; lines++; } 13 . { chars++; } 14 15 %% 16 17 int main(int argc, char **argv) 18 { 19 yylex(); 20 printf("%8d%8d%8d ", lines, words, chars); 21 }
$ flex fb.l
$ cc lex.yy.c
$ cat fb.l | ./a.out
%option noyywrap
http://stackoverflow.com/questions/1811125/undefined-reference-to-yywrap