fork download
  1. %{
  2. #include <stdio.h>
  3. int capitals = 0;
  4. int smalls = 0;
  5. int words = 0;
  6. %}
  7.  
  8. %%
  9. [A-Z] { capitals++; }
  10. [a-z] { smalls++; }
  11. [a-zA-Z]+ { words++; }
  12. [ \t\n]+ { /* Ignore whitespace */ }
  13. . { /* Ignore other characters */ }
  14. %%
  15.  
  16. int main() {
  17. printf("Enter a sentence (press Ctrl+D or Ctrl+Z to finish):\n");
  18. yylex();
  19. printf("Number of capital letters: %d\n", capitals);
  20. printf("Number of small letters: %d\n", smalls);
  21. printf("Number of words: %d\n", words);
  22. return 0;
  23. }
  24.  
  25. int yywrap() {
  26. return 1;
  27. }
Success #stdin #stdout #stderr 0.03s 6868KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/RSiPBk/prog:2:1: Syntax error: Operator expected
ERROR: /home/RSiPBk/prog:27:0: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit