fork download
  1. %{
  2. #include <stdio.h>
  3. #include <string.h>
  4.  
  5. char num[100];
  6. int len;
  7. %}
  8.  
  9. %%
  10.  
  11. [a-zA-Z]+ {
  12. strcpy(num, yytext);
  13. len = strlen(num);
  14. int flag = 1;
  15.  
  16.  
  17. for (int i = 0; i < len / 2; i++) {
  18. if (num[i] != num[len - 1 - i]) {
  19. flag = 0;
  20. break;
  21. }
  22. }
  23.  
  24. if (flag == 1) { // Use '==' to compare
  25. printf("\"%s\" is a palindrome.\n", num);
  26. } else {
  27. printf("\"%s\" is not a palindrome.\n", num);
  28. }
  29. }
  30.  
  31. [ \t\n]+ ;
  32. %%
  33.  
  34. int main() {
  35. printf("Enter a string to check for palindrome:\n");
  36. yylex(); r
  37. return 0;
  38. }
  39.  
Success #stdin #stdout #stderr 0.02s 6996KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/6hRhRL/prog:38:1: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit