digram.l

来自「Compiler generator toolset for Turbo/Bor」· L 代码 · 共 36 行

L
36
字号

%{

(* Lex demonstration program for the use of the REJECT routine, taken from
   the UNIX manual. This program produces a digram table of the input file
   (counts all pairs of lowercase letters).
   Usage: digram <input-file
   To compile: lex digram
               tpc digram *)

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.

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?