fork download
  1. %{
  2. #include <stdio.h>
  3.  
  4. int vowels_count = 0;
  5. int consonants_count = 0;
  6. %}
  7.  
  8. %%
  9.  
  10. // Match vowels (both uppercase and lowercase)
  11. [aeiouAEIOU] { vowels_count++; }
  12.  
  13. // Match consonants (both uppercase and lowercase)
  14. [b-df-hj-np-tv-zB-DF-HJ-NP-TV-Z] { consonants_count++; }
  15.  
  16. // Ignore any other characters (digits, punctuation, whitespace)
  17. . { /* Ignore other characters */ }
  18.  
  19. %%
  20.  
  21. // Main function
  22. int main(int argc, char **argv) {
  23. yylex(); // Start the lexical analysis
  24. printf("Vowels: %d\n", vowels_count);
  25. printf("Consonants: %d\n", consonants_count);
  26. return 0;
  27. }
Success #stdin #stdout #stderr 0.02s 6936KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/gfeuLR/prog:2:1: Syntax error: Operator expected
ERROR: /home/gfeuLR/prog:27:0: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit