summaryrefslogtreecommitdiff
path: root/examples/fastwc/wc1.l
diff options
context:
space:
mode:
Diffstat (limited to 'examples/fastwc/wc1.l')
-rw-r--r--examples/fastwc/wc1.l19
1 files changed, 19 insertions, 0 deletions
diff --git a/examples/fastwc/wc1.l b/examples/fastwc/wc1.l
new file mode 100644
index 0000000..0d4fcf2
--- /dev/null
+++ b/examples/fastwc/wc1.l
@@ -0,0 +1,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();
+ }