fork download
  1. /* Lex program to count the number of vowels & consonants from the given input string */
  2. %{
  3. #include <stdio.h>
  4.  
  5. int vow = 0, con = 0;
  6. %}
  7.  
  8. %%
  9.  
  10. [ \t\n]+ ; /* Ignore whitespace */
  11. [aeiouAEIOU] { vow++; } /* Count vowels */
  12. [a-zA-Z&&[^aeiouAEIOU]] { con++; } /* Count consonants */
  13.  
  14. . ; /* Ignore all other characters */
  15.  
  16. %%
  17.  
  18. int main() {
  19. printf("Enter some input string:\n");
  20. yylex();
  21. printf("Number of vowels = %d\n", vow);
  22. printf("Number of consonants = %d\n", con);
  23. return 0;
  24. }
  25.  
  26. int yywrap() {
  27. return 1;
  28. }
  29.  
Success #stdin #stdout #stderr 0.03s 6956KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/LBhR37/prog:3:1: Syntax error: Operator expected
ERROR: /home/LBhR37/prog:28:1: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit