📄 structk.~pa
字号:
scansisi:=temp;
entercan:=fensensi.init2(0);
now:=scansisi;
count:=1;
end
else
begin
now:=scansisi;
ifexit:=false;
repeat
if now.isequal(temp)
then ifexit:=true;
now:=now.link;
until (now=nil) or ifexit;
if ifexit
then temp.done
else
begin
now:=scansisi;
enternow:=entercan;
while now.link<>nil do
begin
now:=now.link;
enternow:=enternow.link;
end;
now.link:=temp;
enternow.link:=fensensi.init2(0);
count:=count+1;
end;
end;
end;
end;
Procedure cansensi.add2(p:fensensi);
begin
if scansisi=nil
then
begin
scansisi:=fensensi.init3(p);
now:=scansisi;
count:=1;
end
else
begin
now:=scansisi;
while now.link<>nil do
begin
now:=now.link;
end;
now.link:=fensensi.init3(p);
count:=count+1;
end;
end;
Destructor cansensi.Done;
var temp:fensensi;
begin
now:=scansisi;
enternow:=entercan;
if first<>nil
then first.done;
if fellow<>nil
then fellow.done;
if parent<>nil
then parent.done;
if synch<>nil
then synch.done;
if now<>nil
then
begin
while now.link<>nil do
begin
temp:=now.link;
now.Done;
now:=temp;
if (enternow<>nil) and (enternow.link<>nil)
then
begin
temp:=enternow.link;
enternow.done;
enternow:=temp;
end;
end;
now.Done;
if enternow<>nil
then enternow.Done;
end;
inherited destroy;
end;
procedure cansensi.sunsetsi;
begin
now.setsi;
enternow.setsi;
end;
procedure cansensi.setsi(index:integer);
var i:integer;
begin
now:=scansisi;
enternow:=entercan;
i:=index;
while i>1 do
begin
now:=now.link;
if enternow<>nil
then enternow:=enternow.link;
i:=i-1;
end;
now.setsi;
if enternow<>nil
then enternow.setsi;
end;
function cansensi.get:sword;
begin
get.index:=now.get.index;
get.res:=now.get.res;
end;
function cansensi.next:boolean;
begin
if now.link<>nil
then
begin
now:=now.link;
now.setsi;
if enternow<>nil
then
begin
enternow:=enternow.link;
if enternow<>nil
then enternow.setsi;
end;
next:=false;
end
else
begin
next:=true;
end;
end;
function cansensi.ifeof:boolean;
begin
if now.link=nil
then ifeof:=true
else ifeof:=false;
end;
function cansensi.sunnext:boolean;
begin
sunnext:=now.next;
enternow.next;
end;
function cansensi.sunpre:boolean;
begin
sunpre:=now.pre;
enternow.pre;
end;
function cansensi.sunifeof:boolean;
begin
sunifeof:=now.ifeof;
end;
procedure cansensi.setflag(f:boolean);
begin
now.setflag(f);
end;
procedure cansensi.addfirst(index:integer);
var j:integer;
begin
if first.add(index)
then parent.res:=true;
end;
procedure cansensi.addfellow(index:integer);
var j:integer;
begin
if fellow.add(index)
then parent.res:=true;
end;
procedure cansensi.refreshff;
begin
first.emtry;
fellow.emtry;
synch.emtry;
setsi(1);
if enternow<>nil
then
begin
while enternow.link<>nil do
begin
enternow.emtry;
enternow:=enternow.link;
end;
enternow.emtry;
enternow:=entercan;
end;
end;
function cansensi.getcanssi:string;
var temp:string;
temp1:string;
begin
temp:='';
now:=scansisi;
while now.link<>nil do
begin
temp:=temp+now.getcanssi+'|';
now:=now.link;
end;
temp:=temp+now.getcanssi;
temp1:=form1.findname(parent.index);
temp:=temp1+'='+temp;
getcanssi:=temp;
end;
function cansensi.getnewcanssi:string;
var temp:string;
temp1:string;
begin
temp:='';
now:=scansisi;
while now.link<>nil do
begin
temp:=temp+now.getnewcanssi+'|';
now:=now.link;
end;
temp:=temp+now.getnewcanssi;
temp1:=form1.findnewname(parent.index);
temp:=temp1+'='+temp;
getnewcanssi:=temp;
end;
function cansensi.subfuhao(index:integer):boolean;
var temp:fensensi;
temp1:fensensi;
begin
now:=scansisi;
enternow:=entercan;
repeat
if now.subfuhao(index)
then
begin
count:=count-1;
if now=scansisi
then
begin
scansisi:=scansisi.link;
entercan:=entercan.link;
now.done;
enternow.done;
now:=scansisi;
enternow:=entercan;
end
else
begin
temp.link:=now.link;
temp1.link:=enternow.link;
now.done;
enternow.done;
now:=temp.link;
enternow:=temp1.link;
end;
end
else
begin
temp:=now;
now:=now.link;
temp1:=enternow;
enternow:=enternow.link;
end;
until now=nil;
if scansisi=nil
then subfuhao:=true
else subfuhao:=false;
end;
procedure cansensi.change(cs:cansenjh); (*在消除左递归中替换第一个非终结符*)
var i:integer;
begin
now:=now.change(cs,i);
count:=count+i;
end;
function cansensi.change1(cs:cansenjh):integer;
var ifend:boolean;
temp:cansensi;
t1,t2,t3:fensensi;
m:mfuhao;
begin
now:=scansisi;
now.setsi;
ifend:=false;
now.setsi;
repeat
if now.get.index=parent.index
then ifend:=true;
until next or ifend;
if ifend
then
begin
form1.fzjnumnew:=form1.fzjnumnew+1;
form1.fzjfuhaonew[form1.fzjnumnew].name:='添加符号'+form1.findname(parent.index);
form1.fzjfuhaonew[form1.fzjnumnew].index:=form1.fzjnumnew+300;
temp:=cansensi.init2(form1.fzjnumnew+300);
now:=scansisi;
m:=mfuhao.init(form1.fzjnumnew+300);
t2:=nil;
while now<>nil do
begin
t1:=fensensi.init3(now);
t1.add2(m);
now.setsi;
if now.get.index=parent.index
then
begin
if now.ifeof
then
begin
t1.done;
m.done;
temp.done;
change1:=-1*now.get.index;
exit;
end;
t1.subfuhao(parent.index);
temp.add2(t1);
t1.done;
end
else
begin
if t2=nil
then
begin
t2:=t1;
t3:=t2;
end
else
begin
t3.link:=t1;
t3:=t3.link;
end;
end;
now:=now.link;
end;
now:=scansisi.link;
while now<>nil do
begin
scansisi.done;
scansisi:=now;
now:=now.link;
end;
scansisi.done;
scansisi:=t2;
change1:=1;
t2:=fensensi.init2(300);
temp.add2(t2);
t2.done;
cs.add2(temp);
end
else
begin
change1:=0;
end;
end;
(*****************************)
Constructor cansenjh.init;
var i:integer;
begin
for i:=1 to 500 do
begin
cans[i]:=NIL;
end;
count:=0;
end;
function cansenjh.ifhave(index:integer):boolean;
var i:integer;
begin
i:=1;
while (i<=count) and (index<>cans[i].parent.index) do
i:=i+1;
if i>count
then ifhave:=false
else ifhave:=true;
end;
function cansenjh.gofuhao(index:integer):integer; (*返回左部为i的产生式号码*)
var i:integer;
begin
i:=1;
while (i<=count) and (index<>cans[i].parent.index) do
i:=i+1;
if i>count
then gofuhao:=-1
else gofuhao:=i;
end;
Destructor cansenjh.done;
var i:integer;
begin
for i:=1 to count do
begin
cans[i].done;
end;
inherited destroy;
end;
procedure cansenjh.add(s:string);
begin
count:=count+1;
cans[count]:=cansensi.init(s);
end;
procedure cansenjh.add2(p:cansensi); (*增加产生式,注意p不要被删除*)
begin
count:=count+1;
cans[count]:=p;
end;
procedure cansenjh.add3(p:cansensi); (*增加产生式,P可以被删除*)
begin
count:=count+1;
cans[count]:=cansensi.init3(p);
end;
procedure cansenjh.exchange(h:integer;s:string);
begin
cans[h].done;
cans[h]:=cansensi.init(s);
end;
procedure cansenjh.delete(d:integer);
var i:integer;
begin
if (d<count)
then
begin
cans[d].done;
for i:=d to count-1 do
begin
cans[i]:=cans[i+1];
end;
count:=count-1;
end
else
begin
if d=count
then
begin
cans[d].done;
count:=count-1;
end;
end;
end;
(*****************************************)
constructor item.init(p:fensensi;par:mfuhao); (*初始化项目,s 为单产生式,*)
begin
p.setsi;
inherited init3(p);
parent:=mfuhao.init(par.index);
position:=0;
link:=nil;
act.nextfuhao:=-1;
act.act:=-1;
end;
constructor item.init2(p:item;o:integer); (*初始化项目,p 为样本项目,o为位置*)
begin
p.setsi;
inherited init3(p);
parent:=mfuhao.init(p.parent.index);
position:=o;
link:=nil;
act.nextfuhao:=p.getaction.nextfuhao;
act.act:=p.getaction.act;
end;
constructor item.init3(s:string);
(*初始化项目,s为存盘信息 ,s 结构position (int),nextfuhao (string),act (int),parent(string),产生式 (string)*)
var i:integer;
temp:string;
p:integer;
begin
wordlist:=nil;
now:=nil;
i:=1;
temp:='';
while (i<=length(s)) and (s[i]<>' ') do
begin
temp:=temp+s[i];
i:=i+1;
end;
try
p:=strtoint(temp);
except
act.act:=-3;
exit;
end;
position:=p;
temp:='';
i:=i+1;
while (i<=length(s)) and (s[i]<>' ') do
begin
temp:=temp+s[i];
i:=i+1;
end;
if temp=''
then
begin
act.act:=-3;
exit;
end;
if temp='@@@@@@@@@@'
then act.nextfuhao:=-1
else
begin
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -