fork download
  1. %{
  2. int token_count = 0;
  3. %}
  4.  
  5. %%
  6. "int"|"float"|"char"|"return"|"if"|"else"|"while"|"for"|"do"|"void" { token_count++; }
  7. [a-zA-Z_][a-zA-Z0-9_]* { token_count++; } // identifiers
  8. [0-9]+ { token_count++; } // integers
  9. [=+\-*/%<>&|!^] { token_count++; } // operators
  10. [{}();,] { token_count++; } // symbols
  11. [ \t\n]+ { /* ignore whitespace */ }
  12. . { token_count++; } // any other character as token
  13. %%
  14.  
  15. int main(int argc, char **argv)
  16. {
  17. yylex();
  18. printf("Total number of tokens: %d\n", token_count);
  19. return 0;
  20. }
  21.  
  22. int yywrap() {
  23. return 1;
  24. }
  25.  
Success #stdin #stdout #stderr 0.03s 6908KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/4sTgYb/prog:2:4: Syntax error: Operator expected
ERROR: /home/4sTgYb/prog:24:1: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit