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

interface

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

type



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


  public
  procedure  TabID(str:string);
  procedure Shirina();
  procedure Prosto(str:string;nomer:integer);
  //procedure Sort ();
     end;


var
  Form1: TForm1;
  ukazatel,knop1,knop,vssrav,nomer:integer;
  HashArray : Array[0..500,1..2] of string;
  MetSpisok: Array[0..500,1..2] of string;
  srsrav,srsrav1,vssrav1:real;



 implementation

uses Unit2;

{$R *.dfm}


procedure TForm1.vCreat(Sender: TObject);
 begin
StringGrid1.Cells[0,0]:='Номер';
StringGrid1.Cells[1,0]:='Лексема';
StringGrid1.Cells[2,0]:='Инфа';
 nomer:=0;
ukazatel:=0;
srsrav:=0;
  knop:=0;
  vssrav:=0;
  srsrav1:=0;
  knop1:=0;
  vssrav1:=0;


 end;

procedure TForm1.Button3Click(Sender: TObject);
begin
  { Выход из программы }
  Close;
end;


function Xesh(St:string):integer; {процедура вычисление значения хэш-функции}
var dlina:integer;
    twosyb:char;
    fivesyb:char;
begin
dlina:=length(St);
if dlina=0 then  Result:=0 else
                          begin
                          if dlina>=4 then       begin
                                          twosyb:=St[2];
                                          fivesyb:=St[5];
                                           Result:=ord(fivesyb)+ord(twosyb);
                                                 end
                         else       begin
                         twosyb:=St[2];
                         Result:=ord( twosyb);
                                   end;

                            end;
end;

procedure TForm1.Prosto(str:string;nomer:integer);

begin


MetSpisok[nomer,1]:=IntToStr(nomer);
MetSpisok[nomer,2]:=str ;
listbox2.Items.Add(MetSpisok[nomer,1]+' '+MetSpisok[nomer,2]);

 end;

procedure  TForm1.TabID(str:string)   ;
 var i,k,dlina,hash,j,f,kol:integer;
    stroka:string;
label 1,2;
begin

   j:=0;
   k:=2;
   kol:=0;
   ukazatel:=0;
  hash:=Xesh(str);

           if HashArray[hash,1]=''  then
             begin
              HashArray[hash,1]:=IntToStr(hash);
              HashArray[hash,2]:=str;
            listbox1.Items.Add(HashArray[hash,1]+' '+HashArray[hash,2]);
               inc(nomer);
              Prosto(str,nomer);
              end
           else
             begin
  1:           if (HashArray[hash,2])=str  then
                 begin
                  kol:=kol+1;
                   memo2.Lines.Add('Удален повтор '+str);
                   j:=j+1;
                   ukazatel:=ukazatel+1;
                   goto 2;
                 end
               else
                 begin
                 memo2.Lines.Add('Коллизия элемент - ('+str+')  ('+HashArray[hash,2]+') -'+HashArray[hash,1]);
                  kol:=kol+1;
                  hash:=(Xesh(str)+k) mod 509;
                  if (HashArray[hash,1])='' then
                    begin

                      HashArray[hash,1]:=IntToStr(hash);
                      HashArray[hash,2]:=str;
                      inc(nomer);
                       inc(k);
                      listbox1.Items.Add(HashArray[hash,1]+' '+HashArray[hash,2]);
                      Prosto(str,nomer);
                     end
                  else
                    begin
                      inc(k);
                      goto 1;
                    end;
                 end;

 2:

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

end;

 end;

{procedure TForm1.Sort ();
var i,j,z,M,N:integer;
    B:string;
    label me;
begin
n:=500;
for i:=1 to N do
                begin
                if HashArray[i,1]=' ' then break else begin
                                                        B:=HashArray[i,1]; M:=i;
                                                         end;
                      for j:=i-1 DownTo 1 do begin
                                         if (HashArray[j,1] <= B) or (HashArray[j,1]=' ') then break;
                                         HashArray[M,1]:= HashArray[j,1]; M:=j;
                                             end;
                 if HashArray[i,1]=' ' then break else HashArray[M,1]:=B;

                  end;
for z:=0 to N do begin
     if (HashArray[z,2]<>' ') then listbox1.Items.Add(HashArray[z,1]+' '+HashArray[z,2]);
                 end;


end;
}




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


label met1,met2;
begin

  inc(knop);
   k:=2;
  srav:=0;
  stroka:=Edit2.Text;
  if stroka='' then
    begin
      memo2.Lines.add('Поле пусто!');
      Abort ;
   end;
  dlina:=memo1.Lines.Count;
  hash:=Xesh(stroka);
  for i:=0 to 500 do
    begin
      inc(srav);
        if HashArray[hash,1]=IntToStr(hash) then
          begin
          if stroka=HashArray[hash,2] then
            begin

              memo2.Lines.Add('Иден-р  '+stroka+' найден! Его номер '+ IntToStr(hash));
              goto met1;
            end
          else
            begin
              for j:=0 to 500 do
               begin
                inc(srav);
                hash:=(Xesh(stroka)+k) mod 499;
                 inc(k);
                if HashArray[hash,1]=IntToStr(hash) then
                  begin
                    if stroka=HashArray[hash,2] then
                      begin

                        memo2.Lines.Add('Иден-р  '+stroka+'  найден! Его номер '+ IntToStr(hash));
                        goto met1;
                      end;
                   end;
                //else memo2.Lines.Add('Иден-р  '+stroka+'  не найден!');
               end;
            end;
        end
      else begin
        memo2.Lines.add('Иден-р  '+stroka+'  не найден!');

       abort;
       end;
    end;
met1: Label4.Caption:='Номер '+inttostr(hash); { Номер}
      Label6.Caption:='Кол-во сравнений '+inttostr(srav); {Кол-во сравнений}
      dlina:=memo1.Lines.Count;
      vssrav:=vssrav+srav;

      srsrav:=vssrav/dlina;
      label8.Caption:='Среднее кол-во сравнений '+floattostr(srsrav); {Среднее кол-во сравнений}
      label9.Caption:='Кол-во поисков '+inttostr(knop); {Кол-во поисков}
      vssrav:=0;
      srsrav:=0;

end;

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




procedure TForm1.Button4Click(Sender: TObject);
begin
form2.show;
end;




procedure TForm1.Button5Click(Sender: TObject);
var i,dlina,srav:integer;
 stroka:string;

 label met1;
begin

  Inc(knop1);
 stroka:=Edit2.Text;
 dlina:=listbox2.Items.Count;
 if stroka='' then
    begin
      memo2.Lines.add('Поле пусто!');
      Abort;
    end;

for i:=0 to nomer-1 do
    begin
      srav:=srav+1;
      if  MetSpisok[i,2]=stroka then begin
                                        label10.Caption:='Номер '+inttostr(i) ;
                                        label14.Caption:='Кол-во сравнений '+inttostr(srav);
                                        label12.Caption:='Кол-во поисков '+inttostr(knop1);
                                         Memo2.lines.add('Найден - '+stroka);
                                        goto met1;
                                      end;

    end;
     Memo2.Lines.Add('не найден ');
met1:
 vssrav1:=vssrav1+srav;
 srsrav1:=vssrav1/dlina;
  label11.Caption:='Среднее кол-во сравнений: '+floattostr(srsrav1);

end;

procedure TForm1.Button6Click(Sender: TObject);   //сброс
var i,j: integer;
begin

  for i:=0 to 500 do  MetSpisok[i,1]:='';
  for i:=0 to 500 do  MetSpisok[i,2]:='';
  for i:=0 to 500 do HashArray[i,1]:='';
  for i:=0 to 500 do HashArray[i,2]:='';
  for i:=0 to memo1.Lines.Count-1 do memo1.Lines[i]:='';
  for i:=0 to memo2.Lines.Count-1 do memo2.Lines[i]:='';
  for j:=0 to 2 do begin
  for i:=0 to 350 do   StringGrid1.Cells[j,i]:=' '  end;

  Edit2.Text:='';
  listbox1.Clear;
  listbox2.Clear;
  nomer:=0;
  nomer:=0;
  ukazatel:=0;
  srsrav:=0;
  knop:=0;
  vssrav:=0;
  srsrav1:=0;
  knop1:=0;
  vssrav1:=0;
   label10.Caption:='Номер ' ;
   label14.Caption:='Кол-во сравнений ';
   label12.Caption:='Кол-во поисков ';
   Label4.Caption:='Номер ' ;
   Label5.Caption:='Кол-во коллизий  ' ;
   Label6.Caption:='Кол-во сравнений ';
   label8.Caption:='Среднее кол-во сравнений ';
   label9.Caption:='Кол-во поисков ' ;
  
end;

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

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

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

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

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

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

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

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

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

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

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


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

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

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

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

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

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

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

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

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

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



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



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

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

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

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

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

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

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

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

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

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

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

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

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

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


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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



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

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


 end;
end;
 Shirina();
 //Sort ();
end;


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