fork download
  1. %{
  2. #include <stdio.h>
  3. #include <ctype.h>
  4. int lines = 0, words = 0, chars = 0;
  5. %}
  6.  
  7. %option noyywrap
  8.  
  9. %%
  10. \n { lines++; chars++; }
  11. [ \t]+ { chars += yyleng; }
  12. [a-zA-Z_][a-zA-Z0-9_]* { words++; chars += yyleng; printf("Identifier: %s\n", yytext); }
  13. [0-9]+ { chars += yyleng; printf("Number: %s\n", yytext); }
  14. [+\-*/=<>!&|]+ { chars += yyleng; printf("Operator: %s\n", yytext); }
  15. [{}()\[\],;] { chars += yyleng; printf("Special Character: %s\n", yytext); }
  16. . { chars += yyleng; }
  17.  
  18. %%
  19.  
  20. int main() {
  21. yylex();
  22. printf("\nLines: %d\nWords: %d\nCharacters: %d\n", lines, words, chars);
  23. return 0;
  24. }
  25.  
Success #stdin #stdout #stderr 0.03s 6884KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/edNPNn/prog:2:1: Syntax error: Operator expected
ERROR: /home/edNPNn/prog:24:1: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit