source: trunk/essentials/sys-devel/flex/examples/fastwc/wc4.l

Last change on this file was 3031, checked in by bird, 18 years ago

flex 2.5.33.

File size: 680 bytes
Line 
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%option main noyywrap
9%%
10 int cc = 0, wc = 0, lc = 0;
11
12{word}{ws}* ++wc; cc += yyleng;
13{word}{ws}*\n ++wc; cc += yyleng; ++lc;
14{words}{word}{ws}* wc += 2; cc += yyleng;
15{words}{word}{ws}*\n wc += 2; cc += yyleng; ++lc;
16{words}{2}{word}{ws}* wc += 3; cc += yyleng;
17{words}{2}{word}{ws}*\n wc += 3; cc += yyleng; ++lc;
18{words}{3}{word}{ws}* wc += 4; cc += yyleng;
19{words}{3}{word}{ws}*\n wc += 4; cc += yyleng; ++lc;
20
21{ws}+ cc += yyleng;
22
23\n+ cc += yyleng; lc += yyleng;
24
25<<EOF>> {
26 printf( "%8d %8d %8d\n", lc, wc, cc );
27 yyterminate();
28 }
Note: See TracBrowser for help on using the repository browser.