fork download
  1. %{
  2. int vowel_count = 0;
  3. int consonant_count = 0;
  4. %}
  5.  
  6. %%
  7. [a-zA-Z] {
  8. if (strchr("aeiouAEIOU", yytext[0]))
  9. ++vowel_count;
  10. else
  11. ++consonant_count;
  12. }
  13. . ; /* Ignore all other characters */
  14. \n {
  15. printf("Vowels: %d\n", vowel_count);
  16. printf("Consonants: %d\n", consonant_count);
  17. vowel_count = 0;
  18. consonant_count = 0;
  19. }
  20. %%
  21.  
  22. int main() {
  23. yylex();
  24. return 0;
  25. }
  26.  
Success #stdin #stdout #stderr 0.03s 6924KB
stdin
echo "Hello, World!" | ./count_vowels_consonants
stdout
Standard output is empty
stderr
ERROR: /home/lxMZtE/prog:2:4: Syntax error: Operator expected
ERROR: /home/lxMZtE/prog:25:1: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ?