fork download
  1. %{
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <ctype.h>
  5. int vowel_count = 0;
  6. int consonant_count = 0;
  7. %}
  8.  
  9. %%
  10. [a-zA-Z] {
  11. char ch = yytext[0];
  12. ch = tolower(ch);
  13. if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u')
  14. {
  15. vowel_count++;
  16. printf("Vowel found: %c\n", yytext[0]);
  17. }
  18. else
  19. {
  20. consonant_count++;
  21. printf("Consonant found: %c\n", yytext[0]);
  22. }
  23. }
  24. [ \t\n] ; // Ignore whitespace
  25. . ; // Ignore everything else
  26. %%
  27.  
  28. int main(int argc, char **argv) {
  29.  
  30. FILE *file = fopen(argv[1], "r");
  31. yyin = file;
  32. yylex();
  33.  
  34. printf("\nTotal vowels: %d\n", vowel_count);
  35. printf("Total consonants: %d\n", consonant_count);
  36.  
  37. fclose(file);
  38. return 0;
  39. }
  40.  
  41. int yywrap() {
  42. return 1;
  43. }
Success #stdin #stdout #stderr 0.03s 6972KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/gYDi6P/prog:43:0: Syntax error: end_of_file_in_quasi_quotation
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit