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

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Buttons, Grids, ComCtrls, ExtCtrls;
type
TAutoState = ( AUTO_H, AUTO_ZZ, AUTO_OO, AUTO_Q, AUTO_R, AUTO_E, AUTO_Q1, AUTO_RAV, AUTO_IF, AUTO_IF1, AUTO_I, AUTO_EL, AUTO_EL1, AUTO_EL2, AUTO_EL3, AUTO_T, AUTO_T1, AUTO_T2, AUTO_T3,AUTO_CH );
TForm1 = class(TForm)
PageControl1: TPageControl;
OpenDialog1: TOpenDialog;
TabSheet1: TTabSheet;
TabSheet2: TTabSheet;
GroupBox1: TGroupBox;
Label2: TLabel;
Label4: TLabel;
Label8: TLabel;
Label9: TLabel;
StringGrid1: TStringGrid;
StringGrid3: TStringGrid;
BitBtn5: TBitBtn;
Edit4: TEdit;
Edit5: TEdit;
GroupBox2: TGroupBox;
Label5: TLabel;
BitBtn1: TBitBtn;
GroupBox3: TGroupBox;
Label10: TLabel;
Label12: TLabel;
Label11: TLabel;
Edit1: TEdit;
BitBtn3: TBitBtn;
Edit7: TEdit;
BitBtn4: TBitBtn;
Edit6: TEdit;
Button1: TButton;
GroupBox4: TGroupBox;
Label3: TLabel;
Label7: TLabel;
StringGrid2: TStringGrid;
BitBtn2: TBitBtn;
Edit3: TEdit;
Memo1: TMemo;
Label1: TLabel;
Label6: TLabel;
TreeView1: TTreeView;
TabSheet3: TTabSheet;
Button2: TButton;
Button3: TButton;
Label13: TLabel;
Label14: TLabel;
Label15: TLabel;
Edit8: TEdit;
Memo2: TMemo;
TabSheet4: TTabSheet;
TabSheet5: TTabSheet;
Memo3: TMemo;
Button4: TButton;
StringGrid4: TStringGrid;
Label16: TLabel;
Label17: TLabel;
procedure BitBtn1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure BitBtn2Click(Sender: TObject);
procedure BitBtn5Click(Sender: TObject);
procedure BitBtn3Click(Sender: TObject);
procedure BitBtn4Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);

private
{ Private declarations }
public
{ Public declarations }
end;
t_i = Record
znach:array [0..15] of char;
lev,prav,i:integer;
end;
var
Form1: TForm1;
in_f,out_f:text;
one,two:Char;
h_f,max,kolliz,sravn,bad_sravn:integer;
M:array[1..200] of integer; start:TtreeNode; z: integer;
function poisk(i: integer): integer;
procedure dbu(n0: TtreeNode; i: integer);

implementation
{$R *.DFM}

procedure TForm1.BitBtn1Click(Sender: TObject);
var
i:integer;
begin
if OpenDialog1.Execute then memo1.Lines.LoadFromFile(OpenDialog1.FileName);
Edit1.Text:='';
Edit3.Text:='';
Edit4.Text:='';
Edit5.Text:='';
Edit6.Text:='';
Edit7.Text:='';
for i:=1 to 101 do begin
StringGrid3.cells[0,i]:='';
StringGrid3.cells[1,i]:='';
StringGrid3.cells[2,i]:='';
end;
for i:=1 to 255 do begin
StringGrid1.cells[0,i]:=inttostr(i);
StringGrid1.cells[1,i]:='';
end;
for i:=1 to 101 do begin
StringGrid2.cells[0,i]:='';
StringGrid2.cells[1,i]:='';
StringGrid2.cells[2,i]:='';
StringGrid2.cells[3,i]:=''
end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
Memo1.Text:='';
Memo2.Text:='';
Memo3.Text:='';
StringGrid1.Cells[0,0]:='ХФ';
StringGrid1.Cells[1,0]:='Адр.в ТИ';
StringGrid2.Cells[1,0]:='Значение ид.';
StringGrid2.Cells[0,0]:='Адрес';
StringGrid2.Cells[2,0]:='Налево';
StringGrid2.Cells[3,0]:='Направо';
StringGrid3.Cells[0,0]:='Адрес';
StringGrid3.Cells[1,0]:='Значение ид.';
StringGrid3.Cells[2,0]:='Ссылка';
StringGrid4.Cells[0,0]:='№';
StringGrid4.Cells[1,0]:='Лексема';
StringGrid4.Cells[2,0]:='Описание';
StringGrid1.RowCount:=254;
StringGrid2.RowCount:=101;
StringGrid3.RowCount:=101;
Edit1.Text:='';
Edit3.Text:='';
Edit4.Text:='';
Edit5.Text:='';
Edit6.Text:='';
Edit7.Text:='';
Edit8.Text:='';
end;

procedure TForm1.BitBtn2Click(Sender: TObject);
label Metka;
var
i,k,pointer,j,jump,bad_sravn:integer; t: string; n0:TtreeNode;
dob_id:string;

begin

for i:=1 to 101 do begin
StringGrid2.cells[0,i]:='';
StringGrid2.cells[1,i]:='';
StringGrid2.cells[2,i]:='';
StringGrid2.cells[3,i]:=''
end;
sravn:=0;
jump:=0;
For i:=1 to Memo1.Lines.Count do
Begin
bad_sravn:=0;
dob_id:=memo1.Lines.Strings[i-1];
j:=i-jump;
pointer:=1;
if stringGrid2.Cells[1,pointer]='' then begin
stringGrid2.Cells[0,pointer]:=IntToStr(pointer);
stringGrid2.Cells[1,pointer]:=dob_id;
end
else begin

Metka: if dob_id<>StringGrid2.Cells[1,pointer] then begin
inc(sravn); inc(bad_sravn);
if dob_id>StringGrid2.Cells[1,pointer] then {добавляемый идентификатор находится правее анализируемого}
if StringGrid2.Cells[3,pointer]='' then begin{Правая ссылочная область пуста}

StringGrid2.Cells[3,pointer]:=InttoStr(j);
StringGrid2.Cells[0,j]:=InttoStr(j);
StringGrid2.Cells[1,j]:=dob_id
end
else begin{Правая ссылочная область занята}
val(StringGrid2.Cells[3,pointer],pointer,k);{переходим по ссылке}
goto Metka
end
else {ДИд находится левее старого}
if StringGrid2.Cells[2,pointer]='' then begin {левая ссылочная область пуста}
StringGrid2.Cells[2,pointer]:=InttoStr(j);
StringGrid2.Cells[0,j]:=InttoStr(j);
StringGrid2.Cells[1,j]:=dob_id
end
else{левая ссылочная область занята}
begin
val(StringGrid2.Cells[2,pointer],pointer,k);
goto Metka
end
end
else begin
inc(jump);
sravn:=sravn-bad_sravn
end
end;
End;

Edit3.Text:=InttoStr(sravn);

t:=StringGrid2.Cells[1,1];
n0:=treeView1.Items.Add(nil,t);
start:=n0;
z:=0; {m[z]:=1;}
for i:=1 to StringGrid2.RowCount-1 do
if poisk(i)=0 then dbu(n0,i);


end;

procedure dbu(n0: TtreeNode;i:integer);
var
j: integer; sl,sp: string; nl,np: TTreeNode;
Begin
nl:=n0; np:=n0;
if Form1.stringgrid2.cells[3,i]<>'' then begin
sp:=Form1.stringgrid2.cells[3,i];
j:=StrToInt(sp);
np:=Form1.treeView1.Items.addchild(n0,Form1.stringgrid2.cells[1,j]);
z:=z+1;
m[z]:=j;
dbu(np,j);
end else if (n0<>start) or (i=1) then np:=Form1.treeView1.Items.addchild(n0,' ');
if Form1.StringGrid2.cells[2,i]<>'' then begin
sl:=Form1.stringgrid2.cells[2,i];
j:=StrToInt(sl);
nl:=Form1.treeView1.Items.addchild(n0,Form1.stringgrid2.cells[1,j]);
z:=z+1;
m[z]:=j;
dbu(nl,j);
end else if (n0<>start) or (i=1) then nl:=Form1.treeView1.Items.addchild(n0,' ');
end;

function poisk(i: integer): integer;
var j: integer;
Begin
result:=0;
for j:=1 to 200 do
if i=m[j] then result:=1;
end;


procedure TForm1.BitBtn5Click(Sender: TObject);
label Metka;
var
i,k,pointer,link:integer;
dob_id:string;

begin

for i:=1 to 101 do begin
StringGrid3.cells[0,i]:='';
StringGrid3.cells[1,i]:='';
StringGrid3.cells[2,i]:='';
end;
for i:=1 to 255 do begin
StringGrid1.cells[0,i]:='';
StringGrid1.cells[1,i]:='';
end;
pointer:=1;
kolliz:=0;
sravn:=0;
For i:=0 to Memo1.Lines.Count-1 do
Begin
dob_id:=memo1.Lines.Strings[i];
one:=Upcase(dob_id[1]);
if length(dob_id)<2 then two:=' '
else two:=Upcase(dob_id[2]);
h_f:=ord(one)+ord(two); {получение хэш-функции}
bad_sravn:=0;
if stringGrid1.Cells[0,h_f]='' then begin
inc(sravn);
stringGrid1.Cells[0,h_f]:=IntToStr(h_f);
stringGrid1.Cells[1,h_f]:=IntToStr(pointer);
stringGrid3.Cells[0,pointer]:=IntToStr(pointer);
stringGrid3.Cells[1,pointer]:=dob_id;
end
else begin
inc(kolliz);
val(StringGrid1.Cells[1,h_f],Link,k);{переходим по ссылке}
Metka: inc(sravn); inc(bad_sravn);
if StringGrid3.Cells[1,Link]<>dob_id then
if StringGrid3.Cells[2,Link]='' then begin{ссылочная область пуста}
StringGrid3.Cells[2,Link]:=InttoStr(Pointer);
StringGrid3.Cells[0,Pointer]:=InttoStr(Pointer);
StringGrid3.Cells[1,Pointer]:=dob_id
end
else begin{ссылочная область занята}
val(StringGrid3.Cells[2,Link],Link,k);{переходим по ссылке}
goto Metka
end
else begin
sravn:=sravn-bad_sravn;
dec(kolliz);
dec(pointer);
end
end;
inc(pointer);
End;
Edit4.Text:=InttoStr(kolliz);
Edit5.Text:=InttoStr(sravn);
for i:=1 to 255 do begin
StringGrid1.cells[0,i]:=inttostr(i);

end;
end;




procedure TForm1.BitBtn3Click(Sender: TObject);
label Metka;
var
k,link:integer;
isk_id:string;

begin
sravn:=0;
Edit7.Text:='';
isk_id:=edit1.Text;
if length(isk_id)=0 then begin
ShowMessage('Введите строку для поиска!');
Exit
end;

one:=Upcase(isk_id[1]);
if length(isk_id)<2 then two:=' '
else two:=Upcase(isk_id[2]);
h_f:=ord(one)+ord(two); {получение хэш-функции}
if StringGrid1.Cells[1,h_f]='' then begin
ShowMessage('Элемент не найден!');
Exit
end
else begin
sravn:=1;
val(StringGrid1.Cells[1,h_f],Link,k);
Metka: if isk_id=StringGrid3.Cells[1,Link] then ShowMessage('Идентификатор ' + isk_id + ' находится по адресу '+InttoStr(Link))
else begin
if StringGrid3.Cells[2,Link]='' then begin
ShowMessage('Элемент не найден!');
Exit
end
else begin
inc(sravn);
val(StringGrid3.Cells[2,link],Link,k);
goto Metka;
end;
end;
end;
Edit7.Text:=InttoStr(sravn);
end;






procedure TForm1.BitBtn4Click(Sender: TObject);
label Metka;
var
k,pointer:integer;
isk_id:string;

begin
sravn:=0;
Edit6.Text:='';
isk_id:=edit1.Text;
if length(isk_id)=0 then begin
ShowMessage('Введите строку для поиска!');
Exit
end;
pointer:=1;
inc(sravn);
if stringGrid2.Cells[1,pointer]=isk_id then ShowMessage('Идентификатор ' + isk_id + ' находится по адресу '+InttoStr(pointer))
else begin

Metka: if isk_id<>StringGrid2.Cells[1,pointer] then begin
inc(sravn);
if isk_id>StringGrid2.Cells[1,pointer] then {искомый идентификатор находится правее анализируемого}
if StringGrid2.Cells[3,pointer]='' then begin{Правая ссылочная область пуста}
ShowMessage('Элемент не найден!');
Exit
end
else begin{Правая ссылочная область занята}
val(StringGrid2.Cells[3,pointer],pointer,k);{переходим по ссылке}
goto Metka
end
else {Иск_Ид находится левее старого}
if StringGrid2.Cells[2,pointer]='' then begin {левая ссылочная область пуста}
ShowMessage('Элемент не найден!');
Exit
end
else{левая ссылочная область занята}
begin
val(StringGrid2.Cells[2,pointer],pointer,k);
goto Metka
end
end
else ShowMessage('Идентификатор ' + isk_id + ' находится по адресу '+InttoStr(pointer))
end;

Edit6.Text:=InttoStr(sravn);
end;


procedure TForm1.Button1Click(Sender: TObject);
begin
Edit1.Text:='';
Edit6.Text:='';
Edit7.Text:='';
end;
{**************Vtoraia chast*************}

procedure TForm1.Button3Click(Sender: TObject);
Var str:string;
begin
str:=Edit8.Text;
if Edit8.Text<>'' then Memo2.Lines.LoadFromFile(str)
else ShowMessage('Введите название файла!');
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
if OpenDialog1.Execute then Memo2.Lines.LoadFromFile(OpenDialog1.FileName) ;
end;

procedure TForm1.Button4Click(Sender: TObject);
var
ind,dl,i,j,i1,fl,zn:integer;
st,str,stroka:string;
sost:TAutoState;
begin
Memo3.Text:='';
for i:=0 to 2 do
for i1:=1 to 999 do
StringGrid4.Cells[i,i1]:='';
i1:=Memo2.Lines.Count;
ind:=1; {1}
for i:=1 to i1 do
begin
str:='';
stroka:=Memo2.Lines[i-1];
stroka:=stroka+' ';
dl:=Length(stroka);
sost:=AUTO_H;
fl:=0;
zn:=0;
for j:=1 to dl do
begin
st:=stroka[j];
case sost of
AUTO_H:
case stroka[j] of
';': begin sost:=AUTO_R;str:=str+st; end;
'<': begin sost:=AUTO_OO;str:=str+st; end;
'>': begin sost:=AUTO_ZZ;str:=str+st; end;
':': begin sost:=AUTO_Q;str:=str+st; end;
'=': begin sost:=AUTO_RAV;str:=str+st; end;
'i': begin sost:=AUTO_IF;str:=str+st; end;
't': begin sost:=AUTO_T;str:=str+st; end;
'e': begin sost:=AUTO_EL;str:=str+st; end;
'0'..'9': begin sost:=AUTO_CH;str:=str+st; end;
'a'..'d','f'..'h','j'..'s','u'..'z': begin sost:=AUTO_I;str:=str+st; end;
' ': begin sost:=AUTO_H;str:=''; end;
else begin sost:=AUTO_E;str:=str+st; end;
end;
AUTO_R:
case stroka[j] of
' ': begin sost:=AUTO_H;fl:=1;zn:=1; end;
else begin sost:=AUTO_E;str:=str+st; end;
end;
AUTO_OO:
case stroka[j] of
' ': begin sost:=AUTO_H;fl:=1;zn:=2; end;
else begin sost:=AUTO_E;str:=str+st; end;
end;
AUTO_ZZ:
case stroka[j] of
' ': begin sost:=AUTO_H;fl:=1;zn:=3; end;
else begin sost:=AUTO_E;str:=str+st; end;
end;

AUTO_Q:
case stroka[j] of
'=': begin sost:=AUTO_Q1;str:=str+st; end;
else begin sost:=AUTO_E;str:=str+st; end;
end;
AUTO_Q1:
case stroka[j] of
' ': begin sost:=AUTO_H;fl:=1;zn:=4; end;
else begin sost:=AUTO_E;str:=str+st; end;
end;

AUTO_RAV:
case stroka[j] of
' ': begin sost:=AUTO_H;fl:=1;zn:=5; end;
else begin sost:=AUTO_E;str:=str+st; end;
end;

AUTO_IF:
case stroka[j] of
'a'..'e','g'..'z','0'..'9': begin sost:=AUTO_I;str:=str+st; end;
' ': begin sost:=AUTO_H;fl:=1;zn:=6; end;
'f': begin sost:=AUTO_IF1;str:=str+st; end;
else begin sost:=AUTO_E;str:=str+st; end;
end;
AUTO_IF1:
case stroka[j] of
'a'..'z','0'..'9': begin sost:=AUTO_I;str:=str+st; end;
' ': begin sost:=AUTO_H;fl:=1;zn:=7; end;
else begin sost:=AUTO_E;str:=str+st; end;
end;

AUTO_T:
case stroka[j] of
'a'..'g','i'..'z','0'..'9': begin sost:=AUTO_I;str:=str+st; end;
' ': begin sost:=AUTO_H;fl:=1;zn:=6; end;
'h': begin sost:=AUTO_T1;str:=str+st; end;
else begin sost:=AUTO_E;str:=str+st; end;
end;
AUTO_T1:
case stroka[j] of
'a'..'d','f'..'z','0'..'9': begin sost:=AUTO_I;str:=str+st; end;
' ': begin sost:=AUTO_H;fl:=1;zn:=6; end;
'e': begin sost:=AUTO_T2;str:=str+st; end;
else begin sost:=AUTO_E;str:=str+st; end;
end;
AUTO_T2:
case stroka[j] of
'a'..'m','o'..'z','0'..'9': begin sost:=AUTO_I;str:=str+st; end;
' ': begin sost:=AUTO_H;fl:=1;zn:=6; end;
'n': begin sost:=AUTO_T3;str:=str+st; end;
else begin sost:=AUTO_E;str:=str+st; end;
end;
AUTO_T3:
case stroka[j] of
'a'..'z','0'..'9': begin sost:=AUTO_I;str:=str+st; end;
' ': begin sost:=AUTO_H;fl:=1;zn:=8; end;
else begin sost:=AUTO_E;str:=str+st; end;
end;

AUTO_EL:
case stroka[j] of
'a'..'k','m'..'z','0'..'9': begin sost:=AUTO_I;str:=str+st; end;
' ': begin sost:=AUTO_H;fl:=1;zn:=6; end;
'l': begin sost:=AUTO_EL1;str:=str+st; end;
else begin sost:=AUTO_E;str:=str+st; end;
end;
AUTO_EL1:
case stroka[j] of
'a'..'r','t'..'z','0'..'9': begin sost:=AUTO_I;str:=str+st; end;
' ': begin sost:=AUTO_H;fl:=1;zn:=6; end;
's': begin sost:=AUTO_EL2;str:=str+st; end;
else begin sost:=AUTO_E;str:=str+st; end;
end;
AUTO_EL2:
case stroka[j] of
'a'..'d','f'..'z','0'..'9': begin sost:=AUTO_I;str:=str+st; end;
' ': begin sost:=AUTO_H;fl:=1;zn:=6; end;
'e': begin sost:=AUTO_EL3;str:=str+st; end;
else begin sost:=AUTO_E;str:=str+st; end;
end;
AUTO_EL3:
case stroka[j] of
'a'..'z','0'..'9': begin sost:=AUTO_I;str:=str+st; end;
' ': begin sost:=AUTO_H;fl:=1;zn:=9; end;
else begin sost:=AUTO_E;str:=str+st; end;
end;

AUTO_CH:
case stroka[j] of
'a'..'f','0'..'9': begin sost:=AUTO_CH;str:=str+st; end;
' ': begin sost:=AUTO_H;fl:=1;zn:=10; end;
else begin sost:=AUTO_E;str:=str+st; end;
end;

AUTO_I:
case stroka[j] of
'a'..'z','0'..'9': begin sost:=AUTO_I;str:=str+st; end;
' ': begin sost:=AUTO_H;fl:=1;zn:=6; end;
else begin sost:=AUTO_E;str:=str+st; end;
end;
AUTO_E: begin
if stroka[j]<>' 'then
begin
sost:=AUTO_E;
str:=str+st;
end
else
begin
sost:=AUTO_H;
Memo3.Lines.Append(str);
str:='';
end;
end;
end;
if fl=1 then
begin

StringGrid4.Cells[0,ind]:=IntToStr(ind);
StringGrid4.Cells[1,ind]:=str;
case zn of
1: StringGrid4.Cells[2,ind]:='Разделяюший знак';
2: StringGrid4.Cells[2,ind]:='Знак сравнения "<"';
3: StringGrid4.Cells[2,ind]:='Знак сравнения ">"';
4: StringGrid4.Cells[2,ind]:='Знак присваивания';
5: StringGrid4.Cells[2,ind]:='Знак сравнения "="';
6: StringGrid4.Cells[2,ind]:='Идентификатор';
7: StringGrid4.Cells[2,ind]:='Оператор условия "if"';
8: StringGrid4.Cells[2,ind]:='Оператор условия "then"';
9: StringGrid4.Cells[2,ind]:='Оператор условия "else"';
10: StringGrid4.Cells[2,ind]:='Шестнадцатеричное число';
end;
str:='';
ind:=ind+1;
fl:=0;
end;
end;
end;

end;

end.
Соседние файлы в папке КУРС_СПО(12вар)+2ч