%{
#include <stdio.h>
int count = 0; // Initialize the count of capital letters
%}
%%
[A
-Z
] { // If the token
is a capital letter
printf("%s capital letter\n", yytext);
count++; // Increment the count
}
. { // For any other character
printf("%s not a capital letter\n", yytext);
}
\n
{ return
0; } // When newline
is encountered
, return
0 to stop processing
%%
int yywrap() {
return
1; // Return
1 to indicate that input
is finished
}
int main() {
printf("Enter text: ");
yylex(); // Start lexical analysis
printf("\nNumber of Capital letters in the given input - %d\n", count); // Output the result
return 0;
}
JXsKI2luY2x1ZGUgPHN0ZGlvLmg+CmludCBjb3VudCA9IDA7ICAvLyBJbml0aWFsaXplIHRoZSBjb3VudCBvZiBjYXBpdGFsIGxldHRlcnMKJX0KCiUlCgpbQS1aXSB7ICAvLyBJZiB0aGUgdG9rZW4gaXMgYSBjYXBpdGFsIGxldHRlcgogICAgcHJpbnRmKCIlcyBjYXBpdGFsIGxldHRlclxuIiwgeXl0ZXh0KTsKICAgIGNvdW50Kys7ICAvLyBJbmNyZW1lbnQgdGhlIGNvdW50Cn0KCi4geyAgLy8gRm9yIGFueSBvdGhlciBjaGFyYWN0ZXIKICAgIHByaW50ZigiJXMgbm90IGEgY2FwaXRhbCBsZXR0ZXJcbiIsIHl5dGV4dCk7Cn0KClxuIHsgcmV0dXJuIDA7IH0gIC8vIFdoZW4gbmV3bGluZSBpcyBlbmNvdW50ZXJlZCwgcmV0dXJuIDAgdG8gc3RvcCBwcm9jZXNzaW5nCgolJQoKaW50IHl5d3JhcCgpIHsKICAgIHJldHVybiAxOyAgLy8gUmV0dXJuIDEgdG8gaW5kaWNhdGUgdGhhdCBpbnB1dCBpcyBmaW5pc2hlZAp9CgppbnQgbWFpbigpIHsKICAgIHByaW50ZigiRW50ZXIgdGV4dDogIik7CiAgICB5eWxleCgpOyAgLy8gU3RhcnQgbGV4aWNhbCBhbmFseXNpcwogICAgcHJpbnRmKCJcbk51bWJlciBvZiBDYXBpdGFsIGxldHRlcnMgaW4gdGhlIGdpdmVuIGlucHV0IC0gJWRcbiIsIGNvdW50KTsgIC8vIE91dHB1dCB0aGUgcmVzdWx0CiAgICByZXR1cm4gMDsKfQo=