%{
#include <stdio.h>
#include <string.h>
int i = 0; // Word count
%}
/* Rules Section */
%%
[a-zA-Z0-9]+ { i++; } // Increment word count for each sequence of alphanumeric characters
\n { // On a newline, print the word count and reset
printf("%d\n", i);
i = 0;
}
.|\n { /* Match any other character or newline (optional) */
/* This is to consume characters that are not words. */
}
/* Additional rule to catch end of input */
%%
int yywrap(void) {
return 1; // Indicate end of input
}
int main() {
// The function that starts the analysis
yylex();
// Print final count if the last line did not end with a newline
if (i > 0) {
printf("%d\n", i);
}
return 0;
}
JXsKI2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdHJpbmcuaD4KCmludCBpID0gMDsgLy8gV29yZCBjb3VudAolfQoKLyogUnVsZXMgU2VjdGlvbiAqLwolJSAKW2EtekEtWjAtOV0rIHsgaSsrOyB9IC8vIEluY3JlbWVudCB3b3JkIGNvdW50IGZvciBlYWNoIHNlcXVlbmNlIG9mIGFscGhhbnVtZXJpYyBjaGFyYWN0ZXJzCgpcbiB7IC8vIE9uIGEgbmV3bGluZSwgcHJpbnQgdGhlIHdvcmQgY291bnQgYW5kIHJlc2V0CiAgICBwcmludGYoIiVkXG4iLCBpKTsgCiAgICBpID0gMDsgCn0KCi58XG4geyAvKiBNYXRjaCBhbnkgb3RoZXIgY2hhcmFjdGVyIG9yIG5ld2xpbmUgKG9wdGlvbmFsKSAqLwogICAgLyogVGhpcyBpcyB0byBjb25zdW1lIGNoYXJhY3RlcnMgdGhhdCBhcmUgbm90IHdvcmRzLiAqLwp9CgovKiBBZGRpdGlvbmFsIHJ1bGUgdG8gY2F0Y2ggZW5kIG9mIGlucHV0ICovCiUlIAoKaW50IHl5d3JhcCh2b2lkKSB7CiAgICByZXR1cm4gMTsgLy8gSW5kaWNhdGUgZW5kIG9mIGlucHV0Cn0KCmludCBtYWluKCkgeyAKICAgIC8vIFRoZSBmdW5jdGlvbiB0aGF0IHN0YXJ0cyB0aGUgYW5hbHlzaXMgCiAgICB5eWxleCgpOyAKICAgIC8vIFByaW50IGZpbmFsIGNvdW50IGlmIHRoZSBsYXN0IGxpbmUgZGlkIG5vdCBlbmQgd2l0aCBhIG5ld2xpbmUKICAgIGlmIChpID4gMCkgewogICAgICAgIHByaW50ZigiJWRcbiIsIGkpOwogICAgfQogICAgcmV0dXJuIDA7IAp9Cg==