%{
#include <stdio.h>
int lines = 0, spaces = 0, tabs = 0, words = 0, characters = 0;
%}
%%
\n { lines++; characters++; }
[ ] { spaces++; characters++; }
\t { tabs++; characters++; }
[a-zA-Z0-9]+ { words++; characters += yyleng; }
. { characters++; }
%%
int main() {
printf("Enter text (Ctrl+D to end on Linux/Mac or Ctrl+Z on Windows):\n");
yylex();
printf("Lines: %d\nSpaces: %d\nTabs: %d\nWords: %d\nCharacters: %d\n", lines, spaces, tabs, words, characters);
return 0;
}
int yywrap() {
return 1;
}
JXsKI2luY2x1ZGUgPHN0ZGlvLmg+CmludCBsaW5lcyA9IDAsIHNwYWNlcyA9IDAsIHRhYnMgPSAwLCB3b3JkcyA9IDAsIGNoYXJhY3RlcnMgPSAwOwolfQoKJSUKXG4gICAgICAgICAgICAgICB7IGxpbmVzKys7IGNoYXJhY3RlcnMrKzsgfQpbIF0gICAgICAgICAgICAgIHsgc3BhY2VzKys7IGNoYXJhY3RlcnMrKzsgfSAKXHQgICAgICAgICAgICAgICB7IHRhYnMrKzsgY2hhcmFjdGVycysrOyB9ClthLXpBLVowLTldKyAgICAgeyB3b3JkcysrOyBjaGFyYWN0ZXJzICs9IHl5bGVuZzsgfQouICAgICAgICAgICAgICAgIHsgY2hhcmFjdGVycysrOyB9CiUlCgppbnQgbWFpbigpIHsKICAgIHByaW50ZigiRW50ZXIgdGV4dCAoQ3RybCtEIHRvIGVuZCBvbiBMaW51eC9NYWMgb3IgQ3RybCtaIG9uIFdpbmRvd3MpOlxuIik7CiAgICB5eWxleCgpOwogICAgcHJpbnRmKCJMaW5lczogJWRcblNwYWNlczogJWRcblRhYnM6ICVkXG5Xb3JkczogJWRcbkNoYXJhY3RlcnM6ICVkXG4iLCBsaW5lcywgc3BhY2VzLCB0YWJzLCB3b3JkcywgY2hhcmFjdGVycyk7CiAgICByZXR1cm4gMDsKfQoKaW50IHl5d3JhcCgpIHsKICAgIHJldHVybiAxOwp9Cg==