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

Popular posts from this blog

KTU Compiler Lab CSL411 - Dr Binu V P

lexical analyzer for a c program

13.Precedence and conflict resolution in yacc