%{
#include <stdio.h>
// Variables to keep track of frequencies
int count_if = 0;
int count_else = 0;
int count_while = 0;
int total_keywords = 0;
%}

%option noyywrap

%%
"if"        { count_if++; total_keywords++; }
"else"      { count_else++; total_keywords++; }
"while"     { count_while++; total_keywords++; }

[a-zA-Z]+   { /* Ignore other words.  */ }
.|\n        { /* Ignore spaces, punctuation, and new lines */ }
%%

int main() {
    printf("Enter your text (Press Ctrl+Z and Enter on a new line to finish):\n");
    
    // yylex() starts the scanning process
    yylex();
    
    printf("\n--- Keyword Frequency Results ---\n");
    printf("'if' count    : %d\n", count_if);
    printf("'else' count  : %d\n", count_else);
    printf("'while' count : %d\n", count_while);
    printf("Total keywords: %d\n", total_keywords);
    
    return 0;
}