Program:
// lwc.l
%{
int lines=0,wrds=0,characters=0;
%}
whitespace [ \n\t]*
%%
[ \t]{whitespace} {wrds++;characters++;}
\n{whitespace} {wrds++;characters++;lines++;}
. {characters++;}
%%
main()
{
yylex();
printf("\nlines: %d\nwords: %d\ncharacters: %d\n",lines,wrds,characters);
}
Output:
// lwc.l
%{
int lines=0,wrds=0,characters=0;
%}
whitespace [ \n\t]*
%%
[ \t]{whitespace} {wrds++;characters++;}
\n{whitespace} {wrds++;characters++;lines++;}
. {characters++;}
%%
main()
{
yylex();
printf("\nlines: %d\nwords: %d\ncharacters: %d\n",lines,wrds,characters);
}
0 comments:
Post a Comment