%{
#include <stdio.h>
#include <stdlib.h>
int COMMENT = 0;
%}
identifier [a-zA-Z][a-zA-Z0-9]*
%%
#.* { printf("\n%s is a Preprocessor Directive", yytext); }
int
|float|main
|if
|else
|printf
|scanf
|for
|char
|getch
|while
{ if (!COMMENT) printf("\n%s is a Keyword", yytext); }
"/*" { COMMENT = 1; }
"*/" { COMMENT = 0; }
{identifier}\({ if (!COMMENT) printf("\nFunction:\t%s", yytext); }
\{ { if (!COMMENT) printf("\nBlock Begins"); }
\} { if (!COMMENT) printf("\nBlock Ends"); }
{identifier}(\[[0-9]*\])? { if (!COMMENT) printf("\n%s is an Identifier", yytext); }
\".*\" { if (!COMMENT) printf("\n%s is a String", yytext); }
[0-9]+ { if (!COMMENT) printf("\n%s is a Number", yytext); }
\)(\;)? { if (!COMMENT) { printf("\t"); ECHO; printf("\n"); } }
\( { if (!COMMENT) { ECHO; printf("\n"); } }
\= { if (!COMMENT) printf("\n%s is an Assignment Operator", yytext); }
\<=|\>=|\<|\== { if (!COMMENT) printf("\n%s is a Relational Operator", yytext); }
.|\n { /* Ignore other characters */ }
%%
int main(int argc, char **argv) {
if (argc > 1) {
FILE *file = fopen(argv[1], "r");
if (!file) {
printf
("\nCould not
open the file
: %s", argv[1]); exit(0);
}
yyin = file;
}
yylex();
printf("\n\n");
return 0;
}
int yywrap() {
return 1;
}
JXsKI2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KCmludCBDT01NRU5UID0gMDsKJX0KCmlkZW50aWZpZXIgW2EtekEtWl1bYS16QS1aMC05XSoKCiUlCgojLiogeyBwcmludGYoIlxuJXMgaXMgYSBQcmVwcm9jZXNzb3IgRGlyZWN0aXZlIiwgeXl0ZXh0KTsgfQppbnR8ZmxvYXR8bWFpbnxpZnxlbHNlfHByaW50ZnxzY2FuZnxmb3J8Y2hhcnxnZXRjaHx3aGlsZQogICAgeyBpZiAoIUNPTU1FTlQpIHByaW50ZigiXG4lcyBpcyBhIEt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