%{
#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; }
JXsKI2luY2x1ZGUgPHN0ZGlvLmg+CiV9CgpkaWdpdCBbMC05XQpsZXR0ZXIgW2EtekEtWl0KaWQge2xldHRlcn0oe2xldHRlcn18e2RpZ2l0fSkqCm51bWJlcnMge2RpZ2l0fSsoXC57ZGlnaXR9Kik/KEVbKy1dP3tkaWdpdH0rKT8KJSUKCntpZH0geyBwcmludGYoIiVzIGlzIGFuIGlkZW50aWZpZXJcbiIsIHl5dGV4dCk7IH0KaWZ8ZWxzZXxwcmludGZ8I2luY2x1ZGV8PHN0ZGlvLmg+fG1haW58aW50fGZsb2F0fGNoYXJ8cmV0dXJuIHsgcHJpbnRmKCIlcyBpcyBhIGtleXdvcmRcbiIsIHl5dGV4dCk7IH0KIjwifCI+InwiPD0ifCI+PSJ8Ij09InwhPSIgeyBwcmludGYoIiVzIGlzIGEgcmVsYXRpb25hbCBvcGVyYXRvclxuIiwgeXl0ZXh0KTsgfQp7bnVtYmVyc30geyBwcmludGYoIiVzIGlzIGEgbnVtYmVyXG4iLCB5eXRleHQpOyB9CiI9InwiK3wiLSJ8IioifCIvInwiJSIgeyBwcmludGYoIiVzIGlzIGFuIG9wZXJhdG9yXG4iLCB5eXRleHQpO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