%{
#include <stdio.h>
#include <string.h>
// Function to check if a given string is a palindrome
int is_palindrome(char *str) {
int len = strlen(str);
for (int i = 0; i < len / 2; i++) {
if (str[i] != str[len - i - 1]) {
return 0; // Not a palindrome
}
}
return 1; // Is a palindrome
}
%}
%%
\n { /* Ignore empty lines */ }
.*\n {
yytext[strlen(yytext) - 1] = '\0'; // Remove newline character
if (is_palindrome(yytext)) {
printf("Palindrome: %s\n", yytext);
} else {
printf("Not a palindrome: %s\n", yytext);
}
}
.|\n { /* Ignore any other input */ }
%%
int main() {
printf("Enter a string: ");
yylex();
return 0;
}
Standard output is empty
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
Exception: (3) program ? ERROR: Unknown option (h for help)
Exception: (3) program ? ERROR: Unknown option (h for help)
Exception: (3) program ? ERROR: Unknown option (h for help)
Exception: (3) program ? ERROR: '$runtoplevel'/0: Undefined procedure: program/0
Exception: (3) program ? [Illegal port specification]
Exception: (3) program ? ERROR: Can't ignore goal at this port
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
Exception: (3) program ? ERROR: Can't ignore goal at this port
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
Exception: (3) program ? ERROR: '$runtoplevel'/0: Undefined procedure: program/0
Exception: (3) program ? ERROR: Can't ignore goal at this port
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
Exception: (3) program ? Call: (3) program ? ERROR: Unknown option (h for help)
Call: (3) program ? ERROR: Unknown option (h for help)
Call: (3) program ? ERROR: Can't retry at this port
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
Exception: (3) program ? ERROR: Unknown option (h for help)
Exception: (3) program ? ERROR: Unknown option (h for help)
Exception: (3) program ? ERROR: '$runtoplevel'/0: Undefined procedure: program/0
Exception: (3) program ? ERROR: Unknown option (h for help)
Exception: (3) program ? ERROR: Unknown option (h for help)
Exception: (3) program ? ERROR: No previous search
Exception: (3) program ? ERROR: Unknown option (h for help)
Exception: (3) program ? ERROR: Can't ignore goal at this port
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
Exception: (3) program ? Exception: (3) program ? ERROR: Unknown option (h for help)
Exception: (3) program ? Exception: (3) program ? ERROR: Unknown option (h for help)
Exception: (3) program ? ERROR: Unknown option (h for help)
Exception: (3) program ? ERROR: No previous search
Exception: (3) program ? ERROR: Unknown option (h for help)
Exception: (3) program ? ERROR: '$runtoplevel'/0: Undefined procedure: program/0
Exception: (3) program ? ERROR: Can't ignore goal at this port
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
Exception: (3) program ? Exception: (3) program ? ERROR: Unknown option (h for help)
Exception: (3) program ? Call: (3) program ? ERROR: Unknown option (h for help)
Call: (3) program ? EOF: exit