fork download
  1. %{
  2. #include <stdio.h>
  3. int line_count = 0, space_count = 0, tab_count = 0, other_count = 0;
  4. %}
  5.  
  6. %%
  7. \n { line_count++; }
  8. [ ] { space_count++; }
  9. \t { tab_count++; }
  10. . { other_count++; }
  11. %%
  12.  
  13. int main()
  14. {
  15. printf("Enter input (Ctrl+D to end):\n");
  16. yylex();
  17. printf("\nNumber of lines: %d\n", line_count);
  18. printf("Number of spaces: %d\n", space_count);
  19. printf("Number of tabs: %d\n", tab_count);
  20. printf("Number of other characters: %d\n", other_count);
  21. return 0;
  22. }
  23.  
  24. int yywrap() {
  25. return 1;
  26. }
  27.  
Success #stdin #stdout #stderr 0.04s 6920KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/GzP3TZ/prog:2:1: Syntax error: Operator expected
ERROR: /home/GzP3TZ/prog:26:1: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit