fork download
  1. %{
  2. #include <stdio.h>
  3. int word_count = 0;
  4. int char_count = 0;
  5. int line_count = 0;
  6. %}
  7.  
  8. %%
  9. \n { line_count++; }
  10. [[:space:]]+ { char_count += yyleng; }
  11. [a-zA-Z0-9]+ { word_count++; char_count += yyleng; }
  12. . { char_count++; }
  13. %%
  14.  
  15. int main() {
  16. yylex(); // Start scanning input
  17. printf("Lines: %d\n", line_count);
  18. printf("Words: %d\n", word_count);
  19. printf("Characters: %d\n", char_count);
  20. return 0;
  21. }
  22.  
Success #stdin #stdout #stderr 0.03s 6904KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/PcHLvu/prog:2:1: Syntax error: Operator expected
ERROR: /home/PcHLvu/prog:21:1: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit