lex program to count number of lines , words and characters
lex program to count number of lines, words and characters
*******************************************
%{
int num_lines=0,num_words=0,num_chars=0;
%}
%option noyywrap
%%
\n ++num_lines; ++num_chars;++num_words;
" " ++num_words;++num_chars;
. ++num_chars;
%%
main()
{
yylex();
printf( "No of lines = %d, No of words=%d,No of chars = %d\n",num_lines,num_words, num_chars);
}
Comments
Post a Comment