%{
#include <stdio.h>
#include <string.h>
char num[100];
int len;
%}
%%
[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) { // Use '==' to compare
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(); r
return 0;
}
JXsKI2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdHJpbmcuaD4KCmNoYXIgbnVtWzEwMF07ICAKaW50IGxlbjsgICAgICAgIAolfQoKJSUKClthLXpBLVpdKyAgIHsKICAgICAgICAgICAgICAgIHN0cmNweShudW0sIHl5dGV4dCk7ICAKICAgICAgICAgICAgICAgIGxlbiA9IHN0cmxlbihudW0pOyAgCiAgICAgICAgICAgICAgICBpbnQgZmxhZyA9IDE7IAoKICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgZm9yIChpbnQgaSA9IDA7IGkgPCBsZW4gLyAyOyBpKyspIHsKICAgICAgICAgICAgICAgICAgICBpZiAobnVtW2ldICE9IG51bVtsZW4gLSAxIC0gaV0pIHsKICAgICAgICAgICAgICAgICAgICAgICAgZmxhZyA9IDA7ICAKICAgICAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgfQoKICAgICAgICAgICAgICAgIGlmIChmbGFnID09IDEpIHsgIC8vIFVzZSAnPT0nIHRvIGNvbXBhcmUKICAgICAgICAgICAgICAgICAgICBwcmludGYoIlwiJXNcIiBpcyBhIHBhbGluZHJvbWUuXG4iLCBudW0pOwogICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICBwcmludGYoIlwiJXNcIiBpcyBub3QgYSBwYWxpbmRyb21lLlxuIiwgbnVtKTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQoKWyBcdFxuXSsgIDsgIAolJQoKaW50IG1haW4oKSB7CiAgICBwcmludGYoIkVudGVyIGEgc3RyaW5nIHRvIGNoZWNrIGZvciBwYWxpbmRyb21lOlxuIik7CiAgICB5eWxleCgpOyAgcgogICAgcmV0dXJuIDA7IAp9Cg==