%{
#include <stdio.h>
#include <stdlib.h>
%}
%%
// Define tokens
[0-9]+ { printf
("
NUMBER: %s\n", yytext); } [ \t\n]+ { /* ignore whitespace */ }
"if" { printf("KEYWORD: %s\n", yytext); }
"else" { printf("KEYWORD: %s\n", yytext); }
[a-zA-Z_][a-zA-Z0-9_]* { printf("IDENTIFIER: %s\n", yytext); }
"+" { printf("OPERATOR: %s\n", yytext); }
"-" { printf("OPERATOR: %s\n", yytext); }
"*" { printf("OPERATOR: %s\n", yytext); }
"/" { printf("OPERATOR: %s\n", yytext); }
"=" { printf("ASSIGNMENT: %s\n", yytext); }
";" { printf("SEMICOLON: %s\n", yytext); }
. { printf("UNKNOWN: %s\n", yytext); }
%%
// Main function
int main(int argc, char **argv) {
yylex();
return 0;
}
// Error handling
void yyerror(const char *s) {
fprintf(stderr, "Error: %s\n", s);
}
JXsKI2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KJX0KCiUlCgovLyBEZWZpbmUgdG9rZW5zClswLTldKyAgICAgICAgICB7IHByaW50ZigiTlVNQkVSOiAlc1xuIiwgeXl0ZXh0KTsgfQpbIFx0XG5dKyAgICAgICB7IC8qIGlnbm9yZSB3aGl0ZXNwYWNlICovIH0KImlmIiAgICAgICAgICAgeyBwcmludGYoIktFWVdPUkQ6ICVzXG4iLCB5eXRleHQpOyB9CiJlbHNlIiAgICAgICAgIHsgcHJpbnRmKCJLRVlXT1JEOiAlc1xuIiwgeXl0ZXh0KTsgfQpbYS16QS1aX11bYS16QS1aMC05X10qIHsgcHJpbnRmKCJJREVOVElGSUVSOiAlc1xuIiwgeXl0ZXh0KTsgfQoiKyIgICAgICAgICAgICB7IHByaW50ZigiT1BFUkFUT1I6ICVzXG4iLCB5eXRleHQpOyB9CiItIiAgICAgICAgICAgIHsgcHJpbnRmKCJPUEVSQVRPUjogJXNcbiIsIHl5dGV4dCk7IH0KIioiICAgICAgICAgICAgeyBwcmludGYoIk9QRVJBVE9SOiAl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