%{ /* This program will count the number of word, punctuation, and * new lines in a input file. */ /* Variables to keep track of items found. */ int nwords = 0; int npuncs = 0; int nlines = 0; %} /* Rules for determining the tokens. */ word [a-zA-Z]+[ ] punc [\.\,\!\?\:\;] eol \n %% {word}+ {++nwords;} {punc}+ {++npuncs;} {eol}+ {++nlines;} %% main() { yylex(); printf("\n"); printf("%s%d\n","The numbers of punctuations in file = ",npuncs); printf("%s%d\n","The numbers of words in file = ",nwords); printf("%s%d\n","The numbers of line in file = ",nlines); } yywrap(){}