%{
#include <stdio.h>
#include <string.h>
%}
%%
[a-zA-Z]+ {
strcpy(num, yytext);
len = strlen(num);
int flag = 1;
for (int i = 0; i < len / 2; i++)
{
if (num[i] != num[len - 1 - i])
{
flag = 0;
break;
}
}
if (flag=1)
{
printf("\"%s\" is a palindrome.\n", num);
} else
{
printf("\"%s\" is not a palindrome.\n", num);
}
}
[ \t\n]+ ;
%%
int main() {
printf("Enter a string to check for palindrome:\n");
yylex();
return 0;
}
JXsKI2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdHJpbmcuaD4KCiV9CgolJQoKW2EtekEtWl0rICAgewogICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgIHN0cmNweShudW0sIHl5dGV4dCk7ICAKICAgICAgICAgICAgICAgIGxlbiA9IHN0cmxlbihudW0pOyAgCiAgICAgICAgICAgICAgICBpbnQgZmxhZyA9IDE7IAoKICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgZm9yIChpbnQgaSA9IDA7IGkgPCBsZW4gLyAyOyBpKyspIAogICAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgICAgIGlmIChudW1baV0gIT0gbnVtW2xlbiAtIDEgLSBpXSkKICAgICAgICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgICAgICAgIGZsYWcgPSAwOyAgCiAgICAgICAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0KCiAgICAgICAgICAgICAgICBpZiAoZmxhZz0xKSAKICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICBwcmludGYoIlwiJXNcIiBpcyBhIHBhbGluZHJvbWUuXG4iLCBudW0pOwogICAgICAgICAgICAgICAgfSBlbHNlCiAgICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgICAgcHJpbnRmKCJcIiVzXCIgaXMgbm90IGEgcGFsaW5kcm9tZS5cbiIsIG51bSk7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KClsgXHRcbl0rICA7IAoKJSUKCmludCBtYWluKCkgewogICAgcHJpbnRmKCJFbnRlciBhIHN0cmluZyB0byBjaGVjayBmb3IgcGFsaW5kcm9tZTpcbiIpOwogICAgeXlsZXgoKTsgIAogICAgcmV0dXJuIDA7Cn0KCg==