fork download
  1. %{
  2. #include <stdio.h>
  3.  
  4. int char_count = 0;
  5. int word_count = 0;
  6. int line_count = 0;
  7. %}
  8.  
  9. %%
  10.  
  11. \n { line_count++; char_count++; } // Count newlines and characters
  12. [ \t]+ { char_count += yyleng; } // Count spaces/tabs as characters
  13. [^\t\n ]+ { word_count++; char_count += yyleng; } // Count words and their characters
  14. . { char_count++; } // Count any other characters
  15.  
  16. %%
  17.  
  18. int main(int argc, char **argv) {
  19. yylex(); // Call the lexer to process input
  20.  
  21. printf("Lines: %d\n", line_count);
  22. printf("Words: %d\n", word_count);
  23. printf("Characters: %d\n", char_count);
  24.  
  25. return 0;
  26. }
  27.  
  28. int yywrap() {
  29. return 1; // Indicates end of input
  30. }
  31.  
Success #stdin #stdout #stderr 0.03s 6948KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/9alvVi/prog:2:1: Syntax error: Operator expected
ERROR: /home/9alvVi/prog:30:1: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit