%{
#include<stdio.h>
%}
%%
// Rules for token recognition
[ \t\n]+ ; // Ignore whitespace, tabs, and newlines
"if"|"else"|"while"|"for" printf("Keyword: %s\n", yytext); // Recognize keywords
[a-zA-Z_][a-zA-Z0-9_]* printf("Identifier: %s\n", yytext); // Recognize identifiers
[0-9]+ printf
("
Number: %s\n", yytext); // Recognize numbers "+"|"-"|"*"|"/"|"=" printf("Operator: %s\n", yytext); // Recognize operators
. printf("Unknown Symbol: %s\n", yytext); // Catch-all for unknown symbols
%%
int main() {
printf("Enter input to analyze:\n");
yylex(); // Invoke lexical analyzer
return 0;
}
JXsKI2luY2x1ZGU8c3RkaW8uaD4KJX0KCiUlCi8vIFJ1bGVzIGZvciB0b2tlbiByZWNvZ25pdGlvbgpbIFx0XG5dKyAgICAgICAgICAgICAgICAgIDsgLy8gSWdub3JlIHdoaXRlc3BhY2UsIHRhYnMsIGFuZCBuZXdsaW5lcwoiaWYifCJlbHNlInwid2hpbGUifCJmb3IiIHByaW50ZigiS2V5d29yZDogJXNcbiIsIHl5dGV4dCk7IC8vIFJlY29nbml6ZSBrZXl3b3JkcwpbYS16QS1aX11bYS16QS1aMC05X10qICAgIHByaW50ZigiSWRlbnRpZmllcjogJXNcbiIsIHl5dGV4dCk7IC8vIFJlY29nbml6ZSBpZGVudGlmaWVycwpbMC05XSsgICAgICAgICAgICAgICAgICAgIHByaW50ZigiTnVtYmVyOiAlc1xuIiwgeXl0ZXh0KTsgLy8gUmVjb2duaXplIG51bWJlcnMKIisifCItInwiKiJ8Ii8ifCI9IiAgICAgICBwcmludGYoIk9wZXJhdG9yOiAlc1xuIiwgeXl0ZXh0KTsgLy8gUmVjb2duaXplIG9wZXJhdG9ycwouICAgICAgICAgICAgICAgICAgICAgICAgIHByaW50ZigiVW5rbm93biBTeW1ib2w6ICVzXG4iLCB5eXRleHQpOyAvLyBDYXRjaC1hbGwgZm9yIHVua25vd24gc3ltYm9scwolJQoKaW50IG1haW4oKSB7CiAgICBwcmludGYoIkVudGVyIGlucHV0IHRvIGFuYWx5emU6XG4iKTsKICAgIHl5bGV4KCk7IC8vIEludm9rZSBsZXhpY2FsIGFuYWx5emVyCiAgICByZXR1cm4gMDsKfQo=