fork download
  1. %{
  2. #include <stdio.h>
  3. int lines = 0, spaces = 0, tabs = 0, words = 0, characters = 0;
  4. %}
  5.  
  6. %%
  7. \n { lines++; characters++; }
  8. [ ] { spaces++; characters++; }
  9. \t { tabs++; characters++; }
  10. [a-zA-Z0-9]+ { words++; characters += yyleng; }
  11. . { characters++; }
  12. %%
  13.  
  14. int main() {
  15. printf("Enter text (Ctrl+D to end on Linux/Mac or Ctrl+Z on Windows):\n");
  16. yylex();
  17. printf("Lines: %d\nSpaces: %d\nTabs: %d\nWords: %d\nCharacters: %d\n", lines, spaces, tabs, words, characters);
  18. return 0;
  19. }
  20.  
  21. int yywrap() {
  22. return 1;
  23. }
  24.  
Success #stdin #stdout #stderr 0.03s 6808KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/rvWVgq/prog:2:1: Syntax error: Operator expected
ERROR: /home/rvWVgq/prog:23:1: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit