fork download
  1. %{
  2. #include <stdio.h>
  3. int vowel_count = 0;
  4. int consonant_count = 0;
  5. %}
  6.  
  7. %%
  8. [aeiouAEIOU] { vowel_count++; }
  9. [a-zA-Z] { consonant_count++; }
  10. .|\n ; /* ignore everything else */
  11. %%
  12.  
  13. int main(int argc, char *argv[]) {
  14. if(argc > 1) {
  15. FILE *fp = fopen(argv[1], "r");
  16. if(!fp) {
  17. printf("Cannot open file %s\n", argv[1]);
  18. return 1;
  19. }
  20. yyin = fp;
  21. }
  22. yylex();
  23. printf("Total vowels: %d\n", vowel_count);
  24. printf("Total consonants: %d\n", consonant_count);
  25. return 0;
  26. }
  27.  
Success #stdin #stdout #stderr 0.02s 6904KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/FpV49W/prog:26:1: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit