fork download
  1. %{
  2. #include <stdio.h>
  3. %}
  4.  
  5. %option noyywrap
  6.  
  7. %%
  8.  
  9. \n { num_newlines++; }
  10. [ \t] { num_spaces++; }
  11. [a-zA-Z]+ { num_words++; }
  12. [+\-*\/] { num_operators++; }
  13. [0-9]+ { num_operands++; }
  14. [a-zA-Z]+ { num_identifiers++; }
  15. [0-9]+ { num_constants++; }
  16. [=,;] { num_special_symbols++; }
  17. [aeiouAEIOU]{ num_vowels++; }
  18. [^aeiouAEIOU \t\n] { num_consonants++; }
  19.  
  20. %%
  21.  
  22. int yywrap() {
  23. return 1;
  24. }
  25.  
  26. int main() {
  27. yylex();
  28. printf("Number of newlines: %d\n", num_newlines);
  29. printf("Number of spaces: %d\n", num_spaces);
  30. printf("Number of words: %d\n", num_words);
  31. printf("Number of operators: %d\n", num_operators);
  32. printf("Number of operands: %d\n", num_operands);
  33. printf("Number of identifiers: %d\n", num_identifiers);
  34. printf("Number of constants: %d\n", num_constants);
  35. printf("Number of special symbols: %d\n", num_special_symbols);
  36. printf("Number of vowels: %d\n", num_vowels);
  37. printf("Number of consonants: %d\n", num_consonants);
  38. return 0;
  39. }
  40.  
Success #stdin #stdout #stderr 0.02s 6960KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/un1bOz/prog:39:1: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit