uses crt;
const ks: array [1..39] of string=('program','uses','const','var','label','type','begin','end',
'and','or','not','div','mod','if','then','else','case','of',
'byte','integer','real','char','string','array','record','file','set',
'for','to','do','downto','goto','in','nil','repeat','until','while',
'function','procedure');
r: set of char=[' ',':',';',','];
function CutName (str: string; q: byte): string;
var sss: string;
begin
sss:='';
while (q>=1) and (str[q] in ['a'..'z','0'..'9']) do
begin
sss:=str[q]+sss;
dec(q);
end;
CutName:=sss;
end;
function CutNameF (str: string; q: byte): string;
var sss: string;
begin
sss:='';
while (q<=length(str)) and (str[q] in ['a'..'z','0'..'9']) do
begin
sss:=sss+str[q];
inc(q);
end;
CutNameF:=sss;
end;
var f: text;
k: array [1..39] of integer;
s,sl,nm,lb: string;
i,j: byte;
c: char;
begin
assign(f,'D:\in.pas');
reset(f); nm:=''; sl:=''; lb:=''; j:=0;
while not (eof(f)) do
begin
readln(f,s);
s:=' '+s+' ';
if pos('label',s)<>0 then
begin
sl:=copy(s,pos('label',s)+5,pos(';',s)-pos('label',s)+5);
for c:='a' to 'z' do
for j:=2 to length(s) do
if (sl[j]=c) and (sl[j-1] in r) then lb:=lb+CutNameF (sl,j)+' ';
sl:='';
end;
for i:=2 to length(s) do
if copy(s,i,2)=':=' then nm:=nm+CutName (s,i-1)+', ';
for i:=1 to length(s) do
if not (s[i] in r) then sl:=sl+s[i] else
if length(sl)>0 then
begin
for j:=1 to 39 do
if sl=ks[j] then inc(k[j]);
sl:='';
end;
end;
close(f);
clrscr;
writeln('Ключевые слова:');
j:=0;
for i:=1 to 39 do
if k[i]<>0 then
begin
inc(j);
writeln(ks[i]:10,'- ',k[i]);
if i mod 19=0 then
begin
writeln('Enter to continue...');
readln();
clrscr;
writeln('Ключевые слова:');
end;
end;
writeln('Enter to continue...');
readln();
clrscr;
writeln('Перечень простых переменных: ',nm);
writeln('Перечень меток в алфавитном порядке: ',lb);
readln;
end.