Version 8 of fickle

Updated 2002-06-25 01:38:09

fickle is a Tcl utility that generates Tcl code, much like flex does for C code. From the README:

  This is a scanner generator program, much like flex(1) is to C.  If you
  have no desire to author Tcl programs, particularly those that
  manipulate text, fickle is not for you.

  A passing knowledge of flex or some other lex-like program would be
  useful, as that fickle uses nearly identical syntax and commands as
  flex.  Two good references are the flex man page and the O'Reilly book
  'lex & yacc' by Levine, Mason, and Brown.

(Complete README[L1 ]).

The fickle package comes with a bunch of example files, derived from lex & yacc[L2 ].

Download fickle 1.00 from http://tcl.jtang.org/fickle/fickle-1.00.tar.gz .

fickle is protected by the GNU general public license.

Invoke fickle before running the program, much akin to flex:

 > tclsh fickle.tcl foo.fcl
 > tclsh foo.tcl

whereas with flex it would be:

 > flex foo.f
 > gcc -o foo lex.yy.c -lfl
 > ./foo

For comparison purposes, here's a fickle specification file to match some English verbs:

 %{
 #!/usr/bin/tclsh

 # Recognizes various English verbs in sentences.

 # This is based upon example 'ch1-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/.

 %}

 %%

 [\t ]+        # ignore whitespace
 is |
 am |
 are |
 were |
 was |
 be |
 being |
 been |
 do |
 does |
 did |
 will          puts "$yytext: is a verb"
 [a-zA-Z]+     puts "$yytext: is not a verb"

 .|\n          ECHO  ;# normal default anyway

 %%

 yylex

And the equivalent flex version:

 %{
 /*
  * this sample demonstrates (very) simple recognition:
  * a verb/not a verb.  this example derived from 'ch1-02.l'.
  */
 %}

 %%

 [\t ]+        /* ignore whitespace */
 is |
 am |
 are |
 were |
 was |
 be |
 being |
 been |
 do |
 does |
 did |
 will          { printf ("%s: is a verb\n", yytext); }
 [a-zA-Z]+     { printf ("%s: is not a verb\n", yytext); }

 .|\n          { ECHO;  /* normal default anyway */ }

 %%

 main()
 {
     yylex();
 }

Post comments/complaints/flames here:


Return to Jason Tang


Category Application