📄 unit1.~pa
字号:
begin
j:=emtry.get.index;
stringgrid10.cells[0,i]:=inttostr(j);
stringgrid10.cells[1,i]:=findnewname(j);
stringgrid12.cells[0,i]:=inttostr(i);
z:=ccssnew.gofuhao(j);
stringgrid12.cells[1,i]:=ccssnew.cans[z].getnewcanssi;
i:=i+1;
end;
stringgrid11.rowcount:=zjnum+1;
for i:=1 to zjnum do
begin
stringgrid11.cells[0,i]:=inttostr(zjfuhao[i].index);
stringgrid11.cells[1,i]:=zjfuhao[i].name;
end;
end;
procedure TForm1.Save2Click(Sender: TObject);
begin
savenew;
end;
procedure TForm1.Saveas2Click(Sender: TObject);
begin
if not cansave
then
begin
application.Messagebox('未生成新分析表!', '中止', mb_Ok+MB_ICONHAND);
exit
end;
savefxas;
end;
function Tform1.openfxf:boolean;
var f:textfile;
temp,temp1:String;
ifend:boolean;
temp2:string;
i,j:integer;
temp3:integer;
begin
if fileexists(filename)
then
begin
AssignFile(F,FileName);
try
reset(f);
except
application.Messagebox('文件打不开!', '中止', mb_Ok);
openfxf:=false;
exit;
end;
try
ifend:=eoln(f);
except
application.Messagebox('文件格式不对!', '中止', mb_Ok);
closefile(f);
openfxf:=false;
exit;
end;
try
readln(f,temp);
except
application.Messagebox('文件格式不对!', '中止', mb_Ok);
closefile(f);
openfxf:=false;
exit;
end;
if temp<>'[终结符号]'
then
begin
application.Messagebox('文件格式不对!', '中止', mb_Ok);
closefile(f);
openfxf:=false;
exit;
end;
while not ifend and (temp<>'[LL1文法]') do
begin
try
readln(f,temp);
except
application.Messagebox('文件格式不对!', '中止', mb_Ok);
closefile(f);
openfxf:=false;
exit;
end;
if temp<>'[LL1文法]'
then
begin
i:=1;
temp2:='';
while (i<=length(temp))and (temp[i]<>' ') do
begin
temp2:=temp2+temp[i];
i:=i+1;
end;
if i>=length(temp)
then
begin
application.Messagebox('文件格式不对!', '中止', mb_Ok);
closefile(f);
openfxf:=false;
exit;
end;
try
zjfuhao[zjnum+1].index:=strtoint(temp2);
except
application.Messagebox('文件格式不对!', '中止', mb_Ok);
closefile(f);
openfxf:=false;
exit;
end;
temp1:='';
for i:=i+1 to length(temp) do
begin
temp1:=temp1+temp[i];
end;
zjnum:=zjnum+1;
zjfuhao[zjnum].name:=temp1;
stringgrid3.rowcount:=zjnum+1;
stringgrid3.cells[0,zjnum]:=temp2;
stringgrid3.cells[1,zjnum]:=temp1;
end;
ifend:=eoln(f);
end;
while (not eoln(f)) and (temp<>'[LL1分析表]') do
begin
try
readln(f,temp);
except
application.Messagebox('文件格式不对!', '中止', mb_Ok);
closefile(f);
openfxf:=false;
exit;
end;
if temp<>'[LL1分析表]'
then
begin
Dprod.edit1.text:=temp;
Dprod.anaysis;
if Dprod.addnum>0
then
begin
j:=1;
while j<=Dprod.addnum do
begin
addfzjfuhao(Dprod.addfuhao[j]);
j:=j+1;
end;
end;
ccss.add(dprod.edit1.text);
stringgrid2.rowcount:=ccss.count+1;
stringgrid2.cells[0,ccss.count]:=inttostr(ccss.count);
stringgrid2.cells[1,ccss.count]:=temp;
end;
end;
for i:=1 to ccss.count do
begin
ccss.cans[i].setsi(1);
repeat
try
readln(f,temp);
except
application.Messagebox('文件不正确!', '中止', mb_Ok);
closefile(f);
openfxf:=false;
exit;
end;
temp1:='';
for j:=1 to length(temp) do
begin
if temp[j]<>' '
then
begin
temp1:=temp1+temp[j];
end
else
begin
temp3:=findindex(temp1);
ccss.cans[i].enternow.add(temp3);
temp1:='';
end;
end;
if temp1<>''
then
begin
temp3:=findindex(temp1);
ccss.cans[i].enternow.add(temp3);
end;
until ccss.cans[i].next;
try
readln(f,temp);
except
application.Messagebox('文件不正确!', '中止', mb_Ok);
closefile(f);
openfxf:=false;
exit;
end;
temp1:='';
for j:=1 to length(temp) do
begin
if temp[j]<>' '
then
begin
temp1:=temp1+temp[j];
end
else
begin
temp3:=findindex(temp1);
ccss.cans[i].synch.add(temp3);
temp1:='';
end;
end;
end;
try
readln(f,temp);
except
application.Messagebox('文件不正确!', '中止', mb_Ok);
closefile(f);
openfxf:=false;
exit;
end;
if temp<>'[First Fellow 集合]'
then
begin
application.Messagebox('文件不正确!', '中止', mb_Ok);
closefile(f);
openfxf:=false;
exit;
end
else
begin
for i:=1 to ccss.count do
begin
try
readln(f,temp);
except
application.Messagebox('文件不正确!', '中止', mb_Ok);
closefile(f);
openfxf:=false;
exit;
end;
try
readln(f,temp1);
except
application.Messagebox('文件不正确!', '中止', mb_Ok);
closefile(f);
openfxf:=false;
exit;
end;
temp2:='';
for j:=1 to length(temp) do
begin
if temp[j]<>' '
then
begin
temp2:=temp2+temp[j];
end
else
begin
if temp2<>''
then
begin
temp3:=findindex(temp2);
ccss.cans[i].first.add(temp3);
end;
temp2:='';
end;
end;
if temp2<>''
then
begin
temp3:=findindex(temp2);
ccss.cans[i].first.add(temp3);
end;
temp2:='';
for j:=1 to length(temp1) do
begin
if temp1[j]<>' '
then
begin
temp2:=temp2+temp1[j];
end
else
begin
if temp2<>''
then
begin
temp3:=findindex(temp2);
ccss.cans[i].fellow.add(temp3);
end;
temp2:='';
end;
end;
if temp2<>''
then
begin
temp3:=findindex(temp2);
ccss.cans[i].fellow.add(temp3);
end
end
end;
closefile(f);
openfxf:=true;
end
else
begin
application.Messagebox('文件不存在!', '中止', mb_Ok);
openfxf:=false;
end;
end;
procedure TForm1.Open2Click(Sender: TObject);
var i:integer;
res:boolean;
begin
OpenDialog1.Filter := 'LL1 files (*.LL1)|*.LL1';
zjnum:=0;
fzjnum:=0;
for i:=ccss.count downto 1 do
begin
ccss.delete(i);
end;
stringgrid1.rowcount:=2;
stringgrid2.rowcount:=2;
stringgrid3.rowcount:=3;
stringgrid1.cells[0,1]:='';
stringgrid1.cells[1,1]:='';
stringgrid2.cells[0,1]:='';
stringgrid2.cells[1,1]:='';
if OpenDialog1.execute
then
begin
filename:=OpenDialog1.filename;
caption:='文法转换器'+'-'+filename;
res:=openfxf;
if not res
then
begin
application.Messagebox('不正确打开文件!', '警告', mb_Ok);
end
else
begin
cansave:=true;
setview;
end;
end;
end;
procedure TForm1.About1Click(Sender: TObject);
begin
AboutBox.showmodal;
end;
function Tform1.findname(index:integer):string;
var i:integer;
begin
i:=1;
while (i<=fzjnum)and (fzjfuhao[i].index<>index) do
i:=i+1;
if i<=fzjnum
then
begin
findname:=fzjfuhao[i].name;
exit;
end;
i:=1;
while (i<=zjnum)and (zjfuhao[i].index<>index) do
i:=i+1;
if i<=zjnum
then
begin
findname:=zjfuhao[i].name;
end;
end;
function Tform1.findnewname(index:integer):string;
var i:integer;
begin
i:=1;
while (i<=fzjnumnew)and (fzjfuhaonew[i].index<>index) do
i:=i+1;
if i<=fzjnumnew
then
begin
findnewname:=fzjfuhaonew[i].name;
exit;
end;
i:=1;
while (i<=zjnum)and (zjfuhao[i].index<>index) do
i:=i+1;
if i<=zjnum
then
begin
findnewname:=zjfuhao[i].name;
end;
end;
procedure TForm1.Exit1Click(Sender: TObject);
begin
close;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -