fork download
  1. %{
  2. #include<stdio.h>
  3. %}
  4. %option noyymrap
  5. %%
  6. [\t\n]+ {/*ignore whitespace*/}
  7. "int"|"float"|"else"|"whie"|"{printf("keyword:%s\n",yytext);}
  8. [0-9]+ {printf("integer constant:%s\n",yytext);}
  9. [0-9]*","[0-9]+ {printf("float constant:%s\n",yytext);}
  10. "//",* {printf("single-line comment\n");}
  11. "^*"[^*]*"\*/" {printf("multi-line comment\n");}
  12. [a-zA-Z_][a-zA-Z0-9_]*{printf("identifer:%s\n",yytext);}
  13. "=="|"!"|"<"|"="|"+"|"-"|"*"|"/" {printf("operator:%s\n",yytext);}
  14. .
  15. {printf("unknown token":%s\n",yytext);}
  16. %%
  17. int main(){
  18. print("enter input:");
  19. yylex();
  20. return 0;
  21. }
Success #stdin #stdout #stderr 0.02s 6752KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/EMgCJy/prog:2:1: Syntax error: Operator expected
ERROR: /home/EMgCJy/prog:21:0: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit