%{
#include <stdio.h>
#include <string.h>
int count = 0; // Counter to count occurrences
char targetWord[100] = "word"; // Word to be counted, replace "word" with your target
%}
%%
{targetWord} { count++; } // Increment count if target word matches
.|\n { /* ignore other characters */ }
%%
int main() {
printf("Enter the word to search for: ");
scanf("%s", targetWord); // Get target word from user
printf("Enter the sentence: ");
yylex(); // Start lexical analysis
printf("Frequency of '%s': %d\n", targetWord, count);
return 0;
}
int yywrap() {
return 1;
}
JXsKI2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdHJpbmcuaD4KCmludCBjb3VudCA9IDA7ICAgICAgICAgICAgICAgLy8gQ291bnRlciB0byBjb3VudCBvY2N1cnJlbmNlcwpjaGFyIHRhcmdldFdvcmRbMTAwXSA9ICJ3b3JkIjsgLy8gV29yZCB0byBiZSBjb3VudGVkLCByZXBsYWNlICJ3b3JkIiB3aXRoIHlvdXIgdGFyZ2V0CgolfQoKJSUKe3RhcmdldFdvcmR9ICB7IGNvdW50Kys7IH0gICAgICAgLy8gSW5jcmVtZW50IGNvdW50IGlmIHRhcmdldCB3b3JkIG1hdGNoZXMKLnxcbiAgICAgICAgICB7IC8qIGlnbm9yZSBvdGhlciBjaGFyYWN0ZXJzICovIH0KJSUKCmludCBtYWluKCkgewogICAgcHJpbnRmKCJFbnRlciB0aGUgd29yZCB0byBzZWFyY2ggZm9yOiAiKTsKICAgIHNjYW5mKCIlcyIsIHRhcmdldFdvcmQpOyAgLy8gR2V0IHRhcmdldCB3b3JkIGZyb20gdXNlcgoKICAgIHByaW50ZigiRW50ZXIgdGhlIHNlbnRlbmNlOiAiKTsKICAgIHl5bGV4KCk7ICAgICAgICAgICAgICAgICAgLy8gU3RhcnQgbGV4aWNhbCBhbmFseXNpcwoKICAgIHByaW50ZigiRnJlcXVlbmN5IG9mICclcyc6ICVkXG4iLCB0YXJnZXRXb3JkLCBjb3VudCk7CiAgICByZXR1cm4gMDsKfQoKaW50IHl5d3JhcCgpIHsKICAgIHJldHVybiAxOwp9