%{
#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; 
}
