fork download
  1. %{
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. %}
  5.  
  6. digit [0-9]
  7. number {digit}+ // Matches one or more digits (integer numbers)
  8.  
  9. %%
  10.  
  11. {number} {
  12. int num = atoi(yytext); // Convert the matched string to an integer
  13. if (num % 2 == 0) {
  14. printf("%d is Even\n", num);
  15. } else {
  16. printf("%d is Odd\n", num);
  17. }
  18. }
  19.  
  20. .|\n { /* Ignore non-digit characters and newlines */ }
  21.  
  22. %%
  23.  
  24. int main() {
  25. printf("Enter a number: ");
  26. yylex(); // Start lexical analysis to process input
  27. return 0;
  28. }
  29.  
Success #stdin #stdout #stderr 0.03s 6780KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/KhxxRR/prog:28:1: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit