Monday 22 August 2011

LEX:PROGRAM TO COUNT THE NUMBER OF LINES IN THE GIVEN INPUT

,
  PROGRAM TO COUNT THE NUMBER OF LINES IN THE GIVEN INPUT
 Algorithm:-
         begin
         num_lines=0
         num_chars=0
         if new line
         then num_lines++
         end
PROGRAM:
 LEX program to count the number of lines in a given input
 %{
int num_lines=0;
%}
%%
\n    ++num_lines;
%%
main()
{
yylex();
printf(“no of lines=%d”,num_lines);
}
int yywrap()
{
return num_lines;
}
 Output:
 $./a.out
abcd
1234
^d
No.of lines=2

0 comments to “LEX:PROGRAM TO COUNT THE NUMBER OF LINES IN THE GIVEN INPUT”

Post a Comment