summaryrefslogtreecommitdiff
path: root/examples/fastwc/wc1.l
blob: 0d4fcf23cdf9f6872a931f53d4128cf7c138c62d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/* First cut at a flex-based "wc" tool. */

ws    [ \t]
nonws [^ \t\n]

%option main noyywrap
%%
	int cc = 0, wc = 0, lc = 0;

{nonws}+	cc += yyleng; ++wc;

{ws}+		cc += yyleng;

\n		++lc; ++cc;

<<EOF>>		{
		printf( "%8d %8d %8d\n", lc, wc, cc );
		yyterminate();
		}