%{
#include <stdio.h>
int word_count
= 0; // To count the
number of words
int char_count
= 0; // To count the
number of characters
int line_count
= 0; // To count the
number of lines
%}
%%
\n { line_count++; } // Increment line count on newline
[ \t]+ { /* Ignore spaces and tabs */ }
[A-Za-z0-9]+ { word_count++; char_count += yyleng; } // Count words and characters
. { char_count++; } // Count other characters (including punctuation)
%%
int main() {
yylex();
printf("Lines: %d\n", line_count);
printf("Words: %d\n", word_count);
printf("Characters: %d\n", char_count);
return 0;
}
JXsKI2luY2x1ZGUgPHN0ZGlvLmg+CgppbnQgd29yZF9jb3VudCA9IDA7ICAgICAgLy8gVG8gY291bnQgdGhlIG51bWJlciBvZiB3b3JkcwppbnQgY2hhcl9jb3VudCA9IDA7ICAgICAgLy8gVG8gY291bnQgdGhlIG51bWJlciBvZiBjaGFyYWN0ZXJzCmludCBsaW5lX2NvdW50ID0gMDsgICAgICAvLyBUbyBjb3VudCB0aGUgbnVtYmVyIG9mIGxpbmVzCiV9CgolJQoKXG4gICAgICAgICAgICAgIHsgbGluZV9jb3VudCsrOyB9ICAgLy8gSW5jcmVtZW50IGxpbmUgY291bnQgb24gbmV3bGluZQpbIFx0XSsgICAgICAgICAgeyAvKiBJZ25vcmUgc3BhY2VzIGFuZCB0YWJzICovIH0KW0EtWmEtejAtOV0rICAgIHsgd29yZF9jb3VudCsrOyBjaGFyX2NvdW50ICs9IHl5bGVuZzsgfSAgLy8gQ291bnQgd29yZHMgYW5kIGNoYXJhY3RlcnMKLiAgICAgICAgICAgICAgIHsgY2hhcl9jb3VudCsrOyB9ICAgLy8gQ291bnQgb3RoZXIgY2hhcmFjdGVycyAoaW5jbHVkaW5nIHB1bmN0dWF0aW9uKQoKJSUKCmludCBtYWluKCkgewogICAgeXlsZXgoKTsKICAgIHByaW50ZigiTGluZXM6ICVkXG4iLCBsaW5lX2NvdW50KTsKICAgIHByaW50ZigiV29yZHM6ICVkXG4iLCB3b3JkX2NvdW50KTsKICAgIHByaW50ZigiQ2hhcmFjdGVyczogJWRcbiIsIGNoYXJfY291bnQpOwogICAgcmV0dXJuIDA7Cn0K