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