wc4.l revision 1.1
1/*	$NetBSD: wc4.l,v 1.1 2009/10/26 00:28:34 christos Exp $	*/
2
3/* Fastest version of wc: add rules to pick up newlines, too */
4
5ws    [ \t]
6nonws [^ \t\n]
7word  {ws}*{nonws}+
8words {word}{ws}+
9
10%option main noyywrap
11%%
12	int cc = 0, wc = 0, lc = 0;
13
14{word}{ws}*		++wc; cc += yyleng;
15{word}{ws}*\n		++wc; cc += yyleng; ++lc;
16{words}{word}{ws}*	wc += 2; cc += yyleng;
17{words}{word}{ws}*\n	wc += 2; cc += yyleng; ++lc;
18{words}{2}{word}{ws}*	wc += 3; cc += yyleng;
19{words}{2}{word}{ws}*\n	wc += 3; cc += yyleng; ++lc;
20{words}{3}{word}{ws}*	wc += 4; cc += yyleng;
21{words}{3}{word}{ws}*\n	wc += 4; cc += yyleng; ++lc;
22
23{ws}+			cc += yyleng;
24
25\n+			cc += yyleng; lc += yyleng;
26
27<<EOF>>		{
28		printf( "%8d %8d %8d\n", lc, wc, cc );
29		yyterminate();
30		}
31