%{
#include <stdio.h>
#define max 5
int i = 0;
%}
Digit [0-9]
Letter [a-zA-Z]
Id {Letter}({Letter}|{Digit})*
Comment "//".*
%%
[ \t\n] {}
{Comment} {}
{Id} {
if(yyleng > max){
printf("Identifier (%s) Can't Exceed Length %d\n",yytext,max);
}else{
printf("Identifier : %s\n",yytext);
i++;
}
}
{Digit
} { printf
("
Number : %s\n",yytext); } "+"|"*"|"/"|"="|"("|")"|";"|"," { printf("Operator Or Punctuation : %s\n", yytext);
} .
{ printf("Unrecognized Character : %s\n", yytext); }
%%
int main(){
yylex();
printf("Valid Identifiers : %d\n",i);
return 0;
}
JXsgIAojaW5jbHVkZSA8c3RkaW8uaD4gCiNkZWZpbmUgbWF4IDUgIAppbnQgaSA9IDA7IAolfSAKRGlnaXQgWzAtOV0gIApMZXR0ZXIgW2EtekEtWl0gIApJZCB7TGV0dGVyfSh7TGV0dGVyfXx7RGlnaXR9KSogIApDb21tZW50ICIvLyIuKiAKJSUgIApbIFx0XG5dIHt9ICAKe0NvbW1lbnR9IHt9ICAKe0lkfSAgIHsgIAppZih5eWxlbmcgPiBtYXgpeyAKcHJpbnRmKCJJZGVudGlmaWVyICglcykgQ2FuJ3QgRXhjZWVkIExlbmd0aCAlZFxuIix5eXRleHQsbWF4KTsgCn1lbHNleyAgCnByaW50ZigiSWRlbnRpZmllciA6ICVzXG4iLHl5dGV4dCk7IAppKys7IAp9ICAKfSAgCntEaWdpdH0geyBwcmludGYoIk51bWJlciA6ICVzXG4iLHl5dGV4dCk7IH0gCiIrInwiKiJ8Ii8ifCI9InwiKCJ8IikifCI7InwiLCIgeyBwcmludGYoIk9wZXJhdG9yIE9yIFB1bmN0dWF0aW9uIDogJXNcbiIsIHl5dGV4dCk7IAp9IC4gCnsgcHJpbnRmKCJVbnJlY29nbml6ZWQgQ2hhcmFjdGVyIDogJXNcbiIsIHl5dGV4dCk7IH0gCiUlIAppbnQgbWFpbigpeyAKeXlsZXgoKTsgCnByaW50ZigiVmFsaWQgSWRlbnRpZmllcnMgOiAlZFxuIixpKTsgIApyZXR1cm4gMDsgCn0g