fork download
  1. %{
  2. #include <string.h>
  3. int is_palindrome(char *str);
  4. %}
  5.  
  6. %%
  7. [a-zA-Z]+ {
  8. if (is_palindrome(yytext))
  9. printf("\"%s\" is a palindrome.\n", yytext);
  10. else
  11. printf("\"%s\" is NOT a palindrome.\n", yytext);
  12. }
  13. .|\n ;
  14. %%
  15.  
  16. int is_palindrome(char *str) {
  17. int len = strlen(str);
  18. for (int i = 0; i < len / 2; i++) {
  19. if (str[i] != str[len - 1 - i])
  20. return 0;
  21. }
  22. return 1;
  23. }
  24.  
  25. int main() {
  26. yylex();
  27. return 0;
  28. }
  29.  
Success #stdin #stdout #stderr 0.04s 6944KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/MlXT1S/prog:28:1: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit