fork download
  1. %{
  2. #include <stdio.h>
  3.  
  4. // Define token types
  5. #define MOV 1
  6. #define ADD 2
  7. #define NUM 3
  8. #define IDENTIFIER 4
  9. %}
  10.  
  11. %%
  12.  
  13. "mov" { return MOV; }
  14. "add" { return ADD; }
  15. [0-9]+ { return NUM; } // Removed yylval since we are not using Yacc/Bison
  16. [a-zA-Z][a-zA-Z0-9]* { return IDENTIFIER; }
  17. [\t\n ]+ { /* Ignore whitespace */ }
  18. . { printf("Unknown character: %s\n", yytext); }
  19.  
  20. %%
  21.  
  22. int main() {
  23. int token;
  24. while ((token = yylex())) {
  25. printf("Token: %d\n", token);
  26. }
  27. return 0;
  28. }
  29.  
Success #stdin #stdout #stderr 0.03s 6988KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/mEKwEj/prog:2:1: Syntax error: Operator expected
ERROR: /home/mEKwEj/prog:28:1: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit