home *** CD-ROM | disk | FTP | other *** search
-
- { 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.