fork download
  1. %{
  2. #include <stdio.h>
  3. int ctChar=0;
  4. int ctSpace=0;
  5. int ctWord=0;
  6. int ctLine=0;
  7. %}
  8. WORD [^ \t\n,\.:]+
  9. EOL [\n]
  10. BLANK [ ]
  11. %%
  12.  
  13. {WORD} {ctWord++; ctChar+=yyleng;}
  14. {BLANK} {ctSpace++;}
  15. {EOL} {ctLine++;}
  16. . {ctChar++;}
  17. %%
  18.  
  19. void main(int argc, char *argv[]){
  20. if(argc!=2){
  21. printf("Usage:\n\t./a.out <FILENAME>\n");
  22. exit(0);
  23. }
  24.  
  25. yyin=fopen(argv[1],"r");
  26. yylex();
  27.  
  28. printf("Word Count: %d\n",ctWord);
  29. printf("Character Count: %d\n",ctChar);
  30. printf("Space Count: %d\n",ctSpace);
  31. printf("Line Count: %d\n",ctLine);
  32. fclose(yyin);
  33.  
  34. }
  35.  
  36. int yywrap(){
  37. return 1;
  38. }
  39.  
Success #stdin #stdout #stderr 0.03s 7000KB
stdin
my name is barshan
stdout
Standard output is empty
stderr
ERROR: /home/rpCGLE/prog:2:5: Syntax error: Operator expected
ERROR: /home/rpCGLE/prog:38:1: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit