fork download
%{
 #include<stdio.h>
 int nl = 0;
 int nw = 0;
 int nc = 0;
%}

%%
\n nl++;
[a-zA-Z]+ {nw++,nc+=yyleng;}
[^]nc++;
%%

int main(){
  printf("Enter the string:\n");
  yylex();
  
  printf("No. of lines is %d,words is %d and characters is %d",nl,nw,nc);
  return 0;
}
Success #stdin #stdout #stderr 0.03s 7020KB
stdin
I am sagar
who are you
stdout
Standard output is empty
stderr
ERROR: /home/3YmdOw/prog:19:0: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit