summaryrefslogtreecommitdiffstats
path: root/fickle/examples/wc.fcl
diff options
context:
space:
mode:
Diffstat (limited to 'fickle/examples/wc.fcl')
-rw-r--r--fickle/examples/wc.fcl40
1 files changed, 40 insertions, 0 deletions
diff --git a/fickle/examples/wc.fcl b/fickle/examples/wc.fcl
new file mode 100644
index 0000000..871b3ad
--- /dev/null
+++ b/fickle/examples/wc.fcl
@@ -0,0 +1,40 @@
+%{
+#!/usr/bin/tclsh
+
+# Counts characters, words, and lines within its input.
+
+# This is based upon example 'ch2-02.l' from "lex & yacc" by John
+# R. Levine, Tony Mason, and Doug Brown (by O'Reilly & Associates, ISBN
+# 1-56592-000-7). For more information on using lex and yacc, see
+# http://www.oreilly.com/catalog/lex/.
+
+set charCount 0
+set wordCount 0
+set lineCount 0
+
+%}
+
+word [^ \t\n]+
+eol \n
+
+%%
+
+{word} { incr ::wordCount; incr ::charCount $yyleng }
+{eol} { incr ::charCount; incr ::lineCount }
+. { incr ::charCount }
+
+%%
+
+if {[llength $argv] > 0} {
+ if {[catch {open [lindex $argv 0]} f]} {
+ puts stderr "could not open file [lindex $argv 0]"
+ exit 1
+ }
+ set yyin $f
+}
+
+yylex
+
+puts "$charCount $wordCount $lineCount"
+
+return 0