fork download
  1. %{
  2. #include <stdio.h>
  3. int blank_spaces = 0;
  4. int words = 0;
  5. int lines = 0;
  6. %}
  7.  
  8. %%
  9. " " { blank_spaces++; } // Count blank spaces
  10. \n { lines++; } // Count lines
  11. [^\s\n]+ { words++; } // Count words (non-whitespace sequences)
  12. . { } // Ignore any other characters
  13. %%
  14.  
  15. int main() {
  16. printf("Enter text (press Ctrl+D to end):\n");
  17. yylex();
  18. printf("\nResults:\n");
  19. printf("Blank spaces: %d\n", blank_spaces);
  20. printf("Words: %d\n", words);
  21. printf("Lines: %d\n", lines);
  22. return 0;
  23. }
  24.  
Success #stdin #stdout #stderr 0.03s 6972KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/Q3yL4v/prog:2:1: Syntax error: Operator expected
ERROR: /home/Q3yL4v/prog:23:1: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit