Скачиваний:
23
Добавлен:
02.05.2014
Размер:
34.28 Кб
Скачать
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Grids, DBGrids, ComCtrls, Buttons, ExtCtrls ;

type



TForm1 = class(TForm)
Label3: TLabel;
PageControl1: TPageControl;
TabSheet1: TTabSheet;
TabSheet2: TTabSheet;
TabSheet3: TTabSheet;
Bevel1: TBevel;
Label2: TLabel;
Button1: TButton;
Edit2: TEdit;
Button2: TButton;
GroupBox1: TGroupBox;
Label4: TLabel;
Label6: TLabel;
Label8: TLabel;
Label9: TLabel;
GroupBox2: TGroupBox;
Label10: TLabel;
Label12: TLabel;
Label14: TLabel;
Button5: TButton;
Label1: TLabel;
Memo1: TMemo;
OpenDialog1: TOpenDialog;
Button6: TButton;
Button3: TButton;
Memo2: TMemo;
Label11: TLabel;
Label13: TLabel;
StringGrid3: TStringGrid;
StringGrid1: TStringGrid;
StringGrid2: TStringGrid;
Label5: TLabel;
procedure Button1Click(Sender: TObject);
procedure vCreat(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button6Click(Sender: TObject);
procedure Button5Click(Sender: TObject);


public
procedure Shirina();
procedure TabID(str:string);
procedure Prosto(str:string);
end;


var
Form1: TForm1;
ukazatel,knop1,knop,vssrav,nomer,adres,raz,a1:integer;
srsrav,srsrav1,vssrav1:real;
tek_uz,koren:string;


implementation

uses Unit2;

{$R *.dfm}


procedure TForm1.Button1Click(Sender: TObject);
type
TAState = ( A_H, A_OR1, A_OR2, A_NO1,A_NO2,A_NO3,A_VA1,A_VA2,A_VA3,A_CH1,
A_DO1,A_DO2,A_WH1,A_WH2,A_WH3,A_WH4,A_WH5,A_BY1,A_BY2,A_BY3,A_BY4,A_KO1,A_KO2,
A_KO3,A_P1,A_P2,A_P3,A_P4,A_BE1,A_BE2,A_BE3,A_BE4,A_BE5,A_EL1,A_EL2,A_EL3,A_TH1,
A_TH2,A_TH3,A_TH4,A_IF1,A_IF2,A_AN1,A_AN2,A_AN3,A_TO,A_Z,A_C1,A_C2,A_SL,A_GA,
A_PR1,A_PR2,A_PR3,A_TZ,A_PL,A_GA2,A_PO,A_MI,A_E,A_ID,A_IR1,A_IR2,A_KO4, A_IR3,A_BY5,A_PR4,A_BI2,A_BI1,A_BI3);

var ind,pos,dl,i,j,i1,fl,zn:integer;
st,str,stroka,zzz:string;
sost:TAState;

begin
if OpenDialog1.execute then
Memo1.lines.loadFromFile(OpenDialog1.FileName) ;

for i:=0 to 2 do
for i1:=1 to 999 do
StringGrid3.Cells[i,i1]:='';

i1:=Memo1.Lines.Count;
ind:=1;
pos:=1;
for i:=1 to i1 do
begin
str:='';
stroka:=Memo1.Lines[i-1];
stroka:=stroka+' ';
dl:=Length(stroka);
sost:=A_H;
fl:=0;
zn:=0;
for j:=1 to dl do
begin
st:=stroka[j];
case sost of
A_H:
case stroka[j] of

';': begin sost:=A_TZ;str:=str+st; end;
'>': begin sost:=A_GA2;str:=str+st; end;
'<': begin sost:=A_GA; str:=str+st end;
'=': begin sost:=A_PO; str:=str+st end;
':': begin sost:=A_P1;str:=str+st; end;
'v': begin sost:=A_VA1;str:=str+st; end;
'n': begin sost:=A_NO1;str:=str+st; end;
'p': begin sost:=A_PR1;str:=str+st; end;
'e': begin sost:=A_KO1;str:=str+st; end;
'i': begin sost:=A_IF1;str:=str+st; end;
't': begin sost:=A_TH1;str:=str+st; end;
'o': begin sost:=A_OR1;str:=str+st; end;
'+': begin sost:=A_PL;str:=str+st; end;
'-': begin sost:=A_MI;str:=str+st; end;
'a': begin sost:=A_IR1;str:=str+st; end;
'{': begin sost:=A_C1;str:=str+st; end;
'}': begin sost:=A_C2;str:=str+st; end;
'*': begin sost:=A_Z;str:=str+st; end;
'/': begin sost:=A_SL;str:=str+st; end;
'd': begin sost:=A_DO1;str:=str+st; end;
'w': begin sost:=A_WH1;str:=str+st; end;
'b': begin sost:=A_BY1;str:=str+st; end;
'0','1': begin sost:=A_CH1;str:=str+st; end;
'c','f'..'h','m','q'..'s','u','x'..'z': begin sost:=A_ID;str:=str+st; end;
' ': begin sost:=A_H;str:=''; end;
else begin sost:=A_E;str:=str+st; end;
end;

A_TZ:
case stroka[j] of
' ':begin sost:=A_H;fl:=1;zn:=1; end;
else begin sost:=A_E;str:=str+st; end;
end;

A_GA2:
case stroka[j] of
' ':begin sost:=A_H;fl:=1;zn:=12; end;
else begin sost:=A_E;str:=str+st; end;
end;

A_GA:
case stroka[j] of
' ':begin sost:=A_H;fl:=1;zn:=13; end;
else begin sost:=A_E;str:=str+st; end;
end;

A_MI:
case stroka[j] of
' ':begin sost:=A_H;fl:=1;zn:=17; end;
else begin sost:=A_E;str:=str+st; end;
end;

A_PL:
case stroka[j] of
' ':begin sost:=A_H;fl:=1;zn:=17; end;
else begin sost:=A_E;str:=str+st; end;
end;


A_PO:
case stroka[j] of
' ':begin sost:=A_H;fl:=1;zn:=6; end;
else begin sost:=A_E;str:=str+st; end;
end;

A_Z:
case stroka[j] of
' ':begin sost:=A_H;fl:=1;zn:=15; end;
else begin sost:=A_E;str:=str+st; end;
end;

A_SL:
case stroka[j] of
' ':begin sost:=A_H;fl:=1;zn:=15;end;
else begin sost:=A_E;str:=str+st; end;
end;

A_CH1:
case stroka[j] of
' ':begin sost:=A_H;fl:=1;zn:=11; end;
'2'..'9' : begin sost:=A_ID; str:=str+st; end;
'0','1': begin sost:=A_CH1;str:=str+st; end;
else begin sost:=A_E;str:=str+st; end; end;

A_DO1:
case stroka[j] of
' ':begin sost:=A_H;fl:=1;zn:=5; end;
'a'..'n','p'..'z','0'..'9' : begin sost:=A_ID; str:=str+st; end;
'o': begin sost:=A_DO2;str:=str+st; end;
else begin sost:=A_E;str:=str+st; end;
end;

A_DO2:
case stroka[j] of
'a'..'z','0'..'9': begin sost:=A_ID;str:=str+st; end;
' ':begin sost:=A_H;fl:=1;zn:=10;end;
else begin sost:=A_E;str:=str+st; end;
end;

A_WH1:
case stroka[j] of
' ': begin sost:=A_H;fl:=1;zn:=5;end;
'h': begin sost:=A_WH2;str:=str+st;end;
'a'..'g','i'..'z','0'..'9':begin sost:=A_ID;str:=str+st; end;
else begin sost:=A_E; str:=str+st; end;
end;

A_WH2:
case stroka[j] of
' ': begin sost:=A_H;fl:=1;zn:=5;end;
'i': begin sost:=A_WH3;str:=str+st;end;
'a'..'h','j'..'z','0'..'9':begin sost:=A_ID;str:=str+st; end;
else begin sost:=A_E; str:=str+st; end;
end;
A_WH3:
case stroka[j] of
' ': begin sost:=A_H;fl:=1;zn:=5;end;
'l': begin sost:=A_WH4;str:=str+st;end;
'a'..'k','m'..'z','0'..'9':begin sost:=A_ID;str:=str+st; end;
else begin sost:=A_E; str:=str+st; end;
end;

A_WH4:
case stroka[j] of
' ': begin sost:=A_H;fl:=1;zn:=5;end;
'e': begin sost:=A_WH5;str:=str+st;end;
'a'..'d','f'..'z','0'..'9':begin sost:=A_ID;str:=str+st; end;
else begin sost:=A_E; str:=str+st; end;
end;

A_WH5:
case stroka[j] of
' ': begin sost:=A_H;fl:=1;zn:=10;end;
'a'..'z','0'..'9':begin sost:=A_ID;str:=str+st; end;
else begin sost:=A_E; str:=str+st; end;
end;



A_ID:
case stroka[j] of
' ': begin sost:=A_H;fl:=1;zn:=5;end;
'a'..'z','0'..'9':begin sost:=A_ID;str:=str+st; end;
else begin sost:=A_E; str:=str+st; end;
end;



A_BY1:
case stroka[j] of
' ': begin sost:=A_H;fl:=1;zn:=5;end;
'y' : begin sost:=A_BI1;str:=str+st;end;
'e': begin sost:=A_BY2;str:=str+st;end;
'a'..'d','f'..'x','z','0'..'9':begin sost:=A_ID;str:=str+st; end;
else begin sost:=A_E; str:=str+st; end;
end;

A_BY2:
case stroka[j] of
' ': begin sost:=A_H;fl:=1;zn:=5;end;
'g': begin sost:=A_BY3;str:=str+st;end;
'a'..'f','h'..'z','0'..'9':begin sost:=A_ID;str:=str+st; end;
else begin sost:=A_E; str:=str+st; end;
end;

A_BY3:
case stroka[j] of
' ': begin sost:=A_H;fl:=1;zn:=5;end;
'i': begin sost:=A_BY4;str:=str+st;end;
'a'..'h','j'..'z','0'..'9':begin sost:=A_ID;str:=str+st; end;
else begin sost:=A_E; str:=str+st; end;
end;

A_BY4:
case stroka[j] of
' ': begin sost:=A_H;fl:=1;zn:=5;end;
'n': begin sost:=A_BY5;str:=str+st;end;
'a'..'m','o'..'z','0'..'9':begin sost:=A_ID;str:=str+st; end;
else begin sost:=A_E; str:=str+st; end;
end;

A_BY5:
case stroka[j] of
' ': begin sost:=A_H;fl:=1;zn:=10;end;
'a'..'z','0'..'9':begin sost:=A_ID;str:=str+st; end;
else begin sost:=A_E; str:=str+st; end;
end;

A_BI1:
case stroka[j] of
' ': begin sost:=A_H;fl:=1;zn:=5;end;
't': begin sost:=A_BI2;str:=str+st;end;
'a'..'s','u'..'z','0'..'9':begin sost:=A_ID;str:=str+st; end;
else begin sost:=A_E; str:=str+st; end;
end;

A_BI2:
case stroka[j] of
' ': begin sost:=A_H;fl:=1;zn:=5;end;
'e': begin sost:=A_BI3;str:=str+st;end;
'a'..'d','f'..'z','0'..'9':begin sost:=A_ID;str:=str+st; end;
else begin sost:=A_E; str:=str+st; end;
end;

A_BI3:
case stroka[j] of
' ': begin sost:=A_H;fl:=1;zn:=14;end;
'a'..'z','0'..'9':begin sost:=A_ID;str:=str+st; end;
else begin sost:=A_E; str:=str+st; end;
end;

A_VA1:
case stroka[j] of
' ': begin sost:=A_H;fl:=1;zn:=5;end;
'a': begin sost:=A_VA2;str:=str+st;end;
'b'..'u','w'..'z','0'..'9':begin sost:=A_ID;str:=str+st; end;
else begin sost:=A_E; str:=str+st; end;
end;

A_VA2:
case stroka[j] of
' ': begin sost:=A_H;fl:=1;zn:=5;end;
'r': begin sost:=A_VA3;str:=str+st;end;
'a'..'q','s'..'z','0'..'9':begin sost:=A_ID;str:=str+st; end;
else begin sost:=A_E; str:=str+st; end;
end;

A_VA3:
case stroka[j] of
' ': begin sost:=A_H;fl:=1;zn:=10;end;
'a'..'z','0'..'9':begin sost:=A_ID;str:=str+st; end;
else begin sost:=A_E; str:=str+st; end;
end;

A_PR1:
case stroka[j] of
' ': begin sost:=A_H;fl:=1;zn:=5;end;
'r': begin sost:=A_PR2;str:=str+st;end;
'a'..'q','s'..'z','0'..'9':begin sost:=A_ID;str:=str+st; end;
else begin sost:=A_E; str:=str+st; end;
end;

A_PR2:
case stroka[j] of
' ': begin sost:=A_H;fl:=1;zn:=5;end;
'o': begin sost:=A_PR3; str:=str+st;end;
'a'..'n','p'..'z','0'..'9':begin sost:=A_ID;str:=str+st; end;
else begin sost:=A_E; str:=str+st; end;
end;

A_PR3:
case stroka[j] of
' ': begin sost:=A_H;fl:=1;zn:=5;end;
'g': begin sost:=A_PR4; str:=str+st;end;
'a'..'f','h'..'z','0'..'9':begin sost:=A_ID;str:=str+st; end;
else begin sost:=A_E; str:=str+st; end;
end;

A_PR4:
case stroka[j] of
' ': begin sost:=A_H;fl:=1;zn:=10;end;
'a'..'z','0'..'9':begin sost:=A_ID;str:=str+st; end;
else begin sost:=A_E; str:=str+st; end;
end;


A_IF1:
case stroka[j] of
' ': begin sost:=A_H;fl:=1;zn:=5;end;
'f': begin sost:=A_IF2;str:=str+st;end;
'a'..'e','g'..'z','0'..'9':begin sost:=A_ID;str:=str+st; end;
else begin sost:=A_E; str:=str+st; end;
end;

A_IF2:
case stroka[j] of
' ': begin sost:=A_H;fl:=1;zn:=10;end;
'a'..'z','0'..'9':begin sost:=A_ID;str:=str+st; end;
else begin sost:=A_E; str:=str+st; end;
end;

A_OR1:
case stroka[j] of
' ': begin sost:=A_H;fl:=1;zn:=5;end;
'r': begin sost:=A_OR2;str:=str+st;end;
'a'..'q','s'..'z','0'..'9':begin sost:=A_ID;str:=str+st; end;
else begin sost:=A_E; str:=str+st; end;
end;

A_OR2:
case stroka[j] of
' ': begin sost:=A_H;fl:=1;zn:=7;end;
'a'..'z','0'..'9':begin sost:=A_ID;str:=str+st; end;
else begin sost:=A_E; str:=str+st; end;
end;

A_P1:
case stroka[j] of
' ' :begin sost:=A_H;fl:=1;zn:=16; end;
'=':begin sost:=A_P2;str:=str+st;end;
else begin sost:=A_E;str:=str+st; end;
end;

A_P2:
case stroka[j] of
' ':begin sost:=A_H;fl:=1;zn:=4;end;
else begin sost:=A_E;str:=str+st; end;
end;

A_KO1:
case stroka[j] of
' ': begin sost:=A_H;fl:=1;zn:=5;end;
'n': begin sost:=A_KO2;str:=str+st;end;
'l': begin sost:=A_EL1;str:=str+st;end;
'a'..'k','m','o'..'z','0'..'9':begin sost:=A_ID;str:=str+st; end;
else begin sost:=A_E; str:=str+st; end;
end;

A_KO2:
case stroka[j] of
' ': begin sost:=A_H;fl:=1;zn:=5;end;
'd': begin sost:=A_KO3;str:=str+st;end;
'a'..'c','e'..'z','0'..'9':begin sost:=A_ID;str:=str+st; end;
else begin sost:=A_E; str:=str+st; end;
end;

A_KO3:
case stroka[j] of
' ': begin sost:=A_H;fl:=1;zn:=10;end;
'.': begin sost:=A_KO4;str:=str+st;end;
'a'..'z','0'..'9':begin sost:=A_ID;str:=str+st; end;
else begin sost:=A_E; str:=str+st; end;
end;

A_KO4:
case stroka[j] of
' ': begin sost:=A_H;fl:=1;zn:=10;end;
else begin sost:=A_E;str:=str+st; end;
end;

A_EL1:
case stroka[j] of
' ': begin sost:=A_H;fl:=1;zn:=5;end;
's': begin sost:=A_EL2;str:=str+st;end;
'a'..'r','t'..'z','0'..'9':begin sost:=A_ID;str:=str+st; end;
else begin sost:=A_E; str:=str+st; end;
end;

A_EL2:
case stroka[j] of
' ': begin sost:=A_H;fl:=1;zn:=5;end;
'e': begin sost:=A_EL3;str:=str+st;end;
'a'..'d','f'..'z','0'..'9':begin sost:=A_ID;str:=str+st; end;
else begin sost:=A_E; str:=str+st; end;
end;

A_EL3:
case stroka[j] of
' ': begin sost:=A_H;fl:=1;zn:=10;end;
'a'..'z','0'..'9':begin sost:=A_ID;str:=str+st; end;
else begin sost:=A_E; str:=str+st; end;
end;

A_IR1:
case stroka[j] of
' ': begin sost:=A_H;fl:=1;zn:=5;end;
'n': begin sost:=A_IR2;str:=str+st;end;
'a'..'m','o'..'z','0'..'9':begin sost:=A_ID;str:=str+st; end;
else begin sost:=A_E; str:=str+st; end;
end;

A_IR2:
case stroka[j] of
' ': begin sost:=A_H;fl:=1;zn:=5;end;
'd': begin sost:=A_IR3;str:=str+st;end;
'a'..'c','e'..'z','0'..'9':begin sost:=A_ID;str:=str+st; end;
else begin sost:=A_E; str:=str+st; end;
end;

A_IR3:
case stroka[j] of
' ': begin sost:=A_H;fl:=1;zn:=8;end;
'a'..'z','0'..'9':begin sost:=A_ID;str:=str+st; end;
else begin sost:=A_E; str:=str+st; end;
end;

A_NO1:
case stroka[j] of
' ': begin sost:=A_H;fl:=1;zn:=5;end;
'o': begin sost:=A_NO2;str:=str+st;end;
'a'..'n','p'..'z','0'..'9':begin sost:=A_ID;str:=str+st; end;
else begin sost:=A_E; str:=str+st; end;
end;

A_NO2:
case stroka[j] of
' ': begin sost:=A_H;fl:=1;zn:=5;end;
't': begin sost:=A_NO3;str:=str+st;end;
'a'..'s','u'..'z','0'..'9':begin sost:=A_ID;str:=str+st; end;
else begin sost:=A_E; str:=str+st; end;
end;
A_NO3:
case stroka[j] of
' ': begin sost:=A_H;fl:=1;zn:=9;end;
'a'..'z','0'..'9':begin sost:=A_ID;str:=str+st; end;
else begin sost:=A_E; str:=str+st; end;
end;

A_TH1:
case stroka[j] of
' ': begin sost:=A_H;fl:=1;zn:=5;end;
'h': begin sost:=A_TH2;str:=str+st;end;
'a'..'g','i'..'z','0'..'9':begin sost:=A_ID;str:=str+st; end;
else begin sost:=A_E; str:=str+st; end;
end;

A_TH2:
case stroka[j] of
' ': begin sost:=A_H;fl:=1;zn:=5;end;
'e': begin sost:=A_BY4;str:=str+st;end;
'a'..'d','f'..'z','0'..'9':begin sost:=A_ID;str:=str+st; end;
else begin sost:=A_E; str:=str+st; end;
end;

A_C1:
case stroka[j] of
' ':begin sost:=A_H;fl:=1;zn:=2;end;
else begin sost:=A_E;str:=str+st; end;
end;

A_C2:
case stroka[j] of
' ':begin sost:=A_H;fl:=1;zn:=3;end;
else begin sost:=A_E;str:=str+st; end;
end;



A_E: begin
if stroka[j]<>' 'then
begin
sost:=A_E;
str:=str+st;
end
else
begin
sost:=A_H;
Memo2.Lines.Append('Ошибочные символы -'+str);
str:='';
end;
end;
end;
if fl=1 then
begin

StringGrid3.Cells[0,ind]:=IntToStr(ind);
StringGrid3.Cells[1,ind]:=str;
if zn=5 then
begin
zzz:=str;
{TabID(str);}
str:=zzz;
{Prosto(str);}
end;
case zn of
1: StringGrid3.Cells[2,ind]:='Разделяюший знак ;';
2: StringGrid3.Cells[2,ind]:=' открывающиеся скобки';
3: StringGrid3.Cells[2,ind]:=' закрывающиеся скобки';
4: StringGrid3.Cells[2,ind]:='Знак присваивания';
5: StringGrid3.Cells[2,ind]:='Идентификатор';
6: StringGrid3.Cells[2,ind]:='Операвтор сравнения "равно"';
7: StringGrid3.Cells[2,ind]:='Логическое "или"';
8: StringGrid3.Cells[2,ind]:='Логическое "и"';
9: StringGrid3.Cells[2,ind]:='Логическое "не"';
10: StringGrid3.Cells[2,ind]:='Ключевое слово';
11: StringGrid3.Cells[2,ind]:='константа';
12: StringGrid3.Cells[2,ind]:='Операвтор сравнения "меньше" ';
13: StringGrid3.Cells[2,ind]:='Операвтор сравнения "больше"';
14: StringGrid3.Cells[2,ind]:='Тип данных Byte ';
15: StringGrid3.Cells[2,ind]:='Дополнительные операции /,* ';
16: StringGrid3.Cells[2,ind]:='Двоеточие';
17: StringGrid3.Cells[2,ind]:='Арифметические операции +,-';
end;
str:='';
ind:=ind+1;
fl:=0;
end;


end;
end;
// Shirina();

end;


procedure Tform1.Shirina();
var x, y, w: integer; s: string;
MaxWidth: integer;
begin
with StringGrid1 do
ClientHeight := DefaultRowHeight * RowCount + 5;
with StringGrid1 do
begin
for x := 0 to ColCount - 1 do
begin
MaxWidth := 0;
for y := 0 to RowCount - 1 do
begin
w := Canvas.TextWidth(Cells[x,y]);
if w > MaxWidth then
MaxWidth := w;
end;
ColWidths[x] := MaxWidth + 5;
end;
end;
end;

procedure TForm1.vCreat(Sender: TObject);
var a1,a2,i:integer;
begin

for a1:=0 to 3 do
for a2:=1 to 500 do
StringGrid2.Cells[a1,a2]:='';
for i:=1 to 500 do
begin
StringGrid1.Cells[0,i]:=IntToStr(i);
end;

StringGrid1.Cells[0,0]:='Номер';
StringGrid1.Cells[1,0]:='ХФ';
StringGrid1.Cells[2,0]:='Иден-р';

StringGrid2.Cells[0,0]:='Индекс';
StringGrid2.Cells[1,0]:='Знач.ид.';
StringGrid2.Cells[2,0]:='Лев.сс.';
StringGrid2.Cells[3,0]:='Пра.сс.';

StringGrid3.Cells[0,0]:='Номер';
StringGrid3.Cells[1,0]:='Лексема';
StringGrid3.Cells[2,0]:='Инфа';
nomer:=0;
ukazatel:=0;
srsrav:=0;
knop:=0;
vssrav:=0;
srsrav1:=0;
knop1:=0;
vssrav1:=0;
adres:=0;
raz:=0;
a1:=1;
end;
function Xesh(St:string):integer; {процедура вычисление значения хэш-функции}
var dlina:integer;
twosyb:char;
fivesyb:char;
begin
dlina:=length(St);
if dlina=0 then Result:=0 else
begin
if dlina>=4 then begin
twosyb:=St[2];
fivesyb:=St[5];
Result:=ord(fivesyb)+ord(twosyb);
end
else begin
twosyb:=St[2];
Result:=ord( twosyb);
end;

end;
end;

procedure TForm1.TabID(str:string); //заполн Рехеш
var i,k,dlina,hash,kol:integer;

label 1,2;
begin
k:=2;
kol:=0;
ukazatel:=0;
hash:=Xesh(str);

if StringGrid1.Cells[1,hash]=' ' then
begin
StringGrid1.Cells[1,hash]:=IntToStr(hash);
StringGrid1.Cells[2,hash]:=str;
inc(nomer);
end
else
begin
1: if (StringGrid1.Cells[2,hash])=str then
begin
inc(kol);
memo2.Lines.Add('Удален повтор '+str);
inc(ukazatel);
goto 2;
end
else
begin
inc(kol);
hash:=(Xesh(str)*k) mod 499;
if (StringGrid1.cells[1,hash])='' then
begin
StringGrid1.Cells[1,hash]:=IntToStr(hash);
StringGrid1.Cells[2,hash]:=str;
inc(nomer);
inc(k);

end
else
begin
inc(k);
goto 1;
end;
end;

2:

label5.Caption:='Кол-во коллизий '+IntToStr(kol);

end;

end;

procedure TForm1.Prosto(str:string); //Заполнение Бинарное дерево
Label M1,m2;
Var i3:integer;

begin
inc(raz);
if raz=1 then begin
StringGrid2.Cells[0,1]:='1';
StringGrid2.Cells[1,1]:=str;
adres:=1;
koren:=StringGrid2.Cells[1,adres];

goto M2;
end;


tek_uz:=koren;


if str=tek_uz then Begin memo2.Lines.Add('Удален повтор '+str); goto m2; end
else
M1:
if str<tek_uz then
if StringGrid2.Cells[2,a1]='' then
begin
inc(adres);
StringGrid2.Cells[0,adres]:=IntToStr(adres);
StringGrid2.Cells[2,a1]:=IntToStr(adres);
StringGrid2.Cells[1,adres]:=str;
end
else
begin
i3:=StrToInt(StringGrid2.Cells[2,a1]);
a1:=i3;
tek_uz:=StringGrid2.Cells[1,a1];
goto m1;
end
else
if StringGrid2.Cells[3,a1]='' then
begin
inc(adres);
StringGrid2.Cells[0,adres]:=IntToStr(adres);
StringGrid2.Cells[3,a1]:=IntToStr(adres);
StringGrid2.Cells[1,adres]:=str;
end
else
begin
i3:=StrToInt(StringGrid2.Cells[3,a1]);
a1:=i3;
tek_uz:=StringGrid2.Cells[1,a1];
goto M1;
end;

M2:
end;



procedure TForm1.Button3Click(Sender: TObject);
begin
close;
end;

procedure TForm1.Button2Click(Sender: TObject);
var k,hash,dlina,i,srav,j,si: integer;
stroka: string;

label met1,met2;
begin
stroka:=Edit2.Text;
if stroka='' then
begin
memo2.Lines.Add('Поле пусто!');
Abort;
end;

inc(knop);
k:=2;
srav:=0;
hash:=Xesh(stroka);
for i:=1 to 500 do
begin
inc(srav);
if StringGrid1.Cells[0,hash]=IntToStr(hash) then
begin
if stroka=StringGrid1.Cells[2,hash] then
begin
memo2.Lines.Add('Иден-р '+stroka+' найден! Его номер '+ IntToStr(hash));
goto met1;
end
else
begin
for j:=1 to 500 do
begin
inc(srav);
hash:=(Xesh(stroka)*k) mod 499;
inc(k);
if StringGrid1.Cells[1,hash]=IntToStr(hash) then
begin
if stroka=StringGrid1.Cells[2,hash] then
begin
memo2.Lines.Add('Иден-р '+stroka+' найден! Его номер '+ IntToStr(hash));
goto met1;
end;
end
// else memo2.Lines.Add('Иден-р '+stroka+' не найден!');
end;
end;
end
else begin
memo2.Lines.Add('Иден-р '+stroka+' не найден!');
abort; end;
end;
met1: Label4.Caption:='Номер '+inttostr(hash);
label6.Caption:='Кол-во сравнений '+inttostr(srav);
label9.Caption:='Кол-во поисков '+inttostr(knop);
dlina:=memo1.Lines.Count;

for si:=1 to dlina do
begin
k:=2;
srav:=0;
stroka:=memo1.Lines[si];
hash:=Xesh(stroka);
for i:=1 to 510 do
begin
srav:=srav+1;
if StringGrid2.Cells[1,hash]=IntToStr(hash) then
begin
if stroka=StringGrid2.Cells[2,hash] then
begin
goto met2;
end
else
begin
for j:=1 to 510 do
begin
srav:=srav+1;
hash:=(Xesh(stroka)*k) mod 509;
k:=k+1;
if StringGrid2.Cells[1,hash]=IntToStr(hash) then
begin
if stroka=StringGrid2.Cells[2,hash] then
begin
goto met2;
end;
end;
end;
end;
end
else begin
goto met2; end;
end;
met2: vssrav:=vssrav+srav;
end;
srsrav:=vssrav/dlina;
Label8.Caption:='Среднее кол-во сравнений '+floattostr(srsrav);
vssrav:=0;
srsrav:=0;

end;




procedure TForm1.Button6Click(Sender: TObject); //сброс
var
i,j:integer;
begin
for j:=0 to 2 do begin
for i:=0 to 500 do begin
StringGrid1.Cells[j,i]:=' ';
StringGrid3.Cells[j,i]:=' '; end; end;
for i:=0 to 3 do begin
for j:=0 to 500 do begin
StringGrid2.Cells[i,j]:=' ';
end; end;
memo1.Clear;
memo2.Clear;
Edit2.Clear;
nomer:=0;
nomer:=0;
ukazatel:=0;
srsrav:=0;
knop:=0;
vssrav:=0;
srsrav1:=0;
knop1:=0;
vssrav1:=0;
adres:=0;
raz:=0;
a1:=1;
tek_uz:='';
koren:='' ;
label10.Caption:='Номер ' ;
label14.Caption:='Кол-во сравнений ';
label12.Caption:='Кол-во поисков ';
label11.Caption:='Среднее кол-во сравнений ';
Label4.Caption:='Номер ' ;
Label5.Caption:='Кол-во коллизий ' ;
Label6.Caption:='Кол-во сравнений ';
label8.Caption:='Среднее кол-во сравнений ';
label9.Caption:='Кол-во поисков ' ;


end;

procedure TForm1.Button5Click(Sender: TObject);
Label M1,M2,M3;
Var str,tek_uz:string;
i,i1,a1,a2,fl:integer;
begin
str:=Edit2.Text;
if str<>' ' then begin memo2.Lines.Add('Поле поиска пусто'); Abort; end;
i1:=Memo1.Lines.Count;
inc(knop1);
a1:=1;
a2:=0;
fl:=0;
if Str<>'' then
begin
tek_uz:=StringGrid2.Cells[1,1];
M2:
if str=StringGrid2.Cells[1,a1] then
begin a2:=a2+1;fl:=1;goto M1;end
else
begin
a2:=a2+1;
if str<StringGrid2.Cells[1,a1]then
if StringGrid2.Cells[2,a1]='' then goto M1
else
begin
i:=StrToInt(StringGrid2.Cells[2,a1]);
a1:=i;
goto M2;
end
else
if StringGrid2.Cells[3,a1]='' then goto M1
else
begin
i:=StrToInt(StringGrid2.Cells[3,a1]);
a1:=i;
goto M2;
end;
end;
end;
M1:

if fl=1 then begin memo2.lines.add('Элемент ' +str+' найден.'); end
else begin memo2.lines.add('Элемент не найден.'); end;
Label11.Caption:='Среднее число сравнений = '+FloatToStr(a2/i1);
Label14.Caption:='Сравнений = '+IntToStr(a2);
Label12.Caption:='Колл-во поисков '+IntToStr(knop1);

end;

end.
Соседние файлы в папке курс_Андрюха