%{
#include <stdio.h>
#include <string.h>
char key
[100][100], head
[100][100], dig
[100][100], op[100][100], id
[100][100];int i = 0, j = 0, k = 0, a = 0, b = 0, c = 0, d = 0, m = 0, n = 0;
%}
/* Define Regular Expressions */
KW "int"|"while"|"if"|"else"|"for"|"char"|"float"|"case"|"switch"
HF "#include<".*">"
DIG [0-9]*|[0-9]*"."[0-9]+
ID [a-zA-Z][a-zA-Z0-9]*
%%
/* Pattern Matching Rules */
{KW} { strcpy(key[i], yytext); i++; }
{HF} { strcpy(head[j], yytext); j++; }
{DIG} { strcpy(dig[k], yytext); k++; }
{OP} { strcpy
(op[m
], yytext
); m
++; } {ID} { strcpy(id[n], yytext); n++; }
. { /* Ignore other characters */ }
%%
/* Main Function */
int main() {
yyin = fopen("input.c", "r+");
yylex();
printf("\nThe keywords are:");
for (a = 0; a < i; a++) {
printf("\n%s", key[a]);
}
printf("\nThe header files are:");
for (b = 0; b < j; b++) {
printf("\n%s", head[b]);
}
printf("\nThe digits are:");
for (c = 0; c < k; c++) {
printf("\n%s", dig[c]);
}
printf("\nThe operators are:");
for (d = 0; d < m; d++) {
printf("\n%s", op[d]);
}
printf("\nThe identifiers are:");
for (d = 0; d < n; d++) {
printf("\n%s", id[d]);
}
return 0;
}
/* Function to Handle End of File */
int yywrap() {
return 1;
}
JXsKI2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdHJpbmcuaD4KCmNoYXIga2V5WzEwMF1bMTAwXSwgaGVhZFsxMDBdWzEwMF0sIGRpZ1sxMDBdWzEwMF0sIG9wWzEwMF1bMTAwXSwgaWRbMTAwXVsxMDBdOwppbnQgaSA9IDAsIGogPSAwLCBrID0gMCwgYSA9IDAsIGIgPSAwLCBjID0gMCwgZCA9IDAsIG0gPSAwLCBuID0gMDsKJX0KCi8qIERlZmluZSBSZWd1bGFyIEV4cHJlc3Npb25zICovCktXICAgImludCJ8IndoaWxlInwiaWYifCJlbHNlInwiZm9yInwiY2hhciJ8ImZsb2F0In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ZvciAoZCA9IDA7IGQgPCBtOyBkKyspIHsKICAgICAgICBwcmludGYoIlxuJXMiLCBvcFtkXSk7CiAgICB9CgogICAgcHJpbnRmKCJcblRoZSBpZGVudGlmaWVycyBhcmU6Iik7CiAgICBmb3IgKGQgPSAwOyBkIDwgbjsgZCsrKSB7CiAgICAgICAgcHJpbnRmKCJcbiVzIiwgaWRbZF0pOwogICAgfQoKICAgIHJldHVybiAwOwp9CgovKiBGdW5jdGlvbiB0byBIYW5kbGUgRW5kIG9mIEZpbGUgKi8KaW50IHl5d3JhcCgpIHsKICAgIHJldHVybiAxOwp9Cg==