fork download
  1. %{
  2. #include <stdio.h>
  3. int wc = 0, cc = 0, lc = 0, bc = 0;
  4. char infile[25];
  5. %}
  6.  
  7. %%
  8. \n { lc++; cc++; }
  9. [ \t]+ { bc += yyleng; cc += yyleng; }
  10. [^ \t\n]+ { wc++; cc += yyleng; }
  11. %%
  12.  
  13. int main()
  14. {
  15. printf("Read the Input File Name:\n");
  16. scanf("%s", infile);
  17.  
  18. yyin = fopen(infile, "r");
  19. if (!yyin)
  20. {
  21. printf("Cannot open file\n");
  22. return 1;
  23. }
  24.  
  25. yylex();
  26. fclose(yyin);
  27.  
  28. printf("No. of Chars : %d\n", cc);
  29. printf("No. of Words : %d\n", wc);
  30. printf("No. of Lines : %d\n", lc);
  31. printf("No. of Blanks: %d\n", bc);
  32.  
  33. return 0;
  34. }
  35.  
  36. int yywrap()
  37. {
  38. return 1;
  39. }
  40.  
Success #stdin #stdout #stderr 0.03s 7000KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/VAJnZr/prog:39:1: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit