fork download
  1. %{
  2. #include <stdio.h>
  3. %}
  4.  
  5. %%
  6. // Define patterns for tokens
  7. [0-9]+ { printf("NUMBER: %s\n", yytext); }
  8. "+" { printf("PLUS\n"); }
  9. "-" { printf("MINUS\n"); }
  10. [ \t\n] { /* Ignore whitespace */ }
  11. . { printf("UNKNOWN: %s\n", yytext); }
  12.  
  13. %%
  14.  
  15. // Main function
  16. int main(void) {
  17. yylex(); // Call the lexer
  18. return 0;
  19. }
  20.  
Success #stdin #stdout #stderr 0.02s 6912KB
stdin
0+9
stdout
Standard output is empty
stderr
ERROR: /home/lp8rlX/prog:2:1: Syntax error: Operator expected
ERROR: /home/lp8rlX/prog:19:1: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit