if s=mas_of_net[i] then begin flagb:=true; break; end;

  if flagb=true then tt. Color:=clAqua

  else tt. Color:=clwhite;

  tt. Width:=30;

  tt. Height:=20;

  inc(fg);

  end;

  end;

//----------------

//---------------

procedure TForm2.Button5Click(Sender: TObject);

var

s, tmp1,tmp2,prod, prod1,xz, symb, s1,sx, sy, sx1,sy1,st:string;

k:integer;

label lb;

begin

Button8.Enabled:=true;

vhod:='';

stack:='';

if ((Checkbox1.Checked=true) and (stringgrid6.Cells[0,1]<>'')) or ((Checkbox1.Checked=false) and (stringgrid6.Cells[0,1]<>'')) then goto lb;

setlength(prav, Listbox1.Count);

for j:=0 to Listbox1.Count-1 do

begin

s:=Listbox1.Items. Strings[j];

prav[j]:=s;

end;

count:=1;

vhod:=Form2.Edit1.text+'$';

//Vhod:=vhod+'$';

vh1:=vhod;

stack:='$';

st1:=stack;

form2.stringgrid6.Cells[0,count]:=inttostr(count);

form2.stringgrid6.Cells[1,count]:=vhod;

form2.stringgrid6.Cells[2,count]:=stack;

form2.stringgrid6.Cells[3,count]:='';

form2.stringgrid6.rowCount:=count+1;

repeat

lb:

stack:=st1;

vhod:=vh1;

tmp1:=newstack(stack);

tmp2:=newstr;

symb:=Get_from_table(tmp1,tmp2);

If  (symb='<') or (symb='=') then

begin

stringgrid6.Cells[3,count]:='перенос';

j:=1;

while vhod[j]<>' ' do

delete(vhod,1,1);

Stack:=stack+' '+symb+' '+tmp2;

delete(vhod,1,1);

end

  else

  If  symb='>' then

  begin

  prod:='';prod1:='';

  xz:='';

  repeat

  s1:=newstack(stack);

НЕ нашли? Не то? Что вы ищете?

  symb:=Get_from_table(nextstack, s1);

  if xz<>'' then

  xz:=s1+' '+xz

  else xz:=s1+xz;

  if symb='=' then  delst(length(s1)+3) else

  delst(length(s1)+1);

  until symb<>'=';

  for j:=0 to Listbox1.Count-1 do

  begin

  prod:=copy(prav[j],4,length(prav[j])-3);

  if xz=prod then

  begin

  prod1:=copy(prav[j],1,1);

  break;

  end;

  end;

  if prod1='' then showmessage('В грамматике нет такого правила!')

  else begin

  stack:=stack+' '+prod1;

  form2.stringgrid6.Cells[3,count]:='свертка '+prav[j];

  end;

  end

  else

  begin showmessage('Неверная синтаксическая конструкция');break;end;

inc(count);

stringgrid6.Cells[0,count]:=inttostr(count);

stringgrid6.Cells[2,count]:=stack;

stringgrid6.Cells[1,count]:=vhod;

stringgrid6.rowCount:=count+1;

Stringgrid6.Row:=count;

Form1.Refresh;

st1:=stack;

vh1:=vhod;

if Checkbox1.Checked=true then break;

until stack='$ < S';

if (stack='$ < S') and (newstr='$') then begin

Showmessage('Допуск');

Form4.Memo10.Clear;

Form4.Memo10.Lines. Add('S->');

sx:='S->';

for i:=Form2.StringGrid6.RowCount downto 1 do

begin

if copy(Form2.StringGrid6.Cells[3,i],1,1)='с' then

begin

sx1:='';

sy1:='';

s1:=copy(Form2.StringGrid6.Cells[3,i],9,1);

s:=copy(Form2.StringGrid6.Cells[3,i],12,length(Form2.StringGrid6.Cells[3,i])-11);

for j:=length(sx) downto 1 do

  begin

  if sx[j]=s1 then

  begin

  break;

  end

  else

  if (sx[j]<>'-') and (sx[j]<>'>') then

  sy1:=sx[j]+sy1;

  end;

if sy1<>'' then

if sy1[length(sy1)]=' ' then

delete(sy1,length(sy1),1);

for k:=j-2 downto 4 do

sx1:=sx[k]+sx1;

if sx1<>'' then sx1:=sx1+' ';

st:='-> '+sx1+s+sy1+' ->';

sx:=st;

Form4.Memo10.Lines. Add(st);

view_dr(s);

end;

end;

s:=Form4.Memo10.Lines. Strings[form4.Memo10.Lines. Count-1];

Form4.Memo10.Lines. Strings[form4.Memo10.Lines. Count-1]:=copy(s,1,length(s)-3);

form4.Show;

Button5.Enabled:=false;

end;

end;

procedure TForm2.Button8Click(Sender: TObject);

begin

Form4.Show;

end;

end.

unit Unit3;

interface

uses

  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

  Dialogs, Grids;

type

  TForm3 = class(TForm)

  StringGrid9: TStringGrid;

  private

  { Private declarations }

  public

  { Public declarations }

  end;

var

  Form3: TForm3;

implementation

{$R *.dfm}

end.

unit Unit4;

interface

uses

  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

  Dialogs, StdCtrls;

type

  TForm4 = class(TForm)

  Memo10: TMemo;

  private

  { Private declarations }

  public

  { Public declarations }

  end;

var

  Form4: TForm4;

implementation

{$R *.dfm}

end.

       ПРИЛОЖЕНИЕ 4

Блок-схемы алгоритмов

Рис. П4.1 Вызов лексического анализа

Рис. П4.2 Алгоритм лексического анализа

Рис. П4.3 Алгоритм синтаксического анализа

Рис. П4.4 Алгоритм построения дерева разбора


Из за большого объема этот материал размещен на нескольких страницах:
1 2 3 4 5 6 7 8 9 10 11