fork download
  1. %{
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <ctype.h>
  5.  
  6. char str[256];
  7. %}
  8.  
  9. %%
  10.  
  11. [a-zA-Z]+ { strcpy(str, yytext); }
  12.  
  13. \n {
  14. int i = 0;
  15. int j = strlen(str) - 1;
  16. int is_palindrome = 1;
  17.  
  18. while (i < j) {
  19. if (tolower(str[i]) != tolower(str[j])) {
  20. is_palindrome = 0;
  21. break;
  22. }
  23. i++;
  24. j--;
  25. }
  26.  
  27. if (is_palindrome)
  28. printf("\"%s\" IS a palindrome.\n", str);
  29. else
  30. printf("\"%s\" is NOT a palindrome.\n", str);
  31. }
  32.  
  33. . { /* ignore other characters */ }
  34.  
  35. %%
  36.  
  37. int main(void) {
  38. printf("Enter a string: ");
  39. yylex();
  40. return 0;
  41. }
  42.  
  43. int yywrap(void) {
  44. return 1;
  45. }
Success #stdin #stdout #stderr 0.02s 6768KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/NGbYtX/prog:2:1: Syntax error: Operator expected
ERROR: /home/NGbYtX/prog:45:0: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit