%{
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;
}
JXsKaW50IGNvdW50ID0gMDsgIC8vIEluaXRpYWxpemUgdGhlIGNvdW50IG9mIGNhcGl0YWwgbGV0dGVycwolfQoKJSUKCltBLVpdIHsgIC8vIElmIHRoZSB0b2tlbiBpcyBhIGNhcGl0YWwgbGV0dGVyCiAgICBwcmludGYoIiVzIGNhcGl0YWwgbGV0dGVyXG4iLCB5eXRleHQpOwogICAgY291bnQrKzsgIC8vIEluY3JlbWVudCB0aGUgY291bnQKfQoKLiB7ICAvLyBGb3IgYW55IG90aGVyIGNoYXJhY3RlcgogICAgcHJpbnRmKCIlcyBub3QgYSBjYXBpdGFsIGxldHRlclxuIiwgeXl0ZXh0KTsKfQoKXG4geyByZXR1cm4gMDsgfSAgLy8gV2hlbiBuZXdsaW5lIGlzIGVuY291bnRlcmVkLCByZXR1cm4gMCB0byBzdG9wIHByb2Nlc3NpbmcKCiUlCgppbnQgeXl3cmFwKCkgewogICAgcmV0dXJuIDE7ICAvLyBSZXR1cm4gMSB0byBpbmRpY2F0ZSB0aGF0IGlucHV0IGlzIGZpbmlzaGVkCn0KCmludCBtYWluKCkgewogICAgcHJpbnRmKCJFbnRlciB0ZXh0OiAiKTsKICAgIHl5bGV4KCk7ICAvLyBTdGFydCBsZXhpY2FsIGFuYWx5c2lzCiAgICBwcmludGYoIlxuTnVtYmVyIG9mIENhcGl0YWwgbGV0dGVycyBpbiB0aGUgZ2l2ZW4gaW5wdXQgLSAlZFxuIiwgY291bnQpOyAgLy8gT3V0cHV0IHRoZSByZXN1bHQKICAgIHJldHVybiAwOwp9Cg==