/* * word count, WC - the program. simple standalone PCLEX application. */ %{#include static unsigned nchar = 0; /* # of characters in file */ static unsigned nword = 0; /* # of words in file */ static unsigned nline = 1; /* # of lines in file */%} %% \n {nchar += 2, ++nline;printf("%d:",nchar);} /* line boundary in MS-DOS is CR LF */ [^ \t\n]+ {++nword, nchar += yyleng;printf("%d:",nchar);}. {++nchar;printf("%d:",nchar);} %% main(int argc, char *argv[]) { if(argc > 1) yyin = fopen(argv[1], "r"); else yyin = stdin; yylex(); printf( "%d\t%d\t%d\n", nchar, nword, nline ); exit(0);}