fork download
  1. %{
  2. #include <stdio.h>
  3. int line_count = 0;
  4. int space_count = 0;
  5. int tab_count = 0;
  6. int other_char_count = 0;
  7. %}
  8.  
  9. %%
  10. \n { line_count++; } /* Increment line count */
  11. \t { tab_count++; } /* Increment tab count */
  12. " " { space_count++; } /* Increment space count */
  13. . { other_char_count++; } /* Increment other character count */
  14. %%
  15. int main() {
  16. printf("Enter input :\n");
  17. yylex();
  18. printf("Lines: %d\n", line_count);
  19. printf("Spaces: %d\n", space_count);
  20. printf("Tabs: %d\n", tab_count);
  21. printf("Other Characters: %d\n", other_char_count);
  22. return 0;
  23. }
  24. int yywrap() {
  25. return 1;
  26. }
  27.  
  28.  
Success #stdin #stdout #stderr 0.02s 6936KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/ruSYeq/prog:2:1: Syntax error: Operator expected
ERROR: /home/ruSYeq/prog:27:0: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit