xref: /minix3/external/bsd/flex/dist/examples/fastwc/wc4.l (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*357f1050SThomas Veerman /* Fastest version of wc: add rules to pick up newlines, too */
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}*		++wc; cc += yyleng;
13*357f1050SThomas Veerman {word}{ws}*\n		++wc; cc += yyleng; ++lc;
14*357f1050SThomas Veerman {words}{word}{ws}*	wc += 2; cc += yyleng;
15*357f1050SThomas Veerman {words}{word}{ws}*\n	wc += 2; cc += yyleng; ++lc;
16*357f1050SThomas Veerman {words}{2}{word}{ws}*	wc += 3; cc += yyleng;
17*357f1050SThomas Veerman {words}{2}{word}{ws}*\n	wc += 3; cc += yyleng; ++lc;
18*357f1050SThomas Veerman {words}{3}{word}{ws}*	wc += 4; cc += yyleng;
19*357f1050SThomas Veerman {words}{3}{word}{ws}*\n	wc += 4; cc += yyleng; ++lc;
20*357f1050SThomas Veerman 
21*357f1050SThomas Veerman {ws}+			cc += yyleng;
22*357f1050SThomas Veerman 
23*357f1050SThomas Veerman \n+			cc += yyleng; lc += yyleng;
24*357f1050SThomas Veerman 
25*357f1050SThomas Veerman <<EOF>>		{
26*357f1050SThomas Veerman 		printf( "%8d %8d %8d\n", lc, wc, cc );
27*357f1050SThomas Veerman 		yyterminate();
28*357f1050SThomas Veerman 		}
29