fork download
  1. %{
  2. #include <stdio.h>
  3. %}
  4.  
  5. /* Token Definitions */
  6. KEYWORD int|float|if|else|while|return|void|char
  7. IDENTIFIER [a-zA-Z_][a-zA-Z0-9_]*
  8. NUMBER [0-9]+(\.[0-9]+)?
  9. OPERATOR [+\-*/=<>]
  10. DELIMITER [;,(){}]
  11.  
  12. %%
  13. "//".* { /* Ignore single-line comments */ }
  14. "/*"([^*]|\*+[^/])*\*+/ { /* Ignore multi-line comments */ }
  15. [ \t\n]+ { /* Ignore whitespace */ }
  16. {KEYWORD} { printf("KEYWORD: %s\n", yytext); }
  17. {IDENTIFIER} { printf("IDENTIFIER: %s\n", yytext); }
  18. {NUMBER} { printf("NUMBER: %s\n", yytext); }
  19. {OPERATOR} { printf("OPERATOR: %s\n", yytext); }
  20. {DELIMITER} { printf("DELIMITER: %s\n", yytext); }
  21. . { printf("UNKNOWN: %s\n", yytext); }
  22. %%
  23.  
  24. int main() {
  25. yylex();
  26. return 0;
  27. }
  28.  
Success #stdin #stdout #stderr 0.03s 7056KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/4UTZHG/prog:2:1: Syntax error: Operator expected
ERROR: /home/4UTZHG/prog:27:1: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit