%{
#include <stdio.h>
%}

digit [0-9]
letter [a-zA-Z]
id {letter}({letter}|{digit})*
numbers {digit}+(\.{digit}*)?(E[+-]?{digit}+)?
%%

{id} { printf("%s is an identifier\n", yytext); }
if|else|printf|#include|<stdio.h>|main|int|float|char|return { printf("%s is a keyword\n", yytext); }
"<"|">"|"<="|">="|"=="|!=" { printf("%s is a relational operator\n", yytext); }
{numbers} { printf("%s is a number\n", yytext); }
"="|"+|"-"|"*"|"/"|"%" { printf("%s is an operator\n", yytext); }
"("|")"|"{"|"}" { printf("%s is a separator\n", yytext); }

%%

int main() {
    FILE *file = fopen("program.c", "r");
    if (!file) { 
        printf("Error: cannot open file program.c\n"); 
        return 1; 
    }
    yyin = file; 
    yylex(); 
    fclose(file); 
    return 0; 
}

int yywrap() { return 1; }
