fork download
  1. %{
  2. #include <stdio.h>
  3. #include <string.h>
  4.  
  5. int vowel_count = 0;
  6. int consonant_count = 0;
  7. %}
  8.  
  9. %%
  10.  
  11. [aeiouAEIOU] { printf("%c is a vowel.\n", yytext[0]); vowel_count++; }
  12. [a-zA-Z] { printf("%c is a consonant.\n", yytext[0]); consonant_count++; }
  13. [ \t\n] { }
  14. . { printf("other\t"); }
  15.  
  16. %%
  17.  
  18. int yywrap() {
  19. return 1;
  20. }
  21.  
  22. int main() {
  23. printf("Enter a string: ");
  24. yylex();
  25. printf("\nNumber of vowels: %d\n", vowel_count);
  26. printf("Number of consonants: %d\n", consonant_count);
  27.     return 0; 
  28. }
  29.  
  30.  
Success #stdin #stdout #stderr 0.02s 6872KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/JsAMd4/prog:2:1: Syntax error: Operator expected
ERROR: /home/JsAMd4/prog:29:0: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit