fork download
  1. %{
  2. #include <stdio.h>
  3. %}
  4.  
  5. %%
  6.  
  7. "void"|"int"|"float"|"double"|"char"|"if"|"else"|"while"|"for"|"do"|"break"|"continue"|"return"|"void"|"main" { printf("%s keyword\n", yytext); }
  8. [0-9]+ { printf("%s digit\n", yytext); }
  9. [a-zA-Z_][a-zA-Z0-9_]* { printf("%s identifier\n", yytext); }
  10. "//"(.*)"\n" { int n = strlen(yytext); int i = 0; while(i < n - 1) {if ((yytext[i] >= 0 && yytext[i] <= 9) || (yytext[i] >= 'a' && yytext[i] <= 'z') || (yytext[i] >= 'A' && yytext[i] <= 'Z') || yytext[i] == ' ' || yytext[i] == '/') {printf("%c", yytext[i]);} else break; i++;} printf(" comment\n");}
  11. "//"(.*) { printf("//%s comment\n", yytext+2); }
  12. [ \t\n] ; // Skip whitespace and newline characters
  13. . ; // Ignore any other character
  14. %%
  15.  
  16. int main() {
  17. yyin = stdin;
  18. yylex();
  19. return 0;
  20. }
Success #stdin #stdout #stderr 0.03s 6980KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/uOkc7T/prog:20:0: Syntax error: end_of_file_in_quasi_quotation
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit