%{
#include <stdio.h>

int char_count = 0; // Total number of characters
int word_count = 0; // Total number of words
int line_count = 0; // Total number of lines
%}

%%
\n          { line_count++; char_count++; } // Increment line and character counts for each newline
[ \t]+      { char_count += yyleng; }      // Count spaces and tabs as characters
[^\n \t]+   { char_count += yyleng; word_count++; } // Count non-whitespace as a word and characters
.           { char_count++; }              // Count any other character
%%

int main() {
    printf("Enter text (Ctrl+D to end input on Linux/macOS, Ctrl+Z on Windows):\n");
    yylex(); // Call the scanner

    // Print the results
    printf("\nLines: %d\n", line_count);
    printf("Words: %d\n", word_count);
    printf("Characters: %d\n", char_count);
    return 0;
}

int yywrap() {
    return 1; // Indicate end of input
}
