fork download
  1. %{
  2. #include<stdio.h>
  3. int lc = 0, sc = 0, tc = 0, ch = 0, wc = 0;
  4. %}
  5.  
  6. // Rules to identify if a character apart from alphabets
  7. // occurs in a string
  8.  
  9. %%
  10. [\n] {lc++; ch += yyleng;}
  11. [ \t] {sc++; ch += yyleng;}
  12. [^\t] {tc++; ch += yyleng;}
  13. [^\t\n]+ {wc++; ch += yyleng;}
  14. %%
  15.  
  16. // code section
  17. int yywrap() {return 1;}
  18.  
  19. int main()
  20. {
  21. printf("Enter the Sentence: ");
  22. yylex();
  23. printf("Number of Lines: %d\n", lc);
  24. printf("Number of Spaces: %d\n", sc);
  25. printf("Number of Tabs: %d\n", wc);
  26.  
  27. return 0;
  28. }
Success #stdin #stdout #stderr 0.02s 6940KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/21xK3T/prog:28:1: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit