fork download
  1. %{
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. %}
  5.  
  6. %%
  7. [0-9]+ {
  8. int num = atoi(yytext);
  9. if (num % 2 == 0)
  10. printf("%s is even\n", yytext);
  11. else
  12. printf("%s is odd\n", yytext);
  13. }
  14.  
  15. [a-zA-Z0-9]+ {
  16. printf("%s is an invalid input\n", yytext);
  17. }
  18.  
  19. .|\n ; // Ignore other characters
  20. %%
  21.  
  22. int main() {
  23. printf("Enter a string: ");
  24. yylex();
  25. return 0;
  26. }
  27.  
  28. int yywrap() {
  29. return 1;
  30. }
  31.  
Success #stdin #stdout #stderr 0.03s 6872KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/iXVB7o/prog:30:1: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit