fork download
  1. %{
  2. #include <stdio.h>
  3. int letter_count = 0, digit_count = 0, special_count = 0;
  4. %}
  5.  
  6. %%
  7. [a-zA-Z] { letter_count++; }
  8. [0-9] { digit_count++; }
  9. [^a-zA-Z0-9\n\t ] { special_count++; }
  10.  
  11. %%
  12.  
  13. int main(int argc, char *argv[]) {
  14. if (argc != 2) {
  15. printf("Usage: %s <filename>\n", argv[0]);
  16. return 1;
  17. }
  18. FILE *file = fopen(argv[1], "r");
  19. if (!file) {
  20. printf("Error: Could not open file %s\n", argv[1]);
  21. return 1;
  22. }
  23. yyin = file;
  24. yylex();
  25. fclose(file);
  26.  
  27. printf("Letters: %d\n", letter_count);
  28. printf("Numbers: %d\n", digit_count);
  29. printf("Special Characters: %d\n", special_count);
  30. return 0;
  31. }
  32.  
  33. int yywrap() {
  34. return 1;
  35. }
  36.  
Success #stdin #stdout #stderr 0.02s 6920KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/WOvlqp/prog:35:1: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit