%{
#include <stdio.h>
#include <string.h>

int keyword_count = 0;
int identifier_count = 0;

// List of C keywords
char *keywords[] = {
    "int", "float", "if", "else", "while", "return", "for", "char", "void", NULL
};

int is_keyword(const char *word) {
    for (int i = 0; keywords[i] != NULL; i++) {
        if (strcmp(word, keywords[i]) == 0)
            return 1;
    }
    return 0;
}
%}

%%

[a-zA-Z_][a-zA-Z0-9_]* {
    if (is_keyword(yytext)) {
        printf("Keyword: %s\n", yytext);
        keyword_count++;
    } else {
        printf("Identifier: %s\n", yytext);
        identifier_count++;
    }
}

[ \t\n]+   ;   // Ignore whitespace
.          ;   // Ignore other characters

%%

int main() {
    printf("Enter code (press Ctrl+D to finish input):\n");
    yylex();
    printf("\nTotal Keywords: %d\n", keyword_count);
    printf("Total Identifiers: %d\n", identifier_count);
    return 0;
}

int yywrap() {
    return 1;
}
