home *** CD-ROM | disk | FTP | other *** search
-
- { Counts word lengths in a file (normally, input is taken from the
- console; use input redirection to input a file), and prints out
- a histogram of word lengths.
- This is a Turbo Pascal Lex version of a UNIX Lex program, discussed in
- the (SUN) UNIX Lex manual, section 7.8. }
-
- uses LexLib;
- var lengs : array [1..100] of integer;
- %%
- [a-zA-Z]+ inc(lengs[yyleng]);
- . |
- \n ;
- %%
- var i : integer;
- begin
- for i := 1 to 100 do
- lengs[i] := 0;
- if yylex=0 then
- begin
- writeln('Length No. words');
- for i := 1 to 100 do
- if lengs[i]>0 then
- writeln(i, ' ', lengs[i]);
- end
- end.