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.l18
1 files changed, 18 insertions, 0 deletions
diff --git a/examples/fastwc/wc1.l b/examples/fastwc/wc1.l
new file mode 100644
index 0000000..d6696bc
--- /dev/null
+++ b/examples/fastwc/wc1.l
@@ -0,0 +1,18 @@
+/* First cut at a flex-based "wc" tool. */
+
+ws [ \t]
+nonws [^ \t\n]
+
+%%
+ 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();
+ }