fork download
  1. %{
  2. #include <stdio.h>
  3. #include <string.h>
  4.  
  5. int vowels = 0; //declare vowels and assign 0 value to it
  6. int consonants = 0; //declare consonants and assign 0 value to it
  7. %}
  8.  
  9. %%
  10.  
  11. [aeiouAEIOU] {vowels++;} //check for vowels and increment it when found or true
  12. [a-zA-Z] {consonants++;} //check for consonants and increment it when found or true
  13. .|\n {} //ignore other characters
  14.  
  15. %%
  16.  
  17. int main(){
  18. printf("Enter text\n");//asks for input
  19. yylex(); //calls the lexical analyzer
  20. printf("Vowels : %d", vowels);//print the number of vowels in the str
  21. printf("\nConsonants : %d", consonants);//print the number of consonants in the str
  22. }
  23.  
  24. int yywrap(){
  25. return 0;//to tell that it was a success
  26. }
Success #stdin #stdout #stderr 0.04s 6952KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/5EOU6i/prog:26:0: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit