1/* Fastest version of wc: add rules to pick up newlines, too */ 2 3ws [ \t] 4nonws [^ \t\n] 5word {ws}*{nonws}+ 6words {word}{ws}+ 7 8%% 9 int cc = 0, wc = 0, lc = 0; 10 11{word}{ws}* ++wc; cc += yyleng; 12{word}{ws}*\n ++wc; cc += yyleng; ++lc; 13{words}{word}{ws}* wc += 2; cc += yyleng; 14{words}{word}{ws}*\n wc += 2; cc += yyleng; ++lc; 15{words}{2}{word}{ws}* wc += 3; cc += yyleng; 16{words}{2}{word}{ws}*\n wc += 3; cc += yyleng; ++lc; 17{words}{3}{word}{ws}* wc += 4; cc += yyleng; 18{words}{3}{word}{ws}*\n wc += 4; cc += yyleng; ++lc; 19 20{ws}+ cc += yyleng; 21 22\n+ cc += yyleng; lc += yyleng; 23 24<<EOF>> { 25 printf( "%8d %8d %8d\n", lc, wc, cc ); 26 yyterminate(); 27 } 28