%{
#include <stdio.h>
#include <stdlib.h>
%}
%%
// Patterns to recognize
[ \t\n]+ ; // Ignore whitespace
"int"|"float"|"char" { printf("Keyword: %s\n", yytext); }
[a-zA-Z_][a-zA-Z0-9_]* { printf("Identifier: %s\n", yytext); }
[0-9]+ { printf
("
Integer: %s\n", yytext); } "+"|"-"|"*"|"/" { printf("Operator: %s\n", yytext); }
"=" { printf("Assignment: %s\n", yytext); }
"(" { printf("Delimiter: %s\n", yytext); }
")" { printf("Delimiter: %s\n", yytext); }
"{" { printf("Delimiter: %s\n", yytext); }
"}" { printf("Delimiter: %s\n", yytext); }
"//".* ; // Ignore single line comments
"/*".* "*/" ; // Ignore multi-line comments
. { printf("Unknown: %s\n", yytext); }
%%
// Main function
int main(int argc, char **argv) {
yylex();
return 0;
}
// Error handling function
void yyerror(const char *s) {
fprintf(stderr, "Error: %s\n", s);
}
JXsKI2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KJX0KCiUlCgovLyBQYXR0ZXJucyB0byByZWNvZ25pemUKWyBcdFxuXSsgICAgICAgICAgICAgICA7ICAvLyBJZ25vcmUgd2hpdGVzcGFjZQoiaW50InwiZmxvYXQifCJjaGFyIiAgeyBwcmludGYoIktleXdvcmQ6ICVzXG4iLCB5eXRleHQpOyB9ClthLXpBLVpfXVthLXpBLVowLTlfXSogeyBwcmludGYoIklkZW50aWZpZXI6ICVzXG4iLCB5eXRleHQpOyB9ClswLTldKyAgICAgICAgICAgICAgICB7IHByaW50ZigiSW50ZWdlcjogJXNcbiIsIHl5dGV4dCk7IH0KIisifCItInwiKiJ8Ii8iICAgICAgIHsgcHJpbnRmKCJPcGVyYXRvcjogJXNcbiIsIHl5dGV4dCk7IH0KIj0iICAgICAgICAgICAgICAgICAgIHsgcHJpbnRmKCJBc3NpZ25tZW50OiAlc1xuIiwgeXl0ZXh0KTsgfQoiKCIgICAgICAgICAgICAgICAgICAgeyBwcmludGYoIkRlbGltaXRlcjogJXNc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