fork download
  1. %{
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4.  
  5. %}
  6.  
  7. digit [0-9]
  8. number {digit}+ /* Matches a sequence of digits representing a number */
  9.  
  10. %%
  11.  
  12. {number} {
  13. int num = atoi(yytext); // Convert the matched text to an integer
  14. if (num % 2 == 0) {
  15. printf("%d is even\n", num);
  16. } else {
  17. printf("%d is odd\n", num);
  18. }
  19. }
  20.  
  21. %%
  22.  
  23. int main(int argc, char *argv[]) {
  24. if (argc > 1) {
  25. yylex(); // Run lexical analyzer on the input string
  26. } else {
  27. printf("Please provide a number as an argument.\n");
  28. }
  29. return 0;
  30. }
  31.  
Success #stdin #stdout #stderr 0.02s 7024KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/ONVW2u/prog:30:1: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit