From f1d010bed8760aa87f9c72eded97d4d9b98cc620 Mon Sep 17 00:00:00 2001 From: Manoj Srivastava Date: Fri, 29 Jul 2016 18:07:24 -0700 Subject: Import flex_2.6.1.orig.tar.gz [dgit import orig flex_2.6.1.orig.tar.gz] --- examples/manual/wc.lex | 122 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100644 examples/manual/wc.lex (limited to 'examples/manual/wc.lex') diff --git a/examples/manual/wc.lex b/examples/manual/wc.lex new file mode 100644 index 0000000..7cae6a1 --- /dev/null +++ b/examples/manual/wc.lex @@ -0,0 +1,122 @@ +%{ + +/* + * wc.lex : A simple example of using FLEX + * to create a wc-like utility. + * + * See MISC/fastwc/ in the flex distribution for examples + * of how to write this scanner for maximum performance. + */ + +int numchars = 0; +int numwords = 0; +int numlines = 0; +int totchars = 0; +int totwords = 0; +int totlines = 0; + +/* + * rules start from here + */ + +%} + +%% + +[\n] { numchars++; numlines++; } +[\r] { numchars++; } +[^ \t\n]+ { numwords++; numchars += yyleng; } +. { numchars++; } + +%% + +/* + * additional C code start from here. This supplies + * all the argument processing etc. + */ + +int main(int argc, char *argv[]) +{ + int loop,first=1; + int lflag = 0; /* 1 if we count # of lines */ + int wflag = 0; /* 1 if we count # of words */ + int cflag = 0; /* 1 if we count # of characters */ + int fflag = 0; /* 1 if we have a file name */ + + for(loop=1; loop