%option noyywrap
%{
int char_count = 0;
int word_count = 0;
int line_count = 0;
%}
%%
\n { line_count++; }
[a-zA-Z0-9]+ { word_count++; }
. { char_count++; }
%%
int main(int argc, char **argv) {
if (argc > 1) {
yyin = fopen(argv[1], "r");
if (!yyin) {
perror(argv[1]);
return 1;
}
}
yylex();
if (yyin != stdin) {
fclose(yyin);
}
printf("Characters: %d\n", char_count);
printf("Words: %d\n", word_count);
printf("Lines: %d\n", line_count);
return 0;
}
JW9wdGlvbiBub3l5d3JhcAoKJXsKaW50IGNoYXJfY291bnQgPSAwOwppbnQgd29yZF9jb3VudCA9IDA7CmludCBsaW5lX2NvdW50ID0gMDsKJX0KCiUlClxuICB7IGxpbmVfY291bnQrKzsgfQpbYS16QS1aMC05XSsgeyB3b3JkX2NvdW50Kys7IH0KLiAgeyBjaGFyX2NvdW50Kys7IH0KCiUlCgppbnQgbWFpbihpbnQgYXJnYywgY2hhciAqKmFyZ3YpIHsKICAgIGlmIChhcmdjID4gMSkgewogICAgICAgIHl5aW4gPSBmb3Blbihhcmd2WzFdLCAiciIpOwogICAgICAgIGlmICgheXlpbikgewogICAgICAgICAgICBwZXJyb3IoYXJndlsxXSk7CiAgICAgICAgICAgIHJldHVybiAxOwogICAgICAgIH0KICAgIH0KCiAgICB5eWxleCgpOwoKICAgIGlmICh5eWluICE9IHN0ZGluKSB7CiAgICAgICAgZmNsb3NlKHl5aW4pOwogICAgfQoKICAgIHByaW50ZigiQ2hhcmFjdGVyczogJWRcbiIsIGNoYXJfY291bnQpOwogICAgcHJpbnRmKCJXb3JkczogJWRcbiIsIHdvcmRfY291bnQpOwogICAgcHJpbnRmKCJMaW5lczogJWRcbiIsIGxpbmVfY291bnQpOwoKICAgIHJldHVybiAwOwp9