fork download
  1. %{
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. %}
  5.  
  6. %option noyywrap
  7.  
  8. %%
  9.  
  10. [ \t\n\r]+ { /* Ignore whitespace */ }
  11. "int"|"float"|"return" { printf("Keyword: %s\n", yytext); }
  12. [0-9]+ { printf("Number: %s\n", yytext); }
  13. [a-zA-Z_][a-zA-Z0-9_]* { printf("Identifier: %s\n", yytext); }
  14. "+"|"-"|"*"|"/" { printf("Operator: %s\n", yytext); }
  15.  
  16. . { printf("Unknown: %s\n", yytext); }
  17.  
  18. %%
  19.  
  20. int main() {
  21. yylex(); // This runs the lexical analyzer
  22. return 0;
  23. }
  24.  
Success #stdin #stdout #stderr 0.04s 6976KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/wkn7bt/prog:2:1: Syntax error: Operator expected
ERROR: /home/wkn7bt/prog:23:1: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit