fork download
  1. %{
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4.  
  5. void yyerror(const char *s);
  6. int yylex(void);
  7. %}
  8.  
  9. %%
  10.  
  11. [0-9]+ { printf("NUMBER: %s\n", yytext); }
  12. [a-zA-Z_][a-zA-Z_0-9]* { printf("IDENTIFIER: %s\n", yytext); }
  13. "+"|"-"|"*"|"/" { printf("OPERATOR: %s\n", yytext); }
  14. \n { /* Ignore newlines */ }
  15. [ \t] { /* Ignore whitespace */ }
  16. . { printf("UNKNOWN: %s\n", yytext); }
  17.  
  18. %%
  19.  
  20. int main(void) {
  21. yylex();
  22. return 0;
  23. }
  24.  
  25. void yyerror(const char *s) {
  26. fprintf(stderr, "Error: %s\n", s);
  27. }
  28.  
Success #stdin #stdout #stderr 0.03s 6944KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/WLh80L/prog:2:1: Syntax error: Operator expected
ERROR: /home/WLh80L/prog:27:1: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit