/*** Definition Section has one variable
which can be accessed inside yylex()
and main() ***/
%{
int count = 0;
%}
/*** Rule Section has three rules, first rule
matches with capital letters, second rule
matches with any character except newline and
third rule does not take input after the enter***/
%%
[A-Z] {printf("%s capital letter\n", yytext);
count++;}
. {printf("%s not a capital letter\n", yytext);}
\n {return 0;}
%%
/*** Code Section prints the number of
capital letter present in the given input***/
int yywrap(){}
int main(){
// Explanation:
// yywrap() - wraps the above rule section
/* yyin - takes the file pointer
which contains the input*/
/* yylex() - this is the main flex function
which runs the Rule Section*/
// yytext
is the text in the buffer
// Uncomment the lines below
// to take input from file
// FILE *fp;
// char filename[50];
// printf("Enter the filename: \n");
// scanf("%s",filename);
// fp = fopen(filename,"r");
// yyin = fp;
yylex();
printf("\nNumber of Capital letters "
"in the given input - %d\n", count);
return 0;
}
LyoqKiBEZWZpbml0aW9uIFNlY3Rpb24gaGFzIG9uZSB2YXJpYWJsZQp3aGljaCBjYW4gYmUgYWNjZXNzZWQgaW5zaWRlIHl5bGV4KCkgCmFuZCBtYWluKCkgKioqLwolewppbnQgY291bnQgPSAwOwolfQoKLyoqKiBSdWxlIFNlY3Rpb24gaGFzIHRocmVlIHJ1bGVzLCBmaXJzdCBydWxlIAptYXRjaGVzIHdpdGggY2FwaXRhbCBsZXR0ZXJzLCBzZWNvbmQgcnVsZQptYXRjaGVzIHdpdGggYW55IGNoYXJhY3RlciBleGNlcHQgbmV3bGluZSBhbmQgCnRoaXJkIHJ1bGUgZG9lcyBub3QgdGFrZSBpbnB1dCBhZnRlciB0aGUgZW50ZXIqKiovCiUlCltBLVpdIHtwcmludGYoIiVzIGNhcGl0YWwgbGV0dGVyXG4iLCB5eXRleHQpOwogICAgICAgY291bnQrKzt9Ci4gICAgIHtwcmludGYoIiVzIG5vdCBhIGNhcGl0YWwgbGV0dGVyXG4iLCB5eXRleHQpO30KXG4gICAge3JldHVybiAwO30KJSUKCi8qKiogQ29kZSBTZWN0aW9uIHByaW50cyB0aGUgbnVtYmVyIG9mCmN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