| Line | |
|---|
| 1 | /* Fastest version of wc: add rules to pick up newlines, too */
|
|---|
| 2 |
|
|---|
| 3 | ws [ \t]
|
|---|
| 4 | nonws [^ \t\n]
|
|---|
| 5 | word {ws}*{nonws}+
|
|---|
| 6 | words {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.