fork download
  1. %{
  2. #include <stdio.h>
  3.  
  4. int charCount = 0;
  5. int wordCount = 0;
  6. int spaceCount = 0;
  7. int specialCount = 0;
  8. int upperCount = 0;
  9. int lowerCount = 0;
  10. int lineCount = 0;
  11. %}
  12.  
  13. %%
  14.  
  15. [A-Z] { charCount++; upperCount++; }
  16. [a-z] { charCount++; lowerCount++; }
  17. [ \t] { charCount++; spaceCount++; }
  18. \n { charCount++; lineCount++; }
  19. [0-9] { charCount++; } /* digits counted as characters */
  20. [^A-Za-z0-9 \t\n] { charCount++; specialCount++; }
  21. ([A-Za-z0-9]+) { wordCount++; }
  22.  
  23. %%
  24.  
  25. int main(int argc, char *argv[]) {
  26. if(argc > 1) {
  27. FILE *file = fopen(argv[1], "r");
  28. if(!file) {
  29. printf("Could not open file %s\n", argv[1]);
  30. return 1;
  31. }
  32. yyin = file;
  33. }
  34.  
  35. yylex();
  36.  
  37. printf("Total Characters: %d\n", charCount);
  38. printf("Total Words: %d\n", wordCount);
  39. printf("Blank Spaces: %d\n", spaceCount);
  40. printf("Special Characters: %d\n", specialCount);
  41. printf("Capital Letters: %d\n", upperCount);
  42. printf("Lowercase Letters: %d\n", lowerCount);
  43. printf("Number of Lines: %d\n", lineCount);
  44.  
  45. return 0;
  46. }
Success #stdin #stdout #stderr 0.03s 6856KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/5KJrhc/prog:46:0: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit