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