fork download
  1. %{
  2. #include <stdio.h>
  3.  
  4. int line = 1, word = 0, chars = 0;
  5. %}
  6.  
  7. %%
  8.  
  9. [a-zA-Z0-9]+ { word++; chars += yyleng; } // Count words and characters
  10. \n { line++; } // Count lines
  11. . { chars++; } // Count other characters
  12.  
  13. %%
  14.  
  15. int yywrap() { return 1; }
  16.  
  17. int main() {
  18. yyin = fopen("data.txt", "r");
  19. if (!yyin) {
  20. printf("Cannot open file data.txt\n");
  21. return 1;
  22. }
  23. yylex();
  24. printf("\nNumber of lines : %d", line);
  25. printf("\nNumber of words : %d", word);
  26. printf("\nNumber of characters : %d\n", chars);
  27. fclose(yyin);
  28. return 0;
  29. }
  30.  
Success #stdin #stdout #stderr 0.04s 6948KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/1LGqF1/prog:2:1: Syntax error: Operator expected
ERROR: /home/1LGqF1/prog:29:1: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit