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

interface

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

type
TAutoState = ( AUTO_H, AUTO_G, AUTO_II, AUTO_I1, AUTO_A, AUTO_A1, AUTO_A2, AUTO_T, AUTO_T1, AUTO_T2, AUTO_T3, AUTO_E1, AUTO_E2, AUTO_E3, AUTO_N, AUTO_N1, AUTO_N2,AUTO_X, AUTO_X1, AUTO_X2,AUTO_O, AUTO_O1, AUTO_WW, AUTO_WW1, AUTO_WW2, AUTO_WW3, AUTO_WW4, AUTO_P, AUTO_M, AUTO_M1,AUTO_B, AUTO_OO, AUTO_ZZ, AUTO_PP, AUTO_PP1, AUTO_PP2, AUTO_PP3, AUTO_BB, AUTO_BB1, AUTO_BB2, AUTO_BB3, AUTO_BB4, AUTO_Q, AUTO_R, AUTO_E, AUTO_EE, AUTO_EE1, AUTO_EE2, AUTO_Q1, AUTO_TT, AUTO_D, AUTO_D1, AUTO_I, AUTO_K,AUTO_K1, AUTO_SL, AUTO_VI, AUTO_VI2,AUTO_VU,AUTO_VU2);
    TForm1 = class(TForm)
    PageControl1: TPageControl;
    TabSheet1: TTabSheet;
    TabSheet2: TTabSheet;
    Label13: TLabel;
    Label14: TLabel;
    Label15: TLabel;
    Label16: TLabel;
    Label17: TLabel;
    Label18: TLabel;
    Label19: TLabel;
    Memo1: TMemo;
    Button3: TButton;
    Button4: TButton;
    Button5: TButton;
    Button7: TButton;
    Memo4: TMemo;
    StringGrid1: TStringGrid;
    StringGrid2: TStringGrid;
    Edit1: TEdit;
    Label7: TLabel;
    Label8: TLabel;
    Label9: TLabel;
    Label10: TLabel;
    Label11: TLabel;
    Label12: TLabel;
    EditSearch: TEdit;
    Button1: TButton;
    Edit2: TEdit;
    Edit3: TEdit;
    Edit4: TEdit;
    Edit5: TEdit;
    Edit6: TEdit;
    Edit8: TEdit;
    Edit7: TEdit;
    StringGrid3: TStringGrid;
    Memo3: TMemo;
    Edit9: TEdit;
    Memo2: TMemo;
    Button2: TButton;
    TabSheet3: TTabSheet;
    Button8: TButton;
    Memo5: TMemo;
    Label1: TLabel;
    Label2: TLabel;
    Memo6: TMemo;
    Button9: TButton;
    Label3: TLabel;
    Button10: TButton;
    Label4: TLabel;
    OpenDialog1: TOpenDialog;
    TreeView1: TTreeView;
    Memo7: TMemo;
    TabSheet4: TTabSheet;
    Memo8: TMemo;
    Button6: TButton;
    procedure FormCreate(Sender: TObject);
    procedure BtnXeshClick(Sender: TObject);
    procedure BtnLoadClick(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure BtnExitClick(Sender: TObject);
    procedure Button6Click(Sender: TObject);
    procedure Button11Click(Sender: TObject);

   private
   public
   l2:integer;
  end;

var
  Form1: TForm1;

implementation
{$R *.DFM}
 //*********************************************
function Cod(S:string;i:integer):integer;

var dl:integer;
    midlsymbol:char;
    lastsymbol,lastsymbol1:char;
    const Nm=510;
begin
dl:=length(S);
              if dl=1 then begin
                  lastsymbol:=S[dl];
                  lastsymbol1:=S[dl];
                  end
                  else if dl>1 then begin lastsymbol:=S[dl];
                                          lastsymbol1:=S[dl-1];
                                     end
                                    else if dl<1 then cod:=0;
                                    Cod:=(ord(lastsymbol)+ord(lastsymbol1)+i)mod Nm;
end;
///*********************************************************************
procedure TForm1.FormCreate(Sender: TObject);
var i,j,kk:integer;
begin
StringGrid1.Cells[0,0]:='Номер';
StringGrid1.Cells[1,0]:='Идентификатор';
StringGrid2.Cells[1,0]:='Идентификатор';
StringGrid2.Cells[0,0]:='ХФ';
label18.caption:='Количество коллизий';
StringGrid3.Cells[0,0]:='№ п/п';
StringGrid3.Cells[1,0]:='Значение';
StringGrid3.Cells[2,0]:='Лексема';
Memo2.Text:='' ;
       { for i:=64 to 510 do begin
             StringGrid2.Cells[0,i-63]:=IntToStr(i);
         end;                                       
         for i:=1 to 445 do begin
             StringGrid1.Cells[0,i]:=IntToStr(i);
         end; }
 end;

///******************************************************
procedure TForm1.BtnXeshClick(Sender: TObject);
var kh,i1,gg,k1,t,i,ii,dlina,ukaz,j,k,kk,kol,kolf,kol1,kol2,P,pm,l:integer;
a1,b:string;
ss,min,max,sr:integer;
f1:string;
Msg:string;
f:textfile;
hash:array[0..510]of integer;
    fl1,fl2,flag,flag1:boolean;
    stroka,stroki:string;

  SIZE:integer;
  Compres:integer;
  a:array[0..445] of string;
  changed:boolean; // TRUE, если в текущем цикле были обмены
  buf:string;     // буфер для обмена элементов массива
   d,d1:integer;
   mass:array[0..445] of string;
   label 11,L1;

label 1,2,5;
   begin

   fl1:=false;
   fl2:=false;
  
  f1:= Edit1.Text;
  AssignFile(f, f1);
  if f1<>'' then
  begin
  edit3.text:='';
  Memo1.modified:=false;
   end;
for i:=1 to 445 do StringGrid2.Cells[1,i]:='';
    j:=0;
     dlina:=memo5.Lines.Count;
     l2:=dlina;
     if dlina<>0 then
     begin
         for i:=0 to dlina-1 do
         begin
         stroka:=memo5.Lines[i];
         k:=0;
         kh:=1;
         hash[k]:=Cod(stroka,k);
         kk:=hash[k];
          if StringGrid2.cells[1,hash[k]-63]='' then
              begin
              StringGrid2.cells[1,hash[k]-63]:=stroka;
              goto 1;
              end;
               kh:=kh+1;
                if (StringGrid2.cells[1,hash[k]-63]<>'')then
               begin
               l:=l+1;
               P:=P+1;
                for k1:=0 to 445 do begin
                  if (stroka=StringGrid2.cells[1,k1]) or (stroka=StringGrid1.cells[1,k1])then begin
                  l:=l-1;
                   l2:=l2-1;
                  FLAG:=TRUE;
                  goto 1;
                  end;
                  end;
               k:=1;
               2:hash[k]:=cod(stroka,k);
               if StringGrid2.cells[1,hash[k]-63]='' then
                  begin
                   StringGrid2.cells[1,hash[k]-63]:=stroka;
                   goto 1;
                   end;
                       if (hash[k]=hash[i]) then
                        begin
                        MessageDlg('Ячейка с ХФ  [ '+StringGrid2.cells[1,hash[i]-63]+ ' ]  уже занята !!!',mtError,[mbOk],0);
                        goto 1;
                        end;
                        kh:=kh+1;
                        if (hash[k]<>hash[i])then begin k:=k+1;
                        goto 2;
                    end;
       end;
  1:  end;
  end;
if (l>0) then
 edit3.text:=' '+inttostr(l);
 if (l=0) then (edit3.text:=' ');
end;

//////**************************************************************
procedure TForm1.BtnLoadClick(Sender: TObject);
Const N1=28;
      N2=27;
      N3=26;
      N4=26;
Label M1,M2;
 var
   f: TextFile;       // файл
   fName,y: String; // имя файла
   buf: String[80];   // буфер для чтения из файла
   i:integer;
    ind,j,i1,i2,fl,fl1,zn,h,fl5,fl3:integer;
    st,str,stroka:string;
    sost:TAutoState;

    CepofV:array [1..100]of integer;
    p,stek,d:TStringList;
   dl,i4,j2fl2,n,m,k,vetv,u:integer;
    o1,o2,o3,o4,o5,o6,pr:string;
   MyTreeNode:TTreeNode;
    nodeTree: TTreeNode;

    const
 matrix: array [1..N3,1..N3] of char =(
(' ','=','<','<',' ',' ',' ','<',' ','<',' ','<',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '),
(' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	'>'),
(' ',	'>',	'>',	'<',	' ',	' ',	' ',	'<',	'>',	'<',	' ',	'<',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' '),
(' ',	' ',	' ',	' ',	'=',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' '),
(' ',	' ',	' ',	' ',	'<',	'=',	' ',	' ',	' ',	' ',	' ',	'<',	'<',	' ',	'<',	'<',	'<',	'<',	'<',	'<',	'<',	'<',	'<',	'<',	' ',	' '),
(' ',	'>',	'>',	' ',	' ',	'>',	'>',	' ',	'>',	' ',	'=',	' ',	' ',	' ',	'>',	'>',	'>',	'>',	'>',	' ',	'>',	'>',	'>',	' ',	'=',	' '),
(' ',	'>',	'>',	'<',	' ',	' ',	'>',	'<',	'>',	'<',	' ',	'<',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' '),
(' ',	' ',	'<',	'<',	' ',	' ',	' ',	'<',	'=',	'<',	' ',	'<',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' '),
(' ',	'>',	'>',	' ',	' ',	' ',	'>',	' ',	'>',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' '),
(' ',	' ',	' ',	' ',	'=',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' '),
(' ',	'>',	'>',	'<',	' ',	' ',	'>',	'<',	'>',	'<',	' ',	'<',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' '),
(' ',	'>',	'>',	' ',	' ',	'>',	'>',	' ',	'>',	' ',	' ',	' ',	' ',	'=',	'>',	'>',	'>',	'>',	'>',	' ',	'>',	'>',	'>',	' ',	' ',	' '),
(' ',	'>',	'>',	' ',	' ',	'>',	'>',	' ',	'>',	' ',	' ',	' ',	' ',	' ',	'>',	'>',	'>',	'>',	'>',	' ',	'>',	'>',	'>',	' ',	' ',	' '),
(' ',	'>',	'>',	' ',	'<',	' ',	'>',	' ',	'>',	' ',	' ',	'<',	'<',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	'<',	'<',	'<',	'<',	' ',	' '),
(' ',	' ',	' ',	' ',	'<',	'>',	' ',	' ',	' ',	' ',	' ',	'<',	'<',	' ',	'>',	'>',	'<',	'<',	'<',	'<',	'<',	'<',	'<',	'<',	' ',	' '),
(' ',	' ',	' ',	' ',	'<',	'>',	' ',	' ',	' ',	' ',	' ',	'<',	'<',	' ',	'>',	'>',	'<',	'<',	'<',	'<',	'<',	'<',	'<',	'<',	' ',	' '),
(' ',	' ',	' ',	' ',	'<',	'>',	' ',	' ',	' ',	' ',	' ',	'<',	'<',	' ',	'>',	'>',	' ',	' ',	' ',	' ',	'<',	'<',	'<',	'<',	' ',	' '),
(' ',	' ',	' ',	' ',	'<',	'>',	' ',	' ',	' ',	' ',	' ',	'<',	'<',	' ',	'>',	'>',	' ',	' ',	' ',	' ',	'<',	'<',	'<',	'<',	' ',	' '),
(' ',	' ',	' ',	' ',	'<',	'>',	' ',	' ',	' ',	' ',	' ',	'<',	'<',	' ',	'>',	'>',	' ',	' ',	' ',	' ',	'<',	'<',	'<',	'<',	' ',	' '),
(' ',	' ',	' ',	' ',	'=',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' '),
(' ',	'>',	'>',	'<',	' ',	'>',	'>',	' ',	'>',	' ',	' ',	'<',	'<',	' ',	'>',	'>',	'>',	'>',	'>',	' ',	'>',	'>',	' ',	' ',	' ',	' '),
(' ',	'>',	'>',	'<',	' ',	'>',	'>',	' ',	'>',	' ',	' ',	'<',	'<',	' ',	'>',	'>',	'>',	'>',	'>',	' ',	'>',	'>',	' ',	' ',	' ',	' '),
(' ',	'>',	'>',	' ',	'<',	'>',	'>',	' ',	'>',	' ',	' ',	'<',	'<',	' ',	'>',	'>',	'>',	'>',	'>',	' ',	'>',	'>',	' ',	' ',	' ',	' '),
(' ',	'>',	'>',	' ',	'<',	'>',	'>',	' ',	'>',	' ',	' ',	'<',	'<',	' ',	'>',	'>',	'>',	'>',	'>',	' ',	'>',	'>',	' ',	' ',	' ',	' '),
(' ',	' ',	'>',	'<',	' ',	' ',	'=',	'<',	'>',	'<',	' ',	'<',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' '),
('<',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' '));

//  	prog	end.	;	or	and	not	'<',	'>',	'=',	(	)	if	then	else	do	for	to	downto	:'=',	' ',	+	*	'>','>',	'<','<',	/	a	c	begin	end	over
{ (	' ',	'=',	'<',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	'<',	' ',	' ',	' ',	'<',	' ',	' ',	'<',	' ',	' ',	' ',	' ',	' ',	' ',	'<',	' ',	'<',	' ',	' ',
	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	'>',
	' ',	'>',	'>',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	'<',	' ',	' ',	' ',	'<',	' ',	' ',	'<',	' ',	' ',	' ',	' ',	' ',	' ',	'<',	' ',	'<',	'>',	' ',
	' ',	' ',	' ',	'>',	'<',	'<',	'<',	'<',	'<',	'<',	'>',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	'<',	'<',	'<',	'<',	'<',	'<',	'<',	'<',	' ',	' ',	' ',
	' ',	' ',	' ',	'>',	'>',	'<',	'<',	'<',	'<',	'<',	'>',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	'<',	'<',	'<',	'<',	'<',	'<',	'<',	'<',	' ',	' ',	' ',
	' ',	' ',	' ',	'>',	'>',	'<',	'<',	'<',	'<',	'<',	'>',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	'<',	'<',	'<',	'<',	'<',	'<',	'<',	'<',	' ',	' ',	' ',
'<',	' ',	' ',	' ',	'>',	'>',	' ',	' ',	' ',	' ',	'<',	'>',	' ',	'>',	' ',	' ',	' ',	' ',	' ',	' ',	'<',	'<',	'<',	'<',	'<',	'<',	'<',	'<',	' ',	' ',	' ',
'>',	' ',	' ',	' ',	'>',	'>',	' ',	' ',	' ',	' ',	'<',	'>',	' ',	'>',	' ',	' ',	' ',	' ',	' ',	' ',	'<',	'<',	'<',	'<',	'<',	'<',	'<',	'<',	' ',	' ',	' ',
'=',	' ',	' ',	' ',	'>',	'>',	' ',	' ',	' ',	' ',	'<',	'>',	' ',	'>',	' ',	' ',	' ',	' ',	' ',	' ',	'<',	'<',	'<',	'<',	'<',	'<',	'<',	'<',	' ',	' ',	' ',
(	' ',	' ',	' ',	'<',	'<',	'<',	'<',	'<',	'<',	'<',	'=',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	'<',	'<',	'<',	'<',	'<',	'<',	'<',	'<',	' ',	' ',	' ',
)	' ',	'>',	'>',	'>',	'>',	' ',	'>',	'>',	'>',	' ',	' ',	' ',	'>',	'>',	' ',	' ',	'>',	'>',	' ',	'>',	'>',	'>',	'>',	'>',	'>',	' ',	' ',	' ',	'>',	' ',
	' ',	'>',	'>',	' ',	' ',	' ',	'<',	'<',	'<',	'<',	' ',	' ',	'<',	'<',	' ',	' ',	' ',	' ',	' ',	'<',	'<',	'<',	'<',	'<',	'<',	'<',	'<',	' ',	'>',	' ',
	' ',	'>',	'>',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	'<',	' ',	'>',	' ',	'<',	' ',	' ',	'<',	' ',	' ',	' ',	' ',	' ',	' ',	'<',	' ',	'<',	'>',	' ',
	' ',	'>',	'>',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	'<',	' ',	'>',	' ',	'<',	' ',	' ',	'<',	' ',	' ',	' ',	' ',	' ',	' ',	'<',	' ',	'<',	'>',	' ',
	' ',	'>',	'>',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	'<',	' ',	'>',	' ',	'<',	' ',	' ',	'<',	' ',	' ',	' ',	' ',	' ',	' ',	'<',	' ',	'<',	'>',	' ',
	' ',	'>',	'>',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	'>',	' ',	' ',	'<',	'<',	'<',	' ',	' ',	' ',	' ',	' ',	' ',	'<',	' ',	' ',	'>',	' ',
	' ',	'>',	'>',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	'>',	'<',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	'<',	'<',	' ',	'>',	' ',
	' ',	'>',	'>',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	'>',	'<',	' ',	' ',	' ',	' ',	'<',	'<',	'<',	'<',	'<',	'<',	'<',	'<',	' ',	'>',	' ',
'=',	' ',	'>',	'>',	' ',	' ',	' ',	' ',	' ',	' ',	'<',	' ',	' ',	' ',	'>',	' ',	' ',	'>',	'>',	' ',	'<',	'<',	'<',	'<',	'<',	'<',	'<',	'<',	' ',	'>',	' ',
' ',	' ',	'>',	'>',	'>',	'>',	' ',	'>',	'>',	'>',	'<',	'>',	' ',	'>',	'>',	' ',	' ',	'>',	'>',	' ',	'>',	'>',	'>',	'>',	'>',	'>',	'<',	'<',	' ',	'>',	' ',
	' ',	'>',	'>',	'>',	'>',	' ',	'>',	'>',	'>',	'<',	'>',	' ',	'>',	'>',	' ',	' ',	'>',	'>',	' ',	'>',	'>',	'>',	'>',	'>',	'>',	'<',	'<',	' ',	'>',	' ',
	' ',	'>',	'>',	'>',	'>',	' ',	'>',	'>',	'>',	'<',	'>',	' ',	'>',	'>',	' ',	' ',	'>',	'>',	' ',	'>',	'>',	'>',	'>',	'>',	'>',	'<',	'<',	' ',	'>',	' ',
'>','>',	' ',	'>',	'>',	'>',	'>',	' ',	'>',	'>',	'>',	'<',	'>',	' ',	'>',	'>',	' ',	' ',	'>',	'>',	' ',	'>',	'>',	'>',	'>',	'>',	'>',	'<',	'<',	' ',	'>',	' ',
'<','<',	' ',	'>',	'>',	'>',	'>',	' ',	'>',	'>',	'>',	'<',	'>',	' ',	'>',	'>',	' ',	' ',	'>',	'>',	' ',	'>',	'>',	'>',	'>',	'>',	'>',	'<',	'<',	' ',	'>',	' ',
	' ',	'>',	'>',	'>',	'>',	' ',	'>',	'>',	'>',	'<',	'>',	' ',	'>',	'>',	' ',	' ',	'>',	'>',	' ',	'>',	'>',	'>',	'>',	'>',	'>',	'<',	'<',	' ',	'>',	' ',
	' ',	'>',	'>',	'>',	'>',	' ',	'>',	'>',	'>',	' ',	'>',	' ',	'>',	'>',	'>',	' ',	'>',	'>',	'>',	'>',	'>',	'>',	'>',	'>',	'>',	' ',	' ',	' ',	'>',	' ',
	' ',	'>',	'>',	'>',	'>',	' ',	'>',	'>',	'>',	' ',	'>',	' ',	'>',	'>',	'>',	' ',	'>',	'>',	' ',	'>',	'>',	'>',	'>',	'>',	'>',	' ',	' ',	' ',	'>',	' ',
	' ',	' ',	'<',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	'<',	' ',	' ',	' ',	'<',	' ',	' ',	'<',	' ',	' ',	' ',	' ',	' ',	' ',	'<',	' ',	'<',	'=',	' ',
	' ',	'>',	'>',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	'>',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	'>',	' ',
	'<',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',	' ',

 }
{   prog S end.
S;S
S;
S or S
S and S
not S
S = S
(S)
S then S
S else S
for S
S to S
S downto S
if S
begin S end
S do S
S := S
S - S
S + S
S * S
S << S
S >> S
S < S
S > S
S / S
a
c
}

  { prav_1:array [1..N2,1..2] of string= (
    ('1','progEend.'),   // progEend.
    ('2','E'),           // E
    ('3','E;E'),        //  E;E
    ('4','E;'),            // E;
    ('5','if(E)thenEelseE'),  //if(b)thenRelseE
    ('6','if(E)thenE'),       //if(B)thenE
    ('7','beginEend'),       // beginEend
    ('8','while(E)doE'),    //  while(B)doE
    ('9','a:=E'),           //  a:=E
    ('10','E-E'),       // E-E
    ('11','E+E'),       //  E+E
    ('12','E<<E'),      // E<<E
    ('13','E>>E'),      //  E>>E
    ('14','(E)'),       // (E)
    ('15','a'),         //   a
    ('16','c'),         //   c
    ('17','if(E)thenEelseE'), // if(B)thenRelseR
    ('18','EorE'),        //    BorB
    ('19','E'),          //     B
    ('20','EandE'),      //     BandB
    ('21','E<E'),       //  E<E
    ('22','E>E'),       //  E>E
    ('23','E=E'),       //E=E
    ('24','(E)'),
    ('25','not(E)'));
    }

     prav_1:array [1..N2,1..2] of string= (
    ('1','progEend.'),   // progEend.
    ('2','E'),           // E
    ('3','E;E'),        //  E;E
    ('4','E;'),            // E;
    ('5','if(E)thenEelseE'),  //if(b)thenRelseE
    ('6','if(E)thenE'),       //if(B)thenE
    ('7','beginEend'),       // beginEend
    ('8','while(E)doE'),    //  while(B)doE
    ('9','a:=E'),           //  a:=E
    ('10','if(E)thenEelseE'), // if(B)thenRelseR
    ('11','EorE'),        //    BorB
    ('12','E'),          //     B
    ('13','EandE'),      //     BandB
    ('14','E'),          //     B
    ('15','E<E'),       //  E<E
    ('16','E>E'),       //  E>E
    ('17','E=E'),       //E=E
    ('18','(E)'),
    ('19','not(E)'),
    ('20','E-E'),       // E-E
    ('21','E+E'),       //  E+E
    ('22','E<<E'),      // E<<E
    ('23','E>>E'),      //  E>>E
    ('24','E'),
    ('25','(E)'),       // (E)
    ('26','a'),         //   a
    ('27','c'));         //   c


  {    prav_1:array [1..N2,1..2] of string= (
    ('1','progEend.'),   // progEend.

    ('2','E;E'),        //  E;E
    ('3','E;'),            // E;
    ('4','if(E)thenEelseE'),  //if(b)thenRelseE
    ('5','if(E)thenE'),       //if(B)thenE
    ('6','beginEend'),       // beginEend
    ('7','while(E)doE'),    //  while(B)doE
    ('8','a:=E'),           //  a:=E
    ('9','E-E'),       // E-E
    ('10','E+E'),       //  E+E
    ('11','E<<E'),      // E<<E
    ('12','E>>E'),      //  E>>E
    ('13','(E)'),       // (E)
    ('14','a'),         //   a
    ('15','c'),         //   c
    ('16','if(E)thenEelseE'), // if(B)thenRelseR
    ('17','EorE'),        //    BorB

    ('18','EandE'),      //     BandB
    ('19','E<E'),       //  E<E
    ('20','E>E'),       //  E>E
    ('21','E=E'),       //E=E
    ('22','(E)'),
    ('23','not(E)'));
   }
    term:array [1..26,1..2] of string =(
  //  prog	end.	;	if	(	)	else	begin	end	while	do	a	c	:=	or	and	<	>	=	not	-	+	<<	>>	then	e
{  prog
End.
;
If
(
)
Else
begin
End.
while
Do
A
c
:=
or
and
<
>
=
not
-
+
<<
>>
then
b   }

    ('1','prog'),
    ('2','end.'),
    ('3',';'),
    ('4','if'),
    ('5','('),
    ('6',')'),
    ('7','else'),
    ('8','begin'),
    ('9','end'),
    ('10','while'),
    ('11','do'),
    ('12','a'),
    ('13','c'),
    ('14',':='),
    ('15','or'),
    ('16','and'),
    ('17','<'),
    ('18','>'),
    ('19','='),
    ('20','not'),
    ('21','-'),
    ('22','+'),
    ('23','<<'),
    ('24','>>'),
    ('25','then'),
    ('26','@'));

    notterm:array [1..28] of char=
    ('E','E','E','E','E','E','E','E','E','E','E','E','E','E','E','E','E','E','E','E','E','E','E','E','E','E','E','E');

  {  Canon:array [1..7,1..4] of string= (
          ('a',':=','E',';'),
          ('E','or','E',''),
          ('E','xor','E',''),
          ('E','and','E',''),
          ('(','E',')',''),
          ('not','(','E',')'),
          ('a','','',''));

      }
 {    Canon:array [1..25,1..9] of string= (
    ('prog','E','end','.','','','','',''),   // progEend.
    ('E','','','','','','','',''),           // E
    ('E',';','E','','','','','',''),        //  E;E
    ('E',';','','','','','','',''),            // E;
    ('if','(','E',')','then','E','else','E',''),  //if(b)thenRelseE
    ('if','(','E',')','then','E','','',''),       //if(B)thenE
    ('begin','E','end','','','','','',''),       // beginEend
    ('while','(','E',')','do','E','','',''),    //  while(B)doE
    ('a',':=','E','','','','','',''),           //  a:=E
    ('E','-','E','','','','','',''),       // E-E
    ('E','+','E','','','','','',''),       //  E+E
    ('E','<<','E','','','','','',''),      // E<<E
    ('E','>>','E','','','','','',''),      //  E>>E
    ('(','E',')','','','','','',''),       // (E)
    ('a','','','','','','','',''),         //   a
    ('c','','','','','','','',''),         //   c
    ('if','(','E',')','then','E','else','E',''), // if(B)thenRelseR
    ('E','or','E','','','','','',''),        //    BorB
    ('E','','','','','','','',''),          //     B
    ('E','and','E','','','','','',''),      //     BandB
    ('E','<','E','','','','','',''),       //  E<E
    ('E','>','E','','','','','',''),       //  E>E
    ('E','=','E','','','','','',''),       //E=E
    ('(','E',')','','','','','',''),
    ('not','(','E',')','','','','',''));
    }

     Canon:array [1..27,1..8] of string= (
    ('prog','E','end.','','','','',''),   // progEend.
    ('E','','','','','','',''),           // E
    ('E',';','E','','','','',''),        //  E;E
    ('E',';','','','','','',''),            // E;
    ('if','(','E',')','then','E','else','E'),  //if(b)thenRelseE
    ('if','(','E',')','then','E','',''),       //if(B)thenE
    ('begin','E','end','','','','',''),       // beginEend
    ('while','(','E',')','do','E','',''),    //  while(B)doE
    ('a',':=','E','','','','',''),           //  a:=E
    ('if','(','E',')','then','E','else','E'), // if(B)thenRelseR
    ('E','or','E','','','','',''),        //    BorB
    ('E','','','','','','',''),          //     B
    ('E','and','E','','','','',''),      //     BandB
    ('E','','','','','','',''),
    ('E','<','E','','','','',''),       //  E<E
    ('E','>','E','','','','',''),       //  E>E
    ('E','=','E','','','','',''),       //E=E
    ('(','E',')','','','','',''),
    ('not','(','E',')','','','',''),
     ('E','-','E','','','','',''),       // E-E
    ('E','+','E','','','','',''),       //  E+E
    ('E','<<','E','','','','',''),      // E<<E
    ('E','>>','E','','','','',''),      //  E>>E
    ('E','','','','','','',''),
    ('(','E',')','','','','',''),       // (E)
    ('a','','','','','','',''),         //   a
    ('c','','','','','','',''));         //   c


   {   Canon:array [1..23,1..9] of string= (
    ('prog','E','end','.','','','','',''),   // progEend.

    ('E',';','E','','','','','',''),        //  E;E
    ('E',';','','','','','','',''),            // E;
    ('if','(','E',')','then','E','else','E',''),  //if(b)thenRelseE
    ('if','(','E',')','then','E','','',''),       //if(B)thenE
    ('begin','E','end','','','','','',''),       // beginEend
    ('while','(','E',')','do','E','','',''),    //  while(B)doE
    ('a',':=','E','','','','','',''),           //  a:=E
    ('E','-','E','','','','','',''),       // E-E
    ('E','+','E','','','','','',''),       //  E+E
    ('E','<<','E','','','','','',''),      // E<<E
    ('E','>>','E','','','','','',''),      //  E>>E
    ('(','E',')','','','','','',''),       // (E)
    ('a','','','','','','','',''),         //   a
    ('c','','','','','','','',''),         //   c
    ('if','(','E',')','then','E','else','E',''), // if(B)thenRelseR
    ('E','or','E','','','','','',''),        //    BorB

    ('E','and','E','','','','','',''),      //     BandB
    ('E','<','E','','','','','',''),       //  E<E
    ('E','>','E','','','','','',''),       //  E>E
    ('E','=','E','','','','','',''),       //E=E
    ('(','E',')','','','','','',''),
    ('not','(','E',')','','','','',''));
   }
 begin

   memo8.Lines.LoadFromFile(getcurrentdir +'\5.txt');
  if OpenDialog1.Execute then   begin

   Memo1.Lines.LoadFromFile(OpenDialog1.FileName)  ;
   Memo3.Lines.LoadFromFile(OpenDialog1.FileName)  ;

    Edit1.Text:=OpenDialog1.FileName;
    y:= Edit1.Text;
    end;
begin
 {    memo5.Text:='' ;
     Memo2.Text:='' ;
     for i:=0 to 2 do
     for i1:=1 to 999 do
     StringGrid3.Cells[i,i1]:='';
     i1:=Memo3.Lines.Count;
     ind:=1;
     i:=0;
     while(i<>i1)do
          begin
                str:='';
                sost:=AUTO_H;
                M1:stroka:=Memo3.Lines[i];
                stroka:=stroka+' #';
                fl:=0;
                fl1:=0;
                zn:=0;
                j:=1;
                while (stroka[j]<>'#') do
                      begin
                            st:=stroka[j];
                            case sost of
                            AUTO_H:      }
                            u:=1;
p:=TStringList.Create;
p.Sorted:=False;
stek:=TStringList.Create;

stek.Sorted:=False;
d:=TStringList.Create;
d.Sorted:=False;

     i1:=Memo1.Lines.Count;
     memo5.Text:='' ;
     Memo2.Text:='' ;
     for i:=0 to 2 do
     {for i1:=1 to 999 do
     StringGrid3.Cells[i,i1]:='';  }

     i1:=Memo1.Lines.Count;
     ind:=1;
     i:=0;
    {
     while(i<>i1)do
     begin   }
    for i:=1 to i1 do
          begin
                str:='';
               // M1:
                stroka:=Memo1.Lines[i-1];
                stroka:=stroka+' ';
                dl:=Length(stroka);
                sost:=AUTO_H;
                fl:=0;
                zn:=0;
                j:=1;
               for j:=1 to dl do
                      begin
                    {  while (stroka[j]<>'#') do
                      begin }
                          st:=stroka[j];
                            case sost of
                            AUTO_H:

                              case stroka[j] of
                                    'P','p':begin sost:=AUTO_PP;str:=str+st; end;
                                    'B','b':begin sost:=AUTO_BB;str:=str+st;h:=1; end;
                                    'E','e':begin sost:=AUTO_EE;str:=str+st;h:=1; end;
                                    'W','w':begin sost:=AUTO_WW;str:=str+st; end;
                                    'A','a':begin sost:=AUTO_A;str:=str+st;h:=1; end;
                                    'O','o':begin sost:=AUTO_O;str:=str+st; end;
                                    'N','n':begin sost:=AUTO_N;str:=str+st; end;
                                    'X','x':begin sost:=AUTO_X;str:=str+st; end;
                                    'I','i':begin sost:=AUTO_II;str:=str+st; end;
                                    'T','t':begin sost:=AUTO_T;str:=str+st; end;
                                    '0'..'9','C','F':begin sost:=AUTO_G;str:=str+st;h:=1; end;
                                    ';': begin sost:=AUTO_R;str:=str+st; end;
                                    '.': begin sost:=AUTO_TT;str:=str+st; end;
                                    '/': begin sost:=AUTO_K;str:=str+st; end;
                                    '+': begin sost:=AUTO_SL;str:=str+st; end;
                                    '-': begin sost:=AUTO_VI;str:=str+st; end;
                                    ':': begin sost:=AUTO_Q;str:=str+st; end;
                                    '=': begin sost:=AUTO_P;str:=str+st; end;
                                     '<': begin sost:=AUTO_VU;str:=str+st; end;
                                     '>': begin sost:=AUTO_M;str:=str+st; end;
                                    '(': begin sost:=AUTO_OO;str:=str+st; end;
                                    ')': begin sost:=AUTO_ZZ;str:=str+st; end;
                                    'D','d': begin sost:=AUTO_D;str:=str+st;h:=1; end;
                                    ' ': begin sost:=AUTO_H;str:=''; end;
                                    'c','f'..'h','j'..'m','q'..'s','u','v','y','z': begin sost:=AUTO_I;str:=str+st; end;
                                    'G'..'H','J'..'M','Q'..'S','U','V','Y','Z': begin sost:=AUTO_I;str:=str+st; end;
                                    else begin sost:=AUTO_E;str:=str+st; end;
                              end;
                            AUTO_T:
                              case stroka[j] of
                                    'H','h':begin sost:=AUTO_T1;str:=str+st; end;
                                    'A'..'G','I'..'Z','a'..'g','i'..'z','0'..'9':begin sost:=AUTO_I;str:=str+st; end;
                                    ' ','+','-',';',':',')','>','<','=': begin sost:=AUTO_H;fl:=1;zn:=5;  {j:=j-1;}fl1:=1;end;
                                    else begin sost:=AUTO_E;str:=str+st; end;
                              end;
                            AUTO_T1:
                              case stroka[j] of
                                    'E','e':begin sost:=AUTO_T2;str:=str+st; end;
                                    'A'..'D','F'..'Z','a'..'d','f'..'z','0'..'9':begin sost:=AUTO_I;str:=str+st; end;
                                    ' ','+','-',';',':',')','(','>','<','=': begin sost:=AUTO_H;fl:=1;zn:=5; {j:=j-1;}fl1:=1; end;
                                    else begin sost:=AUTO_E;str:=str+st; end;
                              end;
                            AUTO_T2:
                              case stroka[j] of
                                    'N','n':begin sost:=AUTO_T3;str:=str+st; end;
                                    'A'..'M','O'..'Z','a'..'m','o'..'z','0'..'9':begin sost:=AUTO_I;str:=str+st; end;
                                    ' ','+','-',';',':',')','>','<','=': begin sost:=AUTO_H;fl:=1;zn:=5;  {j:=j-1;}fl1:=1; end;
                                    else begin sost:=AUTO_E;str:=str+st; end;
                              end;
                            AUTO_T3:
                              case stroka[j] of
                                    'A'..'Z','a'..'z','0'..'9':begin sost:=AUTO_I;str:=str+st; end;
                                    ' ': begin sost:=AUTO_H;fl:=1;zn:=24;{ { {j:=j-1;} fl1:=0;end;
                                    else begin sost:=AUTO_E;str:=str+st; end;
                              end;
                            AUTO_II:
                              case stroka[j] of
                                    'F','f':begin sost:=AUTO_I1;str:=str+st; end;
                                    'A'..'E','G'..'Z','a'..'e','g'..'z','0'..'9':begin sost:=AUTO_I;str:=str+st; end;
                                    ' ','+','-',';',':',')','>','<','=': begin sost:=AUTO_H;fl:=1;zn:=5;{j:=j-1;}fl1:=1;end;
                                    else begin sost:=AUTO_E;str:=str+st; end;
                              end;
                             AUTO_I1:
                              case stroka[j] of
                                    'A'..'Z','a'..'z','0'..'9':begin sost:=AUTO_I;str:=str+st; end;
                                    ' ','(': begin sost:=AUTO_H;fl:=1;zn:=15;  {j:=j-1;}fl1:=0; end;
                                    else begin sost:=AUTO_E;str:=str+st; end;
                              end;
                            AUTO_A:
                              case stroka[j] of
                                    'N','n':begin sost:=AUTO_A1;str:=str+st; end;
                                    'A'..'F','0'..'9':begin sost:=AUTO_G;str:=str+st;h:=h+1; end;
                                    '$':begin sost:=AUTO_H;str:=str+st;fl:=1;zn:=17; fl1:=1;end;
                                    'G'..'M','O'..'Z','a'..'m','o'..'z':begin sost:=AUTO_I;str:=str+st; end;
                                    ' ','+','-',';',':',')','>','<','=': begin sost:=AUTO_H;fl:=1;zn:=5;  {j:=j-1;}fl1:=1;end;
                                    else begin sost:=AUTO_E;str:=str+st; end;
                              end;
                            AUTO_A1:
                              case stroka[j] of
                                    'D','d':begin sost:=AUTO_A2;str:=str+st; end;
                                    'A'..'C','E'..'Z','a'..'c','e'..'z','0'..'9':begin sost:=AUTO_I;str:=str+st; end;
                                    ' ','+','-',';',':',')','>','<','=': begin sost:=AUTO_H;fl:=1;zn:=5;  {j:=j-1;}fl1:=1;end;
                                    else begin sost:=AUTO_E;str:=str+st; end;
                              end;
                             AUTO_A2:
                              case stroka[j] of
                                    'A'..'Z','a'..'z','0'..'9':begin sost:=AUTO_I;str:=str+st; end;
                                    ' ','(': begin sost:=AUTO_H;fl:=1;zn:=16; {j:=j-1;}fl1:=0; end;
                                    else begin sost:=AUTO_E;str:=str+st; end;
                              end;

                            AUTO_N:
                              case stroka[j] of
                                    'o','O':begin sost:=AUTO_N1;str:=str+st; end;
                                    'A'..'N','P'..'Z','a'..'n','p'..'z','0'..'9':begin sost:=AUTO_I;str:=str+st; end;
                                    ' ','+','-',';',':',')','>','<','=': begin sost:=AUTO_H;fl:=1;zn:=5;  {j:=j-1;}fl1:=1;end;
                                    else begin sost:=AUTO_E;str:=str+st; end;
                              end;
                           AUTO_N1:
                              case stroka[j] of
                                    'T','t':begin sost:=AUTO_N2;str:=str+st; end;
                                    'A'..'S','U'..'Z','a'..'s','u'..'z','0'..'9':begin sost:=AUTO_I;str:=str+st; end;
                                    ' ','+','-',';',':',')','>','<','=': begin sost:=AUTO_H;fl:=1;zn:=5;  {j:=j-1;}fl1:=1;end;
                                    else begin sost:=AUTO_E;str:=str+st; end;
                              end;
                             AUTO_N2:
                              case stroka[j] of
                                    'A'..'Z','a'..'z','0'..'9':begin sost:=AUTO_I;str:=str+st; end;
                                    ' ','(': begin sost:=AUTO_H;fl:=1;zn:=19; { {j:=j-1;}fl1:=0; end;
                                    else begin sost:=AUTO_E;str:=str+st; end;
                              end;


                      {         AUTO_N:
                              case stroka[j] of
                                    'a'..'n','p'..'z','0'..'9': begin sost:=AUTO_I;str:=str+st; end;
                                    ' ': begin sost:=AUTO_H;fl:=1;zn:=5; end;
                                    'o': begin sost:=AUTO_N1;str:=str+st; end;
                                    else begin sost:=AUTO_E;str:=str+st; end;
                              end;
                            AUTO_N1:
                              case stroka[j] of
                                    'a'..'s','u'..'z','0'..'9': begin sost:=AUTO_I;str:=str+st; end;
                                    ' ': begin sost:=AUTO_H;fl:=1;zn:=5; end;
                                    't': begin sost:=AUTO_N2;str:=str+st; end;
                                    else begin sost:=AUTO_E;str:=str+st; end;
                              end;
                            AUTO_N2:
                              case stroka[j] of
                                    'a'..'z','0'..'9': begin sost:=AUTO_I;str:=str+st; end;
                                    ' ': begin sost:=AUTO_H;fl:=1;zn:=19; end;
                                    else begin sost:=AUTO_E;str:=str+st; end;
                              end;
                                    }

                            AUTO_X:
                              case stroka[j] of
                                    'o','O':begin sost:=AUTO_X1;str:=str+st; end;
                                    'A'..'N','P'..'Z','a'..'n','p'..'z','0'..'9':begin sost:=AUTO_I;str:=str+st; end;
                                    ' ','+','-',';',':',')','>','<','=': begin sost:=AUTO_H;fl:=1;zn:=5; { {j:=j-1;}fl1:=1;end;
                                    else begin sost:=AUTO_E;str:=str+st; end;
                              end;
                            AUTO_X1:
                              case stroka[j] of
                                    'R','r':begin sost:=AUTO_X2;str:=str+st; end;
                                    'A'..'Q','S'..'Z','a'..'q','s'..'z','0'..'9':begin sost:=AUTO_I;str:=str+st; end;
                                    ' ','+','-',';',':',')','>','<','=': begin sost:=AUTO_H;fl:=1;zn:=5; { {j:=j-1;}fl1:=1;end;
                                    else begin sost:=AUTO_E;str:=str+st; end;
                              end;
                             AUTO_X2:
                              case stroka[j] of
                                    'A'..'Z','a'..'z','0'..'9':begin sost:=AUTO_I;str:=str+st; end;
                                    ' ','(': begin sost:=AUTO_H;fl:=1;zn:=21; { {j:=j-1;}fl1:=0; end;
                                    else begin sost:=AUTO_E;str:=str+st; end;
                              end;
                            AUTO_O:
                              case stroka[j] of
                                    'R','r':begin sost:=AUTO_O1;str:=str+st; end;
                                    'A'..'Q','S'..'Z','a'..'q','s'..'z','0'..'9':begin sost:=AUTO_I;str:=str+st; end;
                                    ' ','+','-',';',':',')','>','<','=': begin sost:=AUTO_H;fl:=1;zn:=5; { {j:=j-1;}fl1:=1;end;
                                    else begin sost:=AUTO_E;str:=str+st; end;
                              end;
                             AUTO_O1:
                              case stroka[j] of
                                    'A'..'Z','a'..'z','0'..'9':begin sost:=AUTO_I;str:=str+st; end;
                                    ' ','(': begin sost:=AUTO_H;fl:=1;zn:=20; { {j:=j-1;}fl1:=0; end;
                                    else begin sost:=AUTO_E;str:=str+st; end;
                              end;
                            AUTO_WW:
                              case stroka[j] of
                                    'H','h':begin sost:=AUTO_WW1;str:=str+st; end;
                                    'A'..'G','I'..'Z','a'..'g','i'..'z','0'..'9':begin sost:=AUTO_I;str:=str+st; end;
                                    ' ','+','-',';',':',')','>','<','=': begin sost:=AUTO_H;fl:=1;zn:=5; { {j:=j-1;}fl1:=1;end;
                                    else begin sost:=AUTO_E;str:=str+st; end;
                              end;
                            AUTO_WW1:
                              case stroka[j] of
                                    'I','i':begin sost:=AUTO_WW2;str:=str+st; end;
                                    'A'..'H','J'..'Z','a'..'h','j'..'z','0'..'9':begin sost:=AUTO_I;str:=str+st; end;
                                    ' ','+','-',';',':',')','>','<','=': begin sost:=AUTO_H;fl:=1;zn:=5; { {j:=j-1;}fl1:=1;end;
                                    else begin sost:=AUTO_E;str:=str+st; end;
                              end;
                            AUTO_WW2:
                              case stroka[j] of
                                    'L','l':begin sost:=AUTO_WW3;str:=str+st; end;
                                    'A'..'K','M'..'Z','a'..'k','m'..'z','0'..'9':begin sost:=AUTO_I;str:=str+st; end;
                                    ' ','+','-',';',':',')','>','<','=': begin sost:=AUTO_H;fl:=1;zn:=5; { {j:=j-1;}fl1:=1;end;
                                    else begin sost:=AUTO_E;str:=str+st; end;
                              end;
                            AUTO_WW3:
                              case stroka[j] of
                                    'E','e':begin sost:=AUTO_WW4;str:=str+st; end;
                                    'A'..'D','F'..'Z','a'..'d','f'..'z','0'..'9':begin sost:=AUTO_I;str:=str+st; end;
                                    ' ','+','-',';',':',')','>','<','=': begin sost:=AUTO_H;fl:=1;zn:=5; { {j:=j-1;}fl1:=1;end;
                                    else begin sost:=AUTO_E;str:=str+st; end;
                              end;
                            AUTO_WW4:
                              case stroka[j] of
                                    'A'..'Z','a'..'z','0'..'9':begin sost:=AUTO_I;str:=str+st; end;
                                    ' ','(': begin sost:=AUTO_H;fl:=1;zn:=11; { {j:=j-1;} fl1:=0;end;
                                    else begin sost:=AUTO_E;str:=str+st; end;
                              end;
                            AUTO_EE:
                              case stroka[j] of
                                    'N','n':begin sost:=AUTO_EE1;str:=str+st; end;
                                    'A'..'F','0'..'9':begin sost:=AUTO_G;str:=str+st;h:=h+1; end;
                                    'L','l':begin sost:=AUTO_E1;str:=str+st; end;
                                    '$':begin sost:=AUTO_H;str:=str+st;fl:=1;zn:=17;fl1:=1; end;
                                    'G'..'K','O'..'Z','a'..'k','o'..'z','M','m':begin sost:=AUTO_I;str:=str+st; end;
                                    ' ','+','-',';',':',')','>','<','=': begin sost:=AUTO_H;fl:=1;zn:=5; { {j:=j-1;}fl1:=1;end;
                                    else begin sost:=AUTO_E;str:=str+st; end;
                              end;
                            AUTO_EE1:
                              case stroka[j] of
                                    'D','d':begin sost:=AUTO_EE2;str:=str+st; end;
                                    'A'..'C','E'..'Z','a'..'c','e'..'z','0'..'9':begin sost:=AUTO_I;str:=str+st; end;
                                    ' ','+','-',';',':',')','>','<','=': begin sost:=AUTO_H;fl:=1;zn:=5; { {j:=j-1;}fl1:=1;end;
                                    else begin sost:=AUTO_E;str:=str+st; end;
                              end;
                             AUTO_EE2:
                              case stroka[j] of
                                    'A'..'Z','a'..'z','0'..'9':begin sost:=AUTO_I;str:=str+st; end;
                                    ' ',';': begin sost:=AUTO_H;fl:=1;zn:=3; { {j:=j-1;} fl1:=0;end;
                                    '.': begin sost:=AUTO_H;fl:=1;str:=str+st; zn:=22; { {j:=j-1;} fl1:=0;end;
                                    else begin sost:=AUTO_E;str:=str+st; end;
                              end;
                            AUTO_E1:
                              case stroka[j] of
                                    'S','s':begin sost:=AUTO_E2;str:=str+st; end;
                                    'A'..'R','T'..'Z','a'..'r','t'..'z','0'..'9':begin sost:=AUTO_I;str:=str+st; end;
                                    ' ','+','-',';',':',')','>','<','=': begin sost:=AUTO_H;fl:=1;zn:=5; { {j:=j-1;}fl1:=1;end;
                                    else begin sost:=AUTO_E;str:=str+st; end;
                              end;
                            AUTO_E2:
                              case stroka[j] of
                                    'E','e':begin sost:=AUTO_E3;str:=str+st; end;
                                    'A'..'D','F'..'Z','a'..'d','f'..'z','0'..'9':begin sost:=AUTO_I;str:=str+st; end;
                                    ' ','+','-',';',':',')','>','<','=': begin sost:=AUTO_H;fl:=1;zn:=5; { {j:=j-1;}fl1:=1;end;
                                    else begin sost:=AUTO_E;str:=str+st; end;
                              end;
                            AUTO_E3:
                              case stroka[j] of
                                    'A'..'Z','a'..'z','0'..'9':begin sost:=AUTO_I;str:=str+st; end;
                                    ' ': begin sost:=AUTO_H;fl:=1;zn:=15; { {j:=j-1;}fl1:=0; end;
                                    else begin sost:=AUTO_E;str:=str+st; end;
                              end;
                            AUTO_BB:
                              case stroka[j] of
                                    'E','e':begin sost:=AUTO_BB1;str:=str+st; end;
                                    'A'..'D','F','0'..'9':begin sost:=AUTO_G;str:=str+st;h:=h+1; end;
                                    '$':begin sost:=AUTO_H;str:=str+st;fl:=1;zn:=17; fl1:=1;end;
                                    'G'..'Z','a'..'d','f'..'z':begin sost:=AUTO_I;str:=str+st; end;
                                    ' ','+','-',';',':',')','>','<','=': begin sost:=AUTO_H;fl:=1;zn:=5; { {j:=j-1;}fl1:=1;end;
                                    else begin sost:=AUTO_E;str:=str+st; end;
                              end;
                            AUTO_BB1:
                              case stroka[j] of
                                    'G','g':begin sost:=AUTO_BB2;str:=str+st; end;
                                    'A'..'F','0'..'9':begin sost:=AUTO_G;str:=str+st;h:=h+1; end;
                                    '$':begin sost:=AUTO_H;str:=str+st;fl:=1;zn:=17;fl1:=1; end;
                                    'H'..'Z','a'..'f','h'..'z':begin sost:=AUTO_I;str:=str+st; end;
                                    ' ','+','-',';',':',')','>','<','=': begin sost:=AUTO_H;fl:=1;zn:=5; { {j:=j-1;}fl1:=1;end;
                                    else begin sost:=AUTO_E;str:=str+st; end;
                              end;
                            AUTO_BB2:
                              case stroka[j] of
                                    'I','i':begin sost:=AUTO_BB3;str:=str+st; end;
                                    'A'..'H','J'..'Z','a'..'h','j'..'z','0'..'9':begin sost:=AUTO_I;str:=str+st; end;
                                    ' ','+','-',';',':',')': begin sost:=AUTO_H;fl:=1;zn:=5; { {j:=j-1;}fl1:=1;end;
                                    else begin sost:=AUTO_E;str:=str+st; end;
                              end;
                            AUTO_BB3:
                              case stroka[j] of
                                    'N','n':begin sost:=AUTO_BB4;str:=str+st; end;
                                    'A'..'M','O'..'Z','a'..'m','o'..'z','0'..'9':begin sost:=AUTO_I;str:=str+st; end;
                                    ' ','+','-',';',':',')','>','<','=': begin sost:=AUTO_H;fl:=1;zn:=5; { {j:=j-1;}fl1:=1;end;
                                    else begin sost:=AUTO_E;str:=str+st; end;
                              end;
                            AUTO_BB4:
                              case stroka[j] of
                                    'A'..'Z','a'..'z','0'..'9':begin sost:=AUTO_I;str:=str+st; end;
                                    ' ': begin sost:=AUTO_H;fl:=1;zn:=2; { {j:=j-1;}fl1:=0; end;
                                    else begin sost:=AUTO_E;str:=str+st; end;
                              end;
                            AUTO_PP:
                              case stroka[j] of
                                    'R','r':begin sost:=AUTO_PP1;str:=str+st; end;
                                    'A'..'Q','S'..'Z','a'..'q','s'..'z','0'..'9':begin sost:=AUTO_I;str:=str+st; end;
                                    ' ','+','-',';',':',')','>','<','=': begin sost:=AUTO_H;fl:=1;zn:=5; { {j:=j-1;}fl1:=1;end;
                                    else begin sost:=AUTO_E;str:=str+st; end;
                              end;
                            AUTO_PP1:
                              case stroka[j] of
                                    'O','o':begin sost:=AUTO_PP2;str:=str+st; end;
                                    'A'..'N','P'..'Z','a'..'n','p'..'z','0'..'9':begin sost:=AUTO_I;str:=str+st; end;
                                    ' ','+','-',';',':',')','>','<','=': begin sost:=AUTO_H;fl:=1;zn:=5; { {j:=j-1;}fl1:=1;end;
                                    else begin sost:=AUTO_E;str:=str+st; end;
                              end;
                            AUTO_PP2:
                              case stroka[j] of
                                    'G','g':begin sost:=AUTO_PP3;str:=str+st; end;
                                    'A'..'F','H'..'Z','a'..'f','h'..'z','0'..'9':begin sost:=AUTO_I;str:=str+st; end;
                                    ' ','+','-',';',':',')','>','<','=': begin sost:=AUTO_H;fl:=1;zn:=5; { {j:=j-1;}fl1:=1;end;
                                    else begin sost:=AUTO_E;str:=str+st; end;
                              end;
                            AUTO_PP3:
                              case stroka[j] of
                                    'A'..'Z','a'..'z','0'..'9':begin sost:=AUTO_I;str:=str+st; end;
                                    ' ': begin sost:=AUTO_H;fl:=1;zn:=1; { {j:=j-1;}fl1:=0; end;
                                    else begin sost:=AUTO_E;str:=str+st; end;
                              end;
                            AUTO_K:
                              case stroka[j] of
                                    '/': begin {str:=str+st;}sost:=AUTO_K1; end;
                                    else begin
                                         sost:=AUTO_E;
                                        str:=str+st;
                                         if stroka[j+1]='#' then begin {i:=i+1;}{goto M1;} end;
                                         end;
                              end;

                            AUTO_K1:
                                case stroka[j] of
                                '/': begin sost:=AUTO_K1; end;
                                end;
                            AUTO_OO:
                              case stroka[j] of
                                    ' ','A'..'Z','a'..'z','0'..'9','(': begin sost:=AUTO_H;fl:=1;zn:=12; { {j:=j-1;} fl1:=0;end;
                                    else begin sost:=AUTO_E;str:=str+st; end;
                              end;
                            AUTO_ZZ:
                              case stroka[j] of
                                    ' ','A','a','N','n','O','o','X','x','D','d','T','t','E','e',')',';': begin sost:=AUTO_H;fl:=1;zn:=13; { {j:=j-1;}fl1:=0; end;
                                    else begin sost:=AUTO_E;str:=str+st; end;
                              end;
                            AUTO_B:
                              case stroka[j] of
                                    ' ','A'..'Z','a'..'z','0'..'9': begin sost:=AUTO_H;fl:=1;zn:=14; { {j:=j-1;}fl1:=0; end;
                                    else begin sost:=AUTO_E;str:=str+st; end;
                              end;
                            AUTO_M:
                              case stroka[j] of
                               '>': begin sost:=AUTO_M1;str:=str+st; end;
                                    ' ','A'..'Z','a'..'z','0'..'9': begin sost:=AUTO_H;fl:=1;zn:=25; { {j:=j-1;}fl1:=0; end;
                                    else begin sost:=AUTO_E;str:=str+st; end;
                              end;

                              AUTO_M1:
                              case stroka[j] of
                                  '>','<', ' ',';','A'..'Z','a'..'z','0'..'9': begin sost:=AUTO_H;fl:=1;zn:=10; { {j:=j-1;}fl1:=0; end;
                                    else begin sost:=AUTO_E;str:=str+st; end;
                              end;


                             AUTO_P:       ///////////
                              case stroka[j] of
                                    ' ','A'..'Z','a'..'z','0'..'9': begin sost:=AUTO_H;fl:=1;zn:=14;fl1:=0; end;
                                    else begin sost:=AUTO_E;str:=str+st; end;
                              end;
                            AUTO_SL:
                              case stroka[j] of
                                    ' ','A'..'Z','a'..'z','0'..'9','(': begin sost:=AUTO_H;fl:=1;zn:=8; { {j:=j-1;}fl1:=0; end;
                                    else begin sost:=AUTO_E;str:=str+st; end;
                              end;
                            AUTO_VI:
                              case stroka[j] of
                                    ' ','A'..'Z','a'..'z','0'..'9','(': begin sost:=AUTO_H;fl:=1;zn:=9; { {j:=j-1;}fl1:=0; end;
                                    else begin sost:=AUTO_E;str:=str+st; end;
                              end;
                             AUTO_VU:
                              case stroka[j] of
                                    '<': begin sost:=AUTO_VU2;str:=str+st; end;
                                    ' ','A'..'Z','a'..'z','0'..'9','(': begin sost:=AUTO_H;fl:=1;zn:=14; { {j:=j-1;}fl1:=0; end;
                                    else begin sost:=AUTO_E;str:=str+st; end;
                              end;
                            AUTO_VU2:
                              case stroka[j] of
                                  '>','<', ' ',';','A'..'Z','a'..'z','0'..'9': begin sost:=AUTO_H;fl:=1;zn:=18; { {j:=j-1;}fl1:=0; end;
                                    else begin sost:=AUTO_E;str:=str+st; end;
                              end;


                            AUTO_TT:
                              case stroka[j] of
                                    ' ': begin sost:=AUTO_H;fl:=1;zn:=6; { {j:=j-1;}fl1:=0; end;
                                    else begin sost:=AUTO_E;str:=str+st; end;
                              end;
                            AUTO_R:
                              case stroka[j] of
                                    ' ': begin sost:=AUTO_H;fl:=1;zn:=4; { {j:=j-1;}fl1:=0; 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
                                    ' ','A'..'Z','a'..'z','1'..'9','(': begin sost:=AUTO_H;
                                    fl:=1;zn:=7;{j:=j-1;}fl1:=0;
                                    end;
                                    else begin sost:=AUTO_E;str:=str+st; end;
                              end;
                            {   AUTO_Q:
                              case stroka[j] of
                                    '=': begin sost:=AUTO_Q1;str:=str+st; ShowMessage('  '+str);end;
                                    else begin sost:=AUTO_E;str:=str+st; end;
                              end;
                            AUTO_Q1:
                              case stroka[j] of
                                    ' ','A'..'Z','a'..'z','1'..'9','(',')': begin sost:=AUTO_H;fl:=1;zn:=7;ShowMessage('  '+str); end;
                                    else begin sost:=AUTO_E;str:=str+st; end;
                              end;    }
                            AUTO_D:
                              case stroka[j] of
                                    'G'..'N','P'..'Z','a'..'n','p'..'z': begin sost:=AUTO_I;str:=str+st; end;
                                    'A'..'F','0'..'9':begin sost:=AUTO_G;str:=str+st;h:=h+1; end;
                                    '$':begin sost:=AUTO_H;str:=str+st;fl:=1;zn:=17;fl1:=1; end;
                                    ' ','+','-',';',':',')','>','<','=': begin sost:=AUTO_H;fl:=1;zn:=5; { {j:=j-1;}fl1:=1;end;
                                    'o': begin sost:=AUTO_D1;str:=str+st; end;
                                    else begin sost:=AUTO_E;str:=str+st; end;
                              end;
                            AUTO_D1:
                              case stroka[j] of
                                    'A'..'Z','a'..'z','0'..'9': begin sost:=AUTO_I;str:=str+st; end;
                                    ' ': begin sost:=AUTO_H;fl:=1;zn:=23; { {j:=j-1;} fl1:=0;end;
                                    else begin sost:=AUTO_E;str:=str+st; end;
                              end;
                            AUTO_I:
                              case stroka[j] of
                                    '0'..'9': begin sost:=AUTO_G;str:=str+st; end;
                                     'A'..'Z','a'..'z':  begin sost:=AUTO_G;str:=str+st; end;
                                    ' ',':','+','-',';',')','>','<','=': begin sost:=AUTO_H;fl:=1;zn:=5; { {j:=j-1;}fl1:=1;end;
                                    else begin sost:=AUTO_E;str:=str+st; end;
                              end;
                            AUTO_G:
                              case stroka[j] of
                                    '0'..'9':begin
                                                      h:=h+1;
                                                      if h<5 then begin sost:=AUTO_G;str:=str+st;fl1:=0;end
                                                              else begin sost:=AUTO_I;str:=str+st;fl1:=0;end;
                                                      end;
                                    '$':begin sost:=AUTO_H;str:=str+st;fl:=1;zn:=17; fl1:=1;end;
                                    ' ',':','+','-',';',')','>','<','=':begin
                                    if (str[1]<>'0')and(str[1]<>'1')and(str[1]<>'2')and(str[1]<>'3')and(str[1]<>'4')and(str[1]<>'5')and(str[1]<>'6')and(str[1]<>'7')and(str[1]<>'8')and(str[1]<>'9')
                                                                          then
                                                                           begin sost:=AUTO_H;fl:=1;zn:=5; { {j:=j-1;}fl1:=1;end
                                                                                           else
                                                                                            begin
                                                                                                     sost:=AUTO_H;
                                                                                                     Memo2.Lines.Append(' '+str);
                                                                                                     str:='';
                                                                                                      { {j:=j-1;}
                                                                                                     fl1:=0;
                                                                         end;
                                                                          end;
                                    'A'..'Z','a'..'z':begin sost:=AUTO_G;str:=str+st; end;
                                    else begin sost:=AUTO_E;str:=str+st; end;
                              end;
                            AUTO_E:      begin
                                          if (stroka[j-1]='/')then
                                                              begin
                                                              sost:=AUTO_H;
                                                              Memo2.Lines.Append(' '+str);
                                                              str:=''; { {j:=j-1;}
                                                              end
                                                           else
                                                     if (stroka[j]=' ')then
                                                              begin
                                                              sost:=AUTO_H;
                                                              Memo2.Lines.Append(' '+str);
                                                              str:='';
                                                              end
                                                           else
                                                              begin
                                                              sost:=AUTO_E;
                                                              str:=str+st;
                                                              end;
                                         end;
                            end;
                            if fl=1 then
                                       begin


                                          StringGrid3.Cells[0,ind]:=IntToStr(ind);
                                          StringGrid3.Cells[1,ind]:=str;
                                          if (fl1=1) then begin Memo5.Lines.Append(str);end;

                                          case zn of
                                                1: Begin StringGrid3.Cells[2,ind]:='Ключевое слово "prog"';p.Add('prog');end;
                                                2: Begin StringGrid3.Cells[2,ind]:='Составной оператор - начало "begin"';p.Add('begin');end;
                                                3: Begin StringGrid3.Cells[2,ind]:='Составной оператор - конец "end" ';p.Add('end');end;
                                                4: Begin StringGrid3.Cells[2,ind]:='Разделитель ";"';p.Add(';'); end;
                                                5: Begin StringGrid3.Cells[2,ind]:='Идентификатор "a"';  p.Add('a'); end;
                                                6: Begin StringGrid3.Cells[2,ind]:='Точка (конец программы) "."';p.Add('.');end;
                                                7: Begin StringGrid3.Cells[2,ind]:='Знак присваивания ":="';p.Add(':='); end;
                                                8: Begin StringGrid3.Cells[2,ind]:='Операция сложения "+"';p.Add('+');end;
                                                9: Begin StringGrid3.Cells[2,ind]:='Операция вычитания "-"';p.Add('-');end;
                                                10:Begin StringGrid3.Cells[2,ind]:='Сдвиг вправо "<<"';p.Add('<<');end;
                                                11:Begin StringGrid3.Cells[2,ind]:='Оператор цикла "while"';p.Add('while'); end;
                                                12:Begin StringGrid3.Cells[2,ind]:='Круглая открывающаяся скобка "("';p.Add('('); end;
                                                13:Begin StringGrid3.Cells[2,ind]:='Круглая закрывающаяся скобка ")"';p.Add(')'); end;
                                                14:Begin StringGrid3.Cells[2,ind]:='Оператор сравнения "<"';p.Add('<');  end;
                                                15:Begin StringGrid3.Cells[2,ind]:='Условный оператор "if"';p.Add('if');end;
                                                16:Begin StringGrid3.Cells[2,ind]:='Логический оператор "and"'; p.Add('and'); end;
                                                17:Begin StringGrid3.Cells[2,ind]:='Константа "c"';{h:=0;}p.Add('c'); end;
                                                18:Begin StringGrid3.Cells[2,ind]:='Сдвиг влево ">>"';p.Add('>>'); end;
                                                19:Begin StringGrid3.Cells[2,ind]:='Логический оператор "not"'; p.Add('not'); end;
                                                20:Begin StringGrid3.Cells[2,ind]:='Логический оператор "or"'; p.Add('or');  end;
                                                21:Begin StringGrid3.Cells[2,ind]:='Логический оператор "xor"'; p.Add('xor');  end;
                                                22:Begin StringGrid3.Cells[2,ind]:='Ключевое слово "end."';p.Add('end.');end;
                                                23:Begin StringGrid3.Cells[2,ind]:='Оператор цикла "do"';p.Add('do'); end;
                                                24:Begin StringGrid3.Cells[2,ind]:='Условный оператор "then"'; p.Add('then');end;
                                                25:Begin StringGrid3.Cells[2,ind]:='Оператор сравнения ">"'; p.Add('>'); end;
                                          end;
                                          str:='';
                                          ind:=ind+1;
                                          fl:=0;
                                       end;
                           { j:=j+1;  }
                      end;
         { i:=i+1;    }
          end;
      //    Edit9.Text:=IntToStr(ind-1);
end;

   Edit9.Text:=IntToStr(ind-1);
fl:=p.Count;

     if fl=0 then begin ShowMessage('Ошибка! Таблица лексем пустая!!'); exit;end;
p.Add('@');
stek.Add('@');

stek.Add(p.Strings[0]);
p.Delete(0);
ind:=p.Count-1;
o1:=p.Strings[0];
fl:=stek.Count-1;
o2:=stek.Strings[fl];
//ShowMessage('fl= "'+inttostr(fl)+'"  o1= "'+o1+'" o2= "'+o2+'"');
repeat
Begin
     o1:=p.Strings[0];
     fl:=stek.Count-1;
     repeat
     if stek.Strings[fl]<>'E' then begin
      o2:=stek.Strings[fl]; //ShowMessage(o2 +' '+inttostr(fl));
        end
                              else fl:=fl-1;
     until(o2<>'E');
     //ShowMessage(o2 +' '+inttostr(fl));
     j:=1;
     i1:=0;
     repeat
        if term[j][2]=o1 then begin i1:=StrToInt(term[j][1]); //////////////////////////
                      //   ShowMessage('o1 '+o1+' столбец= '+inttostr(i1));
                         end
                         else j:=j+1;
        if i1>N1 then begin ShowMessage('Ошибка!');exit;end;
     until(i1<>0);
     j:=1;
     i2:=0;
     repeat
        if term[j][2]=o2 then begin i2:=StrToInt(term[j][1]);
                       //  ShowMessage('o2 '+o2+' строка= '+inttostr(i2));
                          end
                         else begin j:=j+1;  end;
        if i2>N1 then begin ShowMessage('Ошибка!');exit;end;
     until(i2<>0);

     o3:=matrix[i2][i1];
    // ShowMessage('o3 '+o3+'строка '+inttostr(i2)+'столбец'+ inttostr(i1));
     if (o3='=')or(o3='<') then
                           begin stek.Add(o1);p.Delete(0); end
                           else
                           if (o3='>') then  /////////////////
                                     begin
                                       if fl=stek.Count-1 then
                                                           begin

                                                           dl:=1;
                                                           i:=1;
                                                           pr:=o2;
                                                           M1:
                                                           o4:=stek.Strings[fl-i];

                                                              if o4<>'E' then begin
                                                                                   j:=1;
                                                                                   i4:=0;
                                                                                   repeat
                                                                                         if term[j][2]=o4 then begin i4:=StrToInt(term[j][1]);
                                                                                                          // ShowMessage('llllll '+ o4);
                                                                                                          end
                                                                                                          else j:=j+1;
                                                                                         if i4>N1 then begin ShowMessage('Ошибка!' );exit;end;
                                                                                    until(i4<>0);
                                                                                    o5:=matrix[i4][i2];

                                                                                    if o5='='then
                                                                                             begin
                                                                                             dl:=dl+1;pr:=o4+pr;i:=i+1;i2:=i4;
                                                                                             goto M1;
                                                                                             end
                                                                                             else begin goto M2; end;
                                                                               end
                                                                               else
                                                                               begin
                                                                               if stek.Strings[fl-i-1]<>'E' then
                                                                                         begin
                                                                                        //  ShowMessage('uiiiiii '+ stek.Strings[fl-i-1]);
                                                                                         j:=1;i4:=0;
                                                                                         repeat
                                                                                         if term[j][2]=stek.Strings[fl-i-1] then i4:=StrToInt(term[j][1])
                                                                                                          else j:=j+1;
                                                                                         if i4>N1 then begin ShowMessage('Ошибка! ');exit;end;
                                                                                         until(i4<>0);
                                                                                    o5:=matrix[i4][i2];
                                                                                    if o5='='then
                                                                                             begin
                                                                                             dl:=dl+1;pr:=o4+pr; i:=i+1;goto M1;
                                                                                             end
                                                                                             else begin goto M2; end;
                                                                                          end;
                                                                               end;

                                                           end
                                                           else
                                                           begin
                                                           dl:=1;
                                                           i:=1;
                                                           pr:=o2;
                                                           o4:=stek.Strings[fl-i];
                                                           o6:=stek.Strings[fl+i];

                                                           if (o4='E')and(o6='E') then begin pr:='E'+o2+'E';//ShowMessage('o4 '+o4+' o5 '+o5+ ' '+pr);
                                                           dl:=3;end
                                                                                  else begin ShowMessage('Ошибка входной цепочки ('+o2+')('+o1+')!');exit; end;
                                                           end;

                                       M2:
                                       for j:=1 to dl do stek.Delete(stek.Count-1);
                                       j:=1;zn:=0;

                                       repeat  ////правило
                                          if prav_1[j][2]=pr then zn:=StrToInt(prav_1[j][1])
                                                        else j:=j+1;
                                       if zn>N2 then begin ShowMessage('Ошибка!');exit;end;
                                       until(zn<>0);

                                       stek.Add('E');
                                       d.Add(IntToStr(zn));
                                       CepofV[u]:=zn;
                                       u:=u+1;
                                    end


                                     else begin  //ShowMessage('fl= "'+inttostr(fl)+'"  o1= "'+o1+'" o2= "'+o2+'"');
                                     ShowMessage('Ошибка во входной цепочке! '+inttostr(fl)+' '+o3+'  ' );exit; end;
fl:=stek.Count-1;
o1:=p.Strings[0];
o2:=stek.Strings[fl-1];
end;
until (o1='@')or(o2='@');
p.Clear;
str:='';
i4:=d.Count-1;
for i:=0 to i4 do str:=str+d.Strings[i]+' ';
memo7.Text:=str;
n:=d.Count;
with TreeView1 do
begin
Items.Clear;
Items.Add(Nil,'E');
vetv:=0;
j:=0;
for k:=n downto 1 do begin
                 m:=Items.Count;
                 if k<n then
                 for i:=m-1 downto 0 do if (Items[i].Text=notterm[CepofV[k]])and(Items[i].HasChildren=False) then begin vetv:=i;break;  end;
                 for i:=1 to 4 do
                 if Canon[CepofV[k],i]<>'' then Items.AddChild(Items[vetv],Canon[CepofV[k],i]);
                 {vetv:=vetv+1;}
                 end;
FullExpand
end;
p.Destroy;
stek.Destroy;
d.Destroy;



{fl:=p.Count;
     if fl=0 then begin ShowMessage('Ошибка! Таблица лексем пустая!!'); exit;end;
p.Add('@');
stek.Add('@');
stek.Add(p.Strings[0]);
p.Delete(0);
ind:=p.Count-1;
o1:=p.Strings[0];
fl:=stek.Count-1;
o2:=stek.Strings[fl];
repeat
Begin
     o1:=p.Strings[0];
     fl:=stek.Count-1;
     repeat
     if stek.Strings[fl]<>'E' then o2:=stek.Strings[fl]
                              else fl:=fl-1;
     until(o2<>'E');
     j:=1;i1:=0;
     repeat
        if term[j][2]=o1 then i1:=StrToInt(term[j][1])
                         else j:=j+1;
        if i1>N1 then begin ShowMessage('Ошибка!');exit;end;
     until(i1<>0);
     j:=1;i2:=0;
     repeat
        if term[j][2]=o2 then i2:=StrToInt(term[j][1])
                         else j:=j+1;
        if i2>N1 then begin ShowMessage('Ошибка!');exit;end;
     until(i2<>0);
     o3:=matrix[i2][i1];
     if (o3='=')or(o3='<') then
                           begin stek.Add(o1);p.Delete(0); end
                           else
                           if o3='>' then
                                     begin
                                       if fl=stek.Count-1 then
                                                           begin
                                                           dl:=1;
                                                           i:=1;
                                                           pr:=o2;
                                                           M1:
                                                           o4:=stek.Strings[fl-i];
                                                              if o4<>'E' then begin
                                                                                   j:=1;i4:=0;
                                                                                   repeat
                                                                                         if term[j][2]=o4 then i4:=StrToInt(term[j][1])
                                                                                                          else j:=j+1;
                                                                                         if i4>N1 then begin ShowMessage('Ошибка!');exit;end;
                                                                                    until(i4<>0);
                                                                                    o5:=matrix[i4][i2];
                                                                                    if o5='='then
                                                                                             begin
                                                                                             dl:=dl+1;pr:=o4+pr;i:=i+1;i2:=i4;
                                                                                             goto M1;
                                                                                             end
                                                                                             else begin goto M2; end;
                                                                               end
                                                                               else
                                                                               begin
                                                                               if stek.Strings[fl-i-1]<>'E' then
                                                                                         begin
                                                                                         j:=1;i4:=0;
                                                                                         repeat
                                                                                         if term[j][2]=stek.Strings[fl-i-1] then i4:=StrToInt(term[j][1])
                                                                                                          else j:=j+1;
                                                                                         if i4>N1 then begin ShowMessage('Ошибка!');exit;end;
                                                                                         until(i4<>0);
                                                                                    o5:=matrix[i4][i2];
                                                                                    if o5='='then
                                                                                             begin
                                                                                             dl:=dl+1;pr:=o4+pr; i:=i+1;goto M1;
                                                                                             end
                                                                                             else begin goto M2; end;
                                                                                          end;   
                                                                               end;

                                                           end
                                                           else
                                                           begin
                                                           dl:=1;
                                                           i:=1;
                                                           pr:=o2;
                                                           o4:=stek.Strings[fl-i];
                                                           o6:=stek.Strings[fl+i];
                                                           if (o4='E')and(o6='E') then begin pr:='E'+o2+'E';dl:=3;end
                                                                                  else begin ShowMessage('Ошибка входной цепочки ('+o2+')!');exit; end;
                                                           end;

                                       M2:
                                       for j:=1 to dl do stek.Delete(stek.Count-1);
                                       j:=1;zn:=0;
                                       repeat
                                          if prav_1[j][2]=pr then zn:=StrToInt(prav_1[j][1])
                                                        else j:=j+1;
                                         if zn>N2 then begin ShowMessage('Ошибка!');exit;end;
                                       until(zn<>0);
                                       stek.Add('E');
                                       d.Add(IntToStr(zn));
                                       CepofV[u]:=zn;
                                       u:=u+1;
                                     end
                                     else begin ShowMessage('Ошибка во входной цепочке!');exit; end;
fl:=stek.Count-1;
o1:=p.Strings[0];
o2:=stek.Strings[fl-1];
end;
until (o1='@')and(o2='@');
p.Clear;
str:='';
i4:=d.Count-1;
for i:=0 to i4 do str:=str+d.Strings[i]+' ';
memo3.Text:=str;
n:=d.Count;
with TreeView1 do
begin
Items.Clear;
Items.Add(Nil,'E');
vetv:=0;
j:=0;
for k:=n downto 1 do begin
                 m:=Items.Count;
                 if k<n then
                 for i:=m-1 downto 0 do if (Items[i].Text=notterm[CepofV[k]])and(Items[i].HasChildren=False) then begin vetv:=i;break;  end;
                 for i:=1 to 4 do
                 if Canon[CepofV[k],i]<>'' then Items.AddChild(Items[vetv],Canon[CepofV[k],i]);
                 {vetv:=vetv+1;}
   {              end;
FullExpand
end;
p.Destroy;
stek.Destroy;
d.Destroy;
   }

end;

///////////////////Поиск в ТИ (ХФ)/////////////////////////////////////
procedure TForm1.Button1Click(Sender: TObject);
var stroka,el,st:string;
e:real;
s,s1,s2:string;
dlina,dt,dlina1,dlina2,koll,kolf,kolll:integer;
 var k,ss,min,max,p,j,sr,sr1,y:integer;a:string;
    hash:Array[0..445]of integer;
    k1,l,i:integer;
    f:char;
    sredn:real;

    label 4,3,6,22,5;
begin
edit4.text:='';
edit2.text:='';
edit7.text:='';
edit8.text:='';
l:=0;
k:=0;
stroka:=EditSearch.Text;
hash[k]:=Cod(stroka,k);
if stroka='' then  begin

                    edit2.text:='Элемент не введён!';
                    edit7.Text:= '';
                    edit8.Text:= '';
                    edit6.Text:= '';
                    edit4.Text:= '';
                    goto 4;
                    end;
if StringGrid2.cells[1,hash[k]-63]='' then
begin
 edit2.text:='Элемент  "'+stroka+'"  не найден!';
 edit7.Text:= '';
 edit8.Text:= '';
 edit6.Text:= '';
 edit4.Text:= '';
goto 4;
   end;
    if StringGrid2.cells[1,hash[k]-63]<>''  then
    begin
   l:=l+1;

   if(StringGrid2.cells[1,hash[k]-63]=stroka) then
    begin
    kolf:=kolf+1;
    edit2.text:='Элемент  "'+stroka+'"  найден. Его ХФ : '+ StringGrid2.cells[0,hash[k]-63];
    edit4.Text:=inttostr(kolf);
    goto 4;
 end;
     if(StringGrid2.cells[1,hash[k]-63]<>stroka)  then
 begin
 k:=1;
 kolf:=kolf+1;
 3:
    hash[k]:=cod(stroka,k);
    if (StringGrid2.cells[1,hash[k]-63]='')
    then
    begin
     edit2.text:='Элемент  "'+stroka+'"  не найден!';
     edit4.text:='';
     goto 4;
      end;
                  if StringGrid2.cells[1,hash[k]-63]<>''
                  then   begin
                  l:=l+1;
                  if  (StringGrid2.cells[1,hash[k]-63]=stroka)  then
                  begin
                  kolf:=kolf+1;
                  edit2.text:='Элемент  "'+stroka+'"  найден! Его номер: '+ StringGrid2.cells[0,hash[k]-63];
                  edit4.Text:=floattostr(kolf);
                  goto 4;
                  end;
                  if  (StringGrid2.cells[1,hash[k]-63]<>stroka)  then
                 begin
                 kolf:=kolf+1;
                 edit4.Text:=floattostr(kolf);
                 k:=k+1;
                 goto 3;
                 end;
                 end;
                 end;

    4:        end;

  edit4.Text:=inttostr(kolf);
  edit6.Text:=floattostr(kolf/l2);
  el:=EditSearch.text;
  kolll:=0;
  min:=0;
  for i:=0 to (memo5.lines.count) do
   begin
  if(stringgrid1.cells[1,i+1]<>'') then begin  y:=y+1;  end;
   end;
   max:=y+1;
   p:=l2;
   a:=EditSearch.Text;
   sr1:=(max+min) div 2;
   while (StringGrid1.Cells[1,sr]<>a) and (max-min<>1) do
    begin
      sr:=(max+min) div 2;
           if (StringGrid1.Cells[1,sr]>a){ or (StringGrid1.Cells[1,sr]='') }then
            begin
               max:=sr;
               koll:=koll+1;
              end
           else   if (StringGrid1.Cells[1,sr]<a) {or (StringGrid1.Cells[1,sr]='')} then
            begin
             min:=sr;
             koll:=koll+1;
             end;
  5:  end;
 if  (StringGrid1.Cells[1,sr]=a)then
 begin
 koll:=koll+1;
 Edit5.Text:='Элемент "'+stroka+'" найден.Его №:'+ IntToStr(sr);
    edit7.Text:= inttostr(koll);
    str(1+log2(l2):5:3,s2);
   edit8.Text:=s2;
 end ;
 if  (StringGrid1.Cells[1,sr]<>a)  then
 begin
 edit7.Text:= '';
 edit8.Text:= '';
 edit6.Text:= '';
 edit4.Text:= '';
 Edit5.Text:='Элемент  '+'"'+stroka+ '"'+ '  не найден!';
 end;
 if (StringGrid1.Cells[1,sr]='')then
  begin
 edit7.Text:= '';
 edit8.Text:= '';
 edit6.Text:= '';
 edit4.Text:= '';
 Edit5.Text:='Элемент не введён!';
 end;
 end;

//************************************* Упорядоченный список *******************
procedure TForm1.Button2Click(Sender: TObject);
var a,b,buf:string; k,ss,i,min,max,p,j,sr,f:integer;
begin
for i:=1 to 244 do
 begin
   StringGrid1.Cells[1,i]:='';{очистка ТИ при повторном ее создании}
 end;
k:=0;
p:=Memo5.Lines.Count;{определение количества идентификаторов}
if p>1 then StringGrid1.Cells[1,1]:=Memo5.Lines[0];
for i:=1 to p-1 do
 begin
   f:=0;
   min:=0;
   max:=199;
   a:=Memo5.Lines[i];{в a заносится i-й идентификатор}
   while max-min<>1 do
    begin
      sr:=(max+min) div 2;
      if  StringGrid1.Cells[1,sr]=a then
       begin
         Memo6.Lines[k]:=a;
         k:=k+1;
         f:=1;
         break;
       end
        else
           if (StringGrid1.Cells[1,sr]>a) or (StringGrid1.Cells[1,sr]='') then
              max:=sr
           else
              min:=sr;
    end;
    j:=198;
   if f=0 then
     begin  while j>min do
       begin
         StringGrid1.Cells[1,j+1]:=StringGrid1.Cells[1,j];
          j:=j-1;
       end;
       StringGrid1.Cells[1,max]:=a;
     end;
 end;
end;


procedure TForm1.BtnExitClick(Sender: TObject);
begin
Form1.Close;
end;


procedure TForm1.Button6Click(Sender: TObject);
var i:integer;
begin
for i:=0 to memo1.Lines.Count-1 do memo1.Lines[i]:='';
for i:=1 to 445 do StringGrid3.Cells[1,i]:='';
for i:=1 to 445 do StringGrid1.Cells[1,i]:='';
for i:=1 to 445 do StringGrid3.Cells[2,i]:='';
for i:=1 to 445 do StringGrid3.Cells[0,i]:='';
for i:=1 to 445 do StringGrid2.Cells[1,i]:='';
for i:=0 to memo2.Lines.Count-1 do memo2.Lines[i]:='';
for i:=0 to memo3.Lines.Count-1 do memo3.Lines[i]:='';

EditSearch.text:='';
Edit1.text:='';
Edit2.text:='';
Edit3.text:='';
Edit4.text:='';
Edit5.text:='';
Edit7.text:='';
end;
procedure TForm1.Button11Click(Sender: TObject);
 begin
   if OpenDialog1.Execute then
   begin
   Memo1.Lines.LoadFromFile(OpenDialog1.FileName)  ;
   Memo3.Lines.LoadFromFile(OpenDialog1.FileName)  ;
   end;
end;
end.
Соседние файлы в папке 23-2
  • #
    02.05.201442 Кб22fd.dcu
  • #
    02.05.201451 б21fd.ddp
  • #
    02.05.201410 Кб21fd.dfm
  • #
    02.05.201487 Кб22fd.pas
  • #
    02.05.2014386 б21nknjk.cfg
  • #
    02.05.20142 Кб21nknjk.dof
  • #
    02.05.2014179 б21nknjk.dpr
  • #
    02.05.2014876 б21nknjk.res
  • #
    02.05.2014747 б21ProjectGroup1.bpg