%{
#include <stdio.h>
#include <stdlib.h>
%}
%%
"int" { printf("Keyword: int\n"); }
"float"
{ printf
("Keyword
: float\n"
); }"if" { printf("Keyword: if\n"); }
"else" { printf("Keyword: else\n"); }
[a-zA-Z_][a-zA-Z0-9_]* { printf("Identifier: %s\n", yytext); }
[0-9]+ { printf
("
Number: %s\n", yytext); } "+" { printf("Operator: +\n"); }
"-" { printf("Operator: -\n"); }
"*" { printf("Operator: *\n"); }
"/" { printf("Operator: /\n"); }
"=" { printf("Operator: =\n"); }
";" { printf("Delimiter: ;\n"); }
"\n" { /* Ignore newlines */ }
[ \t\r] { /* Ignore whitespace */ }
. { printf("Unknown: %s\n", yytext); }
%%
int main() {
yylex(); // Invoke the lexical analyzer
return 0;
}
JXsKI2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KJX0KCiUlCiJpbnQiICAgICAgICB7IHByaW50ZigiS2V5d29yZDogaW50XG4iKTsgfQoiZmxvYXQiICAgICAgeyBwcmludGYoIktleXdvcmQ6IGZsb2F0XG4iKTsgfQoiaWYiICAgICAgICAgeyBwcmludGYoIktleXdvcmQ6IGlmXG4iKTsgfQoiZWxzZSIgICAgICAgeyBwcmludGYoIktleXdvcmQ6IGVsc2VcbiIpOyB9ClthLXpBLVpfXVthLXpBLVowLTlfXSogICB7IHByaW50ZigiSWRlbnRpZmllcjogJXNcbiIsIHl5dGV4dCk7IH0KWzAtOV0rICAgICAgIHsgcHJpbnRmKCJOdW1iZXI6ICVzXG4iLCB5eXRleHQpOyB9CiIrIiAgICAgICAgICB7IHByaW50ZigiT3BlcmF0b3I6ICtcbiIpOyB9CiItIiAgICAgICAgICB7IHByaW50ZigiT3BlcmF0b3I6IC1cbiIpOyB9CiIqIiAgICAgICAgICB7IHByaW50ZigiT3BlcmF0b3I6ICpcbiIpOyB9CiIvIiAgICAgICAgICB7IHByaW50ZigiT3BlcmF0b3I6IC9cbiIpOyB9CiI9IiAgICAgICAgICB7IHByaW50ZigiT3BlcmF0b3I6ID1cbiIpOyB9CiI7IiAgICAgICAgICB7IHByaW50ZigiRGVsaW1pdGVyOiA7XG4iKTsgfQoiXG4iICAgICAgICAgeyAvKiBJZ25vcmUgbmV3bGluZXMgKi8gfQpbIFx0XHJdICAgICAgeyAvKiBJZ25vcmUgd2hpdGVzcGFjZSAqLyB9Ci4gICAgICAgICAgICB7IHByaW50ZigiVW5rbm93bjogJXNcbiIsIHl5dGV4dCk7IH0KJSUKCmludCBtYWluKCkgewogICAgeXlsZXgoKTsgLy8gSW52b2tlIHRoZSBsZXhpY2FsIGFuYWx5emVyCiAgICByZXR1cm4gMDsKfQoK