fork download
  1. /* file: token_recognizer.l */
  2. %{
  3. #include <stdio.h>
  4. %}
  5.  
  6. DIGIT [0-9]
  7. ID [A-Za-z_][A-Za-z0-9_]*
  8. WS [ \t]+
  9.  
  10. %%
  11. "if" { printf("<KEYWORD, %s>\n", yytext); }
  12. "else" { printf("<KEYWORD, %s>\n", yytext); }
  13. {ID} { printf("<IDENT, %s>\n", yytext); }
  14. {DIGIT}+ { printf("<NUMBER, %s>\n", yytext); }
  15. "+"|"-"|"*"|"/" { printf("<OP, %s>\n", yytext); }
  16. ";" { printf("<SEMICOLON>\n"); }
  17. {WS} { /* ignore whitespace */ }
  18. \n { /* treat newline separately if needed */ }
  19. . { printf("<UNKNOWN, %s>\n", yytext); }
  20. %%
  21.  
  22. int main(void){
  23. yylex();
  24. return 0;
  25. }
  26.  
Success #stdin #stdout #stderr 0.02s 6892KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/v6WA9W/prog:3:1: Syntax error: Operator expected
ERROR: /home/v6WA9W/prog:25:1: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit