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