fork download
  1. !sudo apt instal flex bison
  2. %{
  3. #include<stdio.h>
  4. int sc=0,lc=0,tc=0,wc=0,ch=0;
  5. }%
  6. %%
  7. [\n]{lc++;ch+=yyleng()}
  8. [ \t]{sc++;ch+=yyleng()}
  9. [ ^\t]{tc++;ch+=yyleng()}
  10. [^\t\n]{wc++;ch+=yyleng()}
  11. %%
  12. int yywrap(){
  13. return 1;
  14. }
  15. int main(){
  16. printf("Enter the sentence: ");
  17. yylex();
  18. printf("\nno. of words in given sentence :%d",wc);
  19. printf("\nno. of spaces in given sentence :%d",sc);
  20. printf("\nno. of tabs in given sentence :%d",tc);
  21. printf("\nno. of lines in given sentence :%d",lc);
  22. printf("\nno. of char in given sentence :%d",ch);
  23. }
Success #stdin #stdout #stderr 0.03s 6900KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/xu0zZp/prog:23:0: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit