1*357f1050SThomas Veerman /* Oops; slight change from wc3.l introduces backtracking */ 2*357f1050SThomas Veerman 3*357f1050SThomas Veerman ws [ \t] 4*357f1050SThomas Veerman nonws [^ \t\n] 5*357f1050SThomas Veerman word {ws}*{nonws}+ 6*357f1050SThomas Veerman words {word}{ws}+ 7*357f1050SThomas Veerman 8*357f1050SThomas Veerman %option main noyywrap 9*357f1050SThomas Veerman %% 10*357f1050SThomas Veerman int cc = 0, wc = 0, lc = 0; 11*357f1050SThomas Veerman 12*357f1050SThomas Veerman {word}{ws}* cc += yyleng; ++wc; 13*357f1050SThomas Veerman {word}{ws}*\n cc += yyleng; ++wc; ++lc; 14*357f1050SThomas Veerman {words}{word} cc += yyleng; wc += 2; /* oops */ 15*357f1050SThomas Veerman {words}{2}{word}{ws}* cc += yyleng; wc += 3; 16*357f1050SThomas Veerman {words}{3}{word}{ws}* cc += yyleng; wc += 4; 17*357f1050SThomas Veerman 18*357f1050SThomas Veerman {ws}+ cc += yyleng; 19*357f1050SThomas Veerman 20*357f1050SThomas Veerman \n+ cc += yyleng; lc += yyleng; 21*357f1050SThomas Veerman 22*357f1050SThomas Veerman <<EOF>> { 23*357f1050SThomas Veerman printf( "%8d %8d %8d\n", lc, wc, cc ); 24*357f1050SThomas Veerman yyterminate(); 25*357f1050SThomas Veerman } 26