📄 structk.~pa
字号:
now:=wordlist;
end;
procedure fensensi.setflag(f:boolean);
begin
now.setflag(f);
end;
function fensensi.get:sword;
var temp:string;
begin
{ temp:=form1.findname(now^.index);
get.name:=temp;}
get.index:=now.index;
get.res:=now.res;
end;
function fensensi.next:boolean;
begin
if now.link =nil
then
begin
next:=true;
end
else
begin
now:=now.link;
next:=false;
end;
end;
function fensensi.pre:boolean;
var temp:mfuhao;
begin
temp:=wordlist;
if temp=now
then
begin
pre:=true;
end
else
begin
while temp.link<>now do
temp:=temp.link;
now:=temp;
pre:=false;
end;
end;
function fensensi.ifeof:boolean;
begin
if now.link=nil
then
begin
ifeof:=true;
end
else
begin
ifeof:=false;
end;
end;
function fensensi.add(index:integer):boolean;
var temp:mfuhao;
begin
if wordlist.link=nil
then
begin
wordlist.link:=Mfuhao.init(index);
now:=wordlist;
add:=true;
end
else
begin
temp=now;
now:=wordlist.link;
while (now.link<>nil) and (now.index<>index) do
begin
now:=now.link;
end;
if now.index<>index
then
begin
while (now.link<>nil) do
begin
now:=now.link;
end;
now.link:=Mfuhao.init(index);
add:=true;
end
else
begin
add:=false;
end;
now=temp;
end;
end;
function fensensi.ifhave(index:integer):boolean;
begin
if (wordlist=nil) or (wordlist.link=nil)
then
begin
ifhave:=false;
exit;
end;
now:=wordlist.link;
while (now.link<>nil) and (now.index<>index) do
begin
now:=now.link;
end;
ifhave:=(now.index=index);
end;
procedure fensensi.clear;
var temp:Mfuhao;
begin
now:=wordlist;
while now.link<>nil do
begin
temp:=now;
now:=now.link;
temp.done;
end;
now.done;
wordlist:=nil;
now:=nil;
end;
procedure fensensi.emtry;
var temp:Mfuhao;
begin
now:=wordlist.link;
if now<>nil
then
begin
while (now.link<>nil) do
begin
temp:=now.link;
now.done;
now:=temp;
end;
now.done;
end;
now:=wordlist;
now.link:=nil;
end;
function fensensi.getcanssi:string;
var temp:string;
temp1:string;
begin
temp:='';
now:=wordlist;
while now.link<>nil do
begin
temp1:=form1.findname(now.index);
temp:=temp+' '+temp1;
now:=now.link;
end;
temp1:=form1.findname(now.index);
temp:=temp+' '+temp1;
getcanssi:=temp;
end;
function fensensi.getnewcanssi:string;
var temp:string;
temp1:string;
begin
temp:='';
now:=wordlist;
while now.link<>nil do
begin
temp1:=form1.findnewname(now.index);
temp:=temp+' '+temp1;
now:=now.link;
end;
temp1:=form1.findnewname(now.index);
temp:=temp+' '+temp1;
getnewcanssi:=temp;
end;
function fensensi.isequal(p:fensensi):boolean; (*针对单产生式对象,判断两产生式是否相同,相同返回TRUE*)
begin
p.setsi;
setsi;
while (get.index=p.get.index) and not(ifeof) and not(p.ifeof) do
begin
next;
p.next;
end;
if (get.index=p.get.index) and (p.ifeof) and (ifeof)
then
begin
isequal:=true;
end
else
begin
isequal:=false;
end;
end;
function fensensi.isequal2(p:fensensi):boolean; (*针对集合对象,判断两集合式是否相同,相同返回TRUE*)
begin
if p.getcount<>getcount
then
begin
isequal2:=false;
exit;
end;
p.setsi;
while not p.next do
begin
if not ifhave(p.now.index)
then
begin
isequal2:=false;
exit;
end;
end;
isequal2:=true;
end;
function fensensi.getcount:integer;
var i:integer;
begin
setsi;
i:=0;
while not next do
begin
i:=i+1;
end;
getcount:=i;
end;
function fensensi.setposition(p:integer):boolean;
var i:integer;
begin
setsi;
i:=1;
while (i<p) and not(ifeof) do
begin
next;
i:=i+1;
end;
if i=p
then
setposition:=true
else setposition:=false;
end;
function fensensi.sub(index:integer):boolean;(*针对集合类型,减去一个元素,若无这个元素返回FALSE*)
var temp:mfuhao;
begin
now:=wordlist;
temp:=now;
now:=now.link;
while (now<>nil) and (now.index<>index) do
begin
temp:=now;
now:=now.link;
end;
sub:=now<>nil;
if now<>nil
then
begin
temp.link:=now.link;
now.done;
now:=wordlist;
end;
end;
function fensensi.subfuhao(index:integer):boolean;(*针对产生式类型,减去一个元素,减后为空返回TRUE*)
var temp:mfuhao;
begin
now:=wordlist;
repeat
if now.index=index
then
begin
if now=wordlist
then
begin
wordlist:=wordlist.link;
now.done;
now:=wordlist;
temp:=now;
end
else
begin
temp.link:=now.link;
now.done;
now:=temp.link;
end;
end
else
begin
temp:=now;
now:=now.link;
end;
until now=nil;
if wordlist=nil
then subfuhao:=true
else subfuhao:=false;
end;
function fensensi.change(cs:cansenjh;var acount:integer):fensensi;
(*在消除左递归中替换第一个非终结符,返回替换产生的最后的产生式*)
var temp:Mfuhao;
temp1:Mfuhao;
i:integer;
f,f1:fensensi;
begin
temp:=wordlist;
i:=cs.gofuhao(now.index);
cs.cans[i].setsi(1);
wordlist:=mfuhao.init(cs.cans[i].now.get.index);
now:=wordlist;
while not cs.cans[i].now.next do
begin
now.link:=mfuhao.init(cs.cans[i].now.get.index);
now:=now.link;
end;
temp1:=temp.link;
add2(temp1);
f:=self;
f1:=link;
acount:=0;
while not cs.cans[i].next do
begin
acount:=acount+1;
f.link:=fensensi.init3(cs.cans[i].now);
temp1:=temp.link;
f.link.add2(temp1);
f:=f.link;
end;
f.link:=f1;
change:=f;
temp1:=temp.link;
while temp1<>nil do
begin
temp.done;
temp:=temp1;
temp1:=temp.link;
end;
temp.done;
end;
procedure fensensi.add2(p:mfuhao);
var temp:mfuhao;
begin
now:=wordlist;
while now.link<>nil do
begin
now:=now.link;
end;
temp:=p;
while temp<>nil do
begin
now.link:=mfuhao.init(temp.index);
now:=now.link;
temp:=temp.link;
end;
end;
(*****************************************)
Constructor cansensi.init(cansi:string);
var temp:string;
i:integer;
oldch:char;
j:integer;
begin
scansisi:=nil;
now:=nil;
oldch:='c';
i:=1;
count:=0;
temp:='';
while (cansi[i]<>'=') and (i<=length(cansi))do
begin
if cansi[i]<>' '
then begin
temp:=temp+cansi[i];
end;
i:=i+1;
end;
i:=i+1;
j:=form1.findindex(temp);
parent:=mfuhao.init(j);
first:=fensensi.init2(j);
fellow:=fensensi.init2(j);
synch:=fensensi.init2(j);
temp:='';
while i<=length(cansi) do
begin
case cansi[i] of
'\': begin
if oldch='\'
then
begin
temp:=temp+'\';
oldch:='a';
end
else
begin
oldch:='\';
end;
end;
'|': begin
if oldch='\'
then
begin
temp:=temp+'|';
oldch:='|';
end
else
begin
if temp<>''
then
begin
if scansisi=nil
then
begin
scansisi:=fensensi.init(temp);
now:=scansisi;
entercan:=fensensi.init2(parent.index);
enternow:=entercan;
count:=1;
end
else
begin
now.link:=fensensi.init(temp);
now:=now.link;
enternow.link:=fensensi.init2(parent.index);
enternow:=enternow.link;
count:=count+1;
end;
temp:='';
end;
end;
end;
else begin
temp:=temp+cansi[i];
end;
end;
i:=i+1;
end;
if temp<>''
then
begin
if scansisi=nil
then
begin
scansisi:=fensensi.init(temp);
now:=scansisi;
entercan:=fensensi.init2(parent.index);
enternow:=entercan;
count:=1;
end
else
begin
now.link:=fensensi.init(temp);
now:=now.link;
enternow.link:=fensensi.init2(parent.index);
enternow:=enternow.link;
count:=count+1;
end;
end;
end;
Constructor cansensi.init2(p:integer);
begin
parent:=Mfuhao.init(p);
first:=fensensi.init2(0);
fellow:=fensensi.init2(0); (*FIRST,FELLOW集合*)
synch:=fensensi.init2(0); (*同步化入口集合*)
entercan:=nil; (*入口集合链,链长与scansisi一样长,于scansisi对应位置为进入这个产生式的符号集*)
enternow:=nil; (*指向入口集合链某个位置指针*)
scansisi:=nil; (*单产生式链*)
now:=nil; (*指向单产生式链某个位置指针*)
count:=0;
end;
COnstructor cansensi.init3(p:cansensi); (*复制*)
begin
parent:=Mfuhao.init(p.parent.index);
first:=fensensi.init2(0);
fellow:=fensensi.init2(0);
synch:=fensensi.init2(0);
p.setsi(1);
scansisi:=fensensi.init3(p.scansisi);
entercan:=fensensi.init2(0);
now:=scansisi;
enternow:=entercan;
while not p.next do
begin
now.link:=fensensi.init3(p.now);
enternow.link:=fensensi.init2(0);
now:=now.link;
enternow:=enternow.link;
end;
count:=p.count;
end;
Procedure cansensi.add(p:fensensi;i:integer);
var temp:fensensi;
ifexit:boolean;
begin
temp:=fensensi.init4(p,i);
if temp.wordlist=nil
then
begin
temp.done;
end
else
begin
if scansisi=nil
then
begin
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -