home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / pascal / compcomp / tpyacc / lengs.l < prev    next >
Text File  |  1991-04-30  |  612b  |  34 lines

  1.  
  2. %{
  3.  
  4. (* This is a Lex demonstration program taken from the UNIX manual which
  5.    which counts words in a file.
  6.    Usage: lengs <input-file
  7.    This will produce a histogram of word lengths in the input file.
  8.    To compile: lex lengs
  9.                tpc lengs *)
  10.  
  11. uses LexLib;
  12.  
  13. var lengs : array [1..100] of Integer;
  14.  
  15. %}
  16.  
  17. %%
  18.  
  19. [a-zA-Z]+    inc(lengs[yyleng]);
  20. .        |
  21. \n        ;
  22.  
  23. %%
  24.  
  25. var i : Integer;
  26.  
  27. begin
  28.   for i := 1 to 100 do lengs[i] := 0;
  29.   if yylex=0 then ;
  30.   writeln('Length':6, ' ':3, 'No. words':6);
  31.   for i := 1 to 100 do if lengs[i]>0 then
  32.     writeln(i:6, ' ':3, lengs[i]:6);
  33. end.
  34.