fork download
  1. %{
  2. #include <stdio.h>
  3. #include <ctype.h>
  4.  
  5. int vowel_count = 0; // Counter for vowels
  6. int consonant_count = 0; // Counter for consonants
  7.  
  8. // Helper function to check if a character is a vowel
  9. int is_vowel(char ch) {
  10. ch = tolower(ch); // Convert to lowercase for uniformity
  11. return (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u');
  12. }
  13. %}
  14.  
  15. %%
  16.  
  17. [a-zA-Z] {
  18. if (is_vowel(yytext[0])) {
  19. vowel_count++;
  20. } else {
  21. consonant_count++;
  22. }
  23. }
  24.  
  25. [ \t\n] {
  26. // Ignore whitespace characters
  27. }
  28.  
  29. . {
  30. // Ignore any other non-alphabetic characters
  31. }
  32.  
  33. %%
  34.  
  35. int main() {
  36. printf("Enter a string:\n");
  37. yylex(); // Start lexical analysis
  38.  
  39. printf("\nVowel Count: %d\n", vowel_count);
  40. printf("Consonant Count: %d\n", consonant_count);
  41.  
  42. return 0;
  43. }
  44.  
  45. int yywrap() {
  46. return 1; // Indicate end of input
  47. }
Success #stdin #stdout #stderr 0.02s 6736KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/JYpXyO/prog:47:0: Syntax error: end_of_file_in_quasi_quotation
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit