fork download
  1. %{
  2. #include <stdio.h>
  3.  
  4. int word_count = 0;
  5. int line_count = 0;
  6. %}
  7.  
  8. %%
  9. \n { line_count++; }
  10. [^\t\n ]+ { word_count++; }
  11. . { }
  12. %%
  13.  
  14. int main() {
  15. printf("Enter your text (Press Ctrl+D on Linux/Mac or Ctrl+Z on Windows to finish):\n");
  16. yylex();
  17.  
  18. printf("\n--- Result Summary ---\n");
  19. printf("Total Words: %d\n", word_count);
  20. printf("Total Lines: %d\n", line_count);
  21.  
  22. return 0;
  23. }
  24.  
  25. int yywrap() {
  26. return 1;
  27. }
Success #stdin #stdout #stderr 0.02s 6824KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/MekNef/prog:2:1: Syntax error: Operator expected
ERROR: /home/MekNef/prog:27:0: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit