%{
#include<stdio.h>
%}
%%
"+"|"-"|"*"|"/"|"="|"==" { printf("Operator: %s\n", yytext); }
"("|")"|"{"|"}"|";" { printf("Symbol: %s\n", yytext); }
"include"|"main"|"printf"|"return" { printf("Keyword: %s\n", yytext); }
[0-9]+ { printf
("
Number: %s\n", yytext); } [a-zA-Z_][a-zA-Z0-9_]* { printf("Identifier: %s\n", yytext); }
[ \t\n]+ ; /* Ignore whitespace */
%%
int main(int argc, char *argv[]) {
if (argc != 2) {
printf("Usage: %s \n", argv[0]);
return 1;
}
FILE *file = fopen(argv[1], "r");
if (!file) {
perror("Error opening file");
return 1;
}
yyin = file; // Set the input stream for flex
yylex();
fclose(file);
return 0;
}
int yywrap() {
return 1;
}
JXsKI2luY2x1ZGU8c3RkaW8uaD4gCiV9CgolJQoiKyJ8Ii0ifCIqInwiLyJ8Ij0ifCI9PSIgeyBwcmludGYoIk9wZXJhdG9yOiAlc1xuIiwgeXl0ZXh0KTsgfQoiKCJ8IikifCJ7InwifSJ8IjsiIHsgcHJpbnRmKCJTeW1ib2w6ICVzXG4iLCB5eXRleHQpOyB9CiJpbmNsdWRlInwibWFpbiJ8InByaW50ZiJ8InJldHVybiIgeyBwcmludGYoIktleXdvcmQ6ICVzXG4iLCB5eXRleHQpOyB9ClswLTldKyB7IHByaW50ZigiTnVtYmVyOiAlc1xuIiwgeXl0ZXh0KTsgfQpbYS16QS1aX11bYS16QS1aMC05X10qIHsgcHJpbnRmKCJJZGVudGlmaWVyOiAlc1xuIiwgeXl0ZXh0KTsgfQpbIFx0XG5dKyA7IC8qIElnbm9yZSB3aGl0ZXNwYWNlICovCiUlCgppbnQgbWFpbihpbnQgYXJnYywgY2hhciAqYXJndltdKSB7CmlmIChhcmdjICE9IDIpIHsKcHJpbnRmKCJVc2FnZTogJXMgXG4iLCBhcmd2WzBdKTsKcmV0dXJuIDE7Cn0KCkZJTEUgKmZpbGUgPSBmb3Blbihhcmd2WzFdLCAiciIpOwppZiAoIWZpbGUpIHsKcGVycm9yKCJFcnJvciBvcGVuaW5nIGZpbGUiKTsKcmV0dXJuIDE7Cn0KCnl5aW4gPSBmaWxlOyAvLyBTZXQgdGhlIGlucHV0IHN0cmVhbSBmb3IgZmxleAp5eWxleCgpOwpmY2xvc2UoZmlsZSk7CnJldHVybiAwOwp9CgppbnQgeXl3cmFwKCkgewpyZXR1cm4gMTsKfQ==