fork download
  1. %{
  2. #include <stdio.h>
  3. int sc = 0, wc = 0, lc = 0, cc = 0;
  4. %}
  5.  
  6. %%
  7.  
  8. \n { lc++; }
  9. [ \t] { sc++; }
  10. [^\n \t]+ { wc++; cc += yyleng; }
  11.  
  12. %%
  13.  
  14. int main() {
  15. printf("Enter the input:\n");
  16. yylex();
  17. printf("The number of lines = %d\n", lc);
  18. printf("The number of spaces = %d\n", sc);
  19. printf("The number of words = %d\n", wc);
  20. printf("The number of characters = %d\n", cc);
  21. return 0;
  22. }
  23.  
  24. int yywrap() {
  25. return 1;
  26. }
Success #stdin #stdout #stderr 0.02s 6948KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/TVy9EU/prog:26:0: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit