%{
#include <stdio.h>
int blank_spaces = 0;
int words = 0;
int lines = 0;
%}
%%
" " { blank_spaces++; } // Count blank spaces
\n { lines++; } // Count lines
[^\s\n]+ { words++; } // Count words (non-whitespace sequences)
. { } // Ignore any other characters
%%
int main() {
printf("Enter text (press Ctrl+D to end):\n");
yylex();
printf("\nResults:\n");
printf("Blank spaces: %d\n", blank_spaces);
printf("Words: %d\n", words);
printf("Lines: %d\n", lines);
return 0;
}
JXsKI2luY2x1ZGUgPHN0ZGlvLmg+CmludCBibGFua19zcGFjZXMgPSAwOwppbnQgd29yZHMgPSAwOwppbnQgbGluZXMgPSAwOwolfQoKJSUKIiAiICAgICAgICAgICAgICB7IGJsYW5rX3NwYWNlcysrOyB9ICAgICAgICAgLy8gQ291bnQgYmxhbmsgc3BhY2VzClxuICAgICAgICAgICAgICAgeyBsaW5lcysrOyB9ICAgICAgICAgICAgICAgIC8vIENvdW50IGxpbmVzClteXHNcbl0rICAgICAgICAgeyB3b3JkcysrOyB9ICAgICAgICAgICAgICAgIC8vIENvdW50IHdvcmRzIChub24td2hpdGVzcGFjZSBzZXF1ZW5jZXMpCi4gICAgICAgICAgICAgICAgeyB9ICAgICAgICAgICAgICAgICAgICAgICAgIC8vIElnbm9yZSBhbnkgb3RoZXIgY2hhcmFjdGVycwolJQoKaW50IG1haW4oKSB7CiAgICBwcmludGYoIkVudGVyIHRleHQgKHByZXNzIEN0cmwrRCB0byBlbmQpOlxuIik7CiAgICB5eWxleCgpOwogICAgcHJpbnRmKCJcblJlc3VsdHM6XG4iKTsKICAgIHByaW50ZigiQmxhbmsgc3BhY2VzOiAlZFxuIiwgYmxhbmtfc3BhY2VzKTsKICAgIHByaW50ZigiV29yZHM6ICVkXG4iLCB3b3Jkcyk7CiAgICBwcmludGYoIkxpbmVzOiAlZFxuIiwgbGluZXMpOwogICAgcmV0dXJuIDA7Cn0K