2 // Copyright (c) 2001-2009 Hartmut Kaiser
4 // Distributed under the Boost Software License, Version 1.0. (See accompanying
5 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 #include <boost/timer.hpp>
17 [^ \t\n]+ { return ID_WORD; }
22 bool count(int tok, int* c, int* w, int* l)
25 case ID_WORD: ++*w; *c += yyleng; break;
26 case ID_EOL: ++*l; ++*c; break;
27 case ID_CHAR: ++*c; break;
34 int main(int argc, char* argv[])
37 int c = 0, w = 0, l = 0;
38 yyin = fopen(1 == argc ? "word_count.input" : argv[1], "r");
40 fprintf(stderr, "Couldn't open input file!\n");
47 if (!count(tok, &c, &w, &l))
50 printf("lines: %d, words: %d, characters: %d\n", l, w, c);
55 extern "C" int yywrap()