fork download
  1. %{
  2. #include <stdio.h>
  3.  
  4. int numConsonants = 0;
  5. int numVowels = 0;
  6. %}
  7.  
  8. %%
  9. // Match vowels
  10. [aAeEiIoOuU] {
  11. numVowels++;
  12. printf("%c is a vowel\n", yytext[0]);
  13. }
  14.  
  15. // Match consonants
  16. [bBcCdDfFgGhHjJkKlLmMnNpPqQrRsStTvVwWxXyY] {
  17. numConsonants++;
  18. printf("%c is a consonant\n", yytext[0]);
  19. }
  20.  
  21. // Ignore other characters
  22. . { /* Ignore other characters */ }
  23.  
  24. %%
  25.  
  26. int main() {
  27. printf("Enter text (Ctrl+D to end input):\n");
  28. yylex(); // Start the lexical analysis
  29. printf("Total consonants: %d\n", numConsonants);
  30. printf("Total vowels: %d\n", numVowels);
  31. return 0;
  32. }
  33.  
Success #stdin #stdout #stderr 0.02s 6980KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/8qzyLE/prog:2:1: Syntax error: Operator expected
ERROR: /home/8qzyLE/prog:32:1: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit