fork download
  1. %{
  2. #include <stdio.h>
  3. int ctTab = 0;
  4. int ctSpace = 0;
  5. int ctLine = 0;
  6. %}
  7.  
  8. %%
  9.  
  10. [\t] { ctTab++; }
  11. [ ] { ctSpace++; }
  12. [\n] { ctLine++; }
  13. . { /* ignore other characters */ }
  14.  
  15. %%
  16.  
  17. int yywrap() {
  18. return 1;
  19. }
  20.  
  21. int main(int argc, char *argv[]) {
  22. if(argc != 2) {
  23. printf("Usage: ./a.out <FILENAME>\n");
  24. return 1;
  25. }
  26.  
  27. FILE *file = fopen(argv[1], "r");
  28. if (!file) {
  29. perror("Error opening file");
  30. return 1;
  31. }
  32.  
  33. yyin = file;
  34. yylex();
  35.  
  36. printf("Line Count: %d\n", ctLine);
  37. printf("Space Count: %d\n", ctSpace);
  38. printf("Tab Count: %d\n", ctTab);
  39.  
  40. fclose(file);
  41. return 0;
  42. }
  43.  
Success #stdin #stdout #stderr 0.04s 6920KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/IU1gcJ/prog:2:1: Syntax error: Operator expected
ERROR: /home/IU1gcJ/prog:42:1: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit