fork download
  1. %{
  2. #include <stdio.h>
  3. %}
  4.  
  5. %%
  6.  
  7. "auto"|"break"|"case"|"char"|"const"|"continue"|"default"|"do"|"double"|"else"|"enum"|"extern"|"float"|"for"|"goto"|"if"|"inline"|"int"|"long"|"register"|"restrict"|"return"|"short"|"signed"|"sizeof"|"static"|"struct"|"switch"|"typedef"|"union"|"unsigned"|"void"|"volatile"|"while" { printf("Keyword:%s\n",yytext);}
  8.  
  9. [a-zA-Z_][a-zA-Z0-9]* { printf("Identifier:%s\n",yytext);}
  10. [0-9]+"."[0-9]+ { printf("Float Literal:%s\n",yytext);}
  11. \"(\\.|[^\\"])*\" { printf("String Literal:%s\n",yytext);}
  12. \'.\' { printf("Character Literal:%s\n",yytext);}
  13.  
  14. "=="|"!="|"<="|">="|"<"|">"{ printf("Relational Operator:%s\n",yytext);}
  15.  
  16. "("|")"|"{"|"}"|"["|"]"|";"|"," { printf("Special Symbol:%s\n",yytext);}
  17.  
  18. "//".* { printf("Single-line Comment\n");}
  19. "/*"([^*]|[\r\n]|"*"[^/])*"*/" { printf("Multi-line Comment\n");}
  20.  
  21. [\t\n]+ /*Ignore whitespace*/
  22.  
  23. . { printf("Unknown Token:%s\n",yytext);}
  24.  
  25. %%
  26.  
  27. int main(){
  28. yylex();
  29. return 1;
  30. }
Success #stdin #stdout #stderr 0.02s 6864KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/mFlwWG/prog:2:1: Syntax error: End of file in quoted atom
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit