fork download
  1. %{
  2. #include<stdio.h>
  3. int lc=0, sc=0, wc=0, cc=0;
  4. %}
  5.  
  6. %%
  7. [\n] {lc++; cc+=yyleng;}
  8. [ \t] {sc++; cc+=yyleng;}
  9. [^\t\n ]+ {wc++; cc+=yyleng;}
  10. %%
  11.  
  12. int main()
  13. {
  14. printf("Enter the input:\n");
  15. yylex();
  16. printf("No. of words are: %d\n", wc);
  17. printf("No. of characters are: %d\n", cc);
  18. printf("No. of new lines are: %d\n", lc);
  19. printf("No. of spacess are: %d\n", sc);
  20. }
  21. int yywrap()
  22. {
  23. return 1;
  24. }x([X | T], [X | R]) :- lex(T, R).
  25.  
Success #stdin #stdout #stderr 0.03s 6968KB
stdin
Avilash Roy
CSE
3B
stdout
Standard output is empty
stderr
ERROR: /home/JwgNjo/prog:2:1: Syntax error: Operator expected
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ?    Exception: (3) program ?    Exception: (3) [user] program ? EOF: exit