home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Simtel MSDOS 1992 June
/
SIMTEL_0692.cdr
/
msdos
/
txtutl
/
lex_yacc.arc
/
DIGRAM.L
< prev
next >
Wrap
Text File
|
1989-05-28
|
901b
|
27 lines
{ This is a sample Lex program that produces a digram table of
the input file (counts all pairs of lowercase letters). The input
file normally is standard input (console); use input redirection
to print the digram for a file.
This program shows the use of REJECT to reprocess matched patterns
when patterns to be detected may overlap or include each other.
This is a Turbo Pascal Lex version of a UNIX Lex program discussed
in the (SUN) UNIX Lex manual, section 7.4. }
uses LexLib;
var digram : array ['a'..'z','a'..'z'] of integer;
%%
[a-z][a-z] begin inc(digram[yytext[1],yytext[2]]); reject end;
. |
\n ;
%%
var c,d : char;
begin
for c := 'a' to 'z' do for d := 'a' to 'z' do
digram[c,d] := 0;
if yylex=0 then
for c := 'a' to 'z' do for d := 'a' to 'z' do
if digram[c,d]<>0 then
writeln(c,d,': ',digram[c,d])
end.