fork download
  1. %{
  2. #include<stdio.h>
  3. int lines=0, words=0, sl=0, cl=0, num=0, spl_chr=0, tot=0, in_word=0;
  4. %}
  5.  
  6. %%
  7. \n { lines++; in_word = 0; }
  8. [ \t]+ { in_word = 0; }
  9. [a-z] { sl++; if (!in_word) { words++; in_word = 1; } }
  10. [A-Z] { cl++; if (!in_word) { words++; in_word = 1; } }
  11. [0-9] { num++; if (!in_word) { words++; in_word = 1; } }
  12. . { spl_chr++; if (!in_word) { words++; in_word = 1; } }
  13. <<EOF>> { return 0; }
  14. %%
  15.  
  16. main()
  17. {
  18. yyin = fopen("ex.txt", "r");
  19. yylex();
  20. tot = sl + cl + num + spl_chr;
  21. printf("total no. of symbols : %d\n", tot);
  22. printf("no. of Lines: %d\n", lines);
  23. printf("no. of words: %d\n", words);
  24. printf("no. of lower case letters: %d\n", sl);
  25. printf("no. of upper case letters: %d\n", cl);
  26. printf("no. of special characters: %d\n", spl_chr);
  27. printf("no. of digits: %d\n", num);
  28. }
  29.  
  30. int yywrap()
  31. {
  32. return 1;
  33. }
Success #stdin #stdout #stderr 0.02s 6808KB
stdin
Hello World! 123
Testing.
stdout
Standard output is empty
stderr
ERROR: /home/J1yE6E/prog:2:1: Syntax error: Operator expected
ERROR: /home/J1yE6E/prog:33:0: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? ERROR: Unknown option (h for help)
   Exception: (3) program ? EOF: exit