fork download
  1. %{
  2. #include <stdio.h>
  3. #include <ctype.h>
  4.  
  5. int vowel_count = 0;
  6. int consonant_count = 0;
  7. %}
  8.  
  9. %%
  10. [aeiouAEIOU] { vowel_count++; }
  11. [b-df-hj-np-tv-zB-DF-HJ-NP-TV-Z] { consonant_count++; }
  12. . { /* Ignore other characters */ }
  13.  
  14. %%
  15.  
  16. int main(void) {
  17. yylex(); // Start scanning
  18. printf("Total vowels: %d\n", vowel_count);
  19. printf("Total consonants: %d\n", consonant_count);
  20. return 0;
  21. }
  22.  
  23. void yyerror(char *s) {
  24. fprintf(stderr, "Error: %s\n", s);
  25. }
  26.  
  27.  
  28. /*
  29. output:
  30. Hello World
  31.  
  32. Total vowels: 3
  33. Total consonants: 7
  34. */
Success #stdin #stdout #stderr 0.03s 6952KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/AI6q8r/prog:2:1: Syntax error: Operator expected
ERROR: /home/AI6q8r/prog:34:1: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit