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.  
  11. [0-9]+ { printf("Integer Literal: %s\n", yytext); }
  12. [0-9]+"."[0-9]+ { printf("Float Literal: %s\n", yytext); }
  13. \"(\\.|[^\\"])*\" { printf("String Literal: %s\n", yytext); }
  14. \'.\' { printf("Character Literal: %s\n", yytext); }
  15.  
  16. "=="|"!="|"<="|">="|"<"|">" { printf("Relational Operator: %s\n", yytext); }
  17. "="|"+"|"-"|"*"|"/"|"%" { printf("Arithmetic Operator: %s\n", yytext); }
  18. "&&"|"||"|"!" { printf("Logical Operator: %s\n", yytext); }
  19. "&"|"|"|"^"|"<<"|">>" { printf("Bitwise Operator: %s\n", yytext); }
  20.  
  21. "(" | ")" | "{" | "}" | "[" | "]" | ";" | "," { printf("Special Symbol: %s\n", yytext); }
  22.  
  23. "//".* { printf("Single-line Comment\n"); }
  24. "/*"([^*]|[\r\n]|"*"[^/])*"*/" { printf("Multi-line Comment\n"); }
  25.  
  26. [ \t\n]+ /* Ignore whitespace */
  27.  
  28. . { printf("Unknown Token: %s\n", yytext); }
  29.  
  30. %%
  31.  
  32. int main() {
  33. yylex();
  34. return 0;
  35. }
  36.  
  37. int yywrap() {
  38. return 1;
  39. }
Success #stdin #stdout #stderr 0.03s 6792KB
stdin
int a=10
stdout
Standard output is empty
stderr
ERROR: /home/ZSCB5F/prog:2:1: Syntax error: End of file in quoted atom
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit