fork download
  1. %{
  2. #include <stdio.h>
  3. int vow_count = 0, const_count = 0, digit_count = 0;
  4. int space_count = 0, word_count = 0, line_count = 0;
  5. %}
  6.  
  7. %%
  8.  
  9. [aeiouAEIOU] { vow_count++; } /* Count vowels */
  10. [b-df-hj-np-tv-zB-DF-HJ-NP-TV-Z] { const_count++; } /* Count consonants */
  11. [0-9] { digit_count++; } /* Count digits */
  12. [ \t]+ { space_count++; } /* Count spaces/tabs */
  13. \n { line_count++; word_count++; } /* Count new lines */
  14. [^ \t\n]+ { word_count++; } /* Count words */
  15.  
  16. %%
  17.  
  18. int main()
  19. {
  20. printf("Enter the input text (Ctrl+D or Ctrl+Z to end):\n");
  21. yylex();
  22. printf("\n----- OUTPUT -----\n");
  23. printf("Total vowels = %d\n", vow_count);
  24. printf("Total consonants = %d\n", const_count);
  25. printf("Total digits = %d\n", digit_count);
  26. printf("Total spaces = %d\n", space_count);
  27. printf("Total words = %d\n", word_count);
  28. printf("Total lines = %d\n", line_count);
  29. return 0;
  30. }
  31.  
  32. int yywrap()
  33. {
  34. return 1;
  35. }
  36.  
Success #stdin #stdout #stderr 0.04s 6972KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/nXebjv/prog:35:1: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit