fork download
  1. %option noyywrap
  2. %{
  3. #include <stdio.h>
  4. int charCount = 0, wordCount = 0, sentenceCount = 0, lineCount = 0, tabCount = 0, numberCount = 0;
  5. %}
  6.  
  7. %%
  8. [a-zA-Z] { charCount++; }
  9. [ \t] { tabCount++; }
  10. [0-9]+ { numberCount++; }
  11. \n { lineCount++; }
  12. [.!?] { sentenceCount++; }
  13. [a-zA-Z]+ { wordCount++; }
  14. %%
  15.  
  16. int main() {
  17. yylex();
  18.  
  19. printf("Character count: %d\n", charCount);
  20. printf("Word count: %d\n", wordCount);
  21. printf("Sentence count: %d\n", sentenceCount);
  22. printf("Line count: %d\n", lineCount);
  23. printf("Tab count: %d\n", tabCount);
  24. printf("Number count: %d\n", numberCount);
  25.  
  26. return 0;
  27. }
  28.  
Success #stdin #stdout #stderr 0.02s 6968KB
stdin
I am a boy
stdout
Standard output is empty
stderr
ERROR: /home/J1CdXQ/prog:27:1: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit