[原创]中文编程pascal代码

作者在 2007-02-14 23:59:00 发布以下内容

program SKCP(input,output);
{孙锴中国 2005年}
{中文编程 V0.5版}
label
100,1000;

var
z:char;

procedure SKBY;

var
x,y:char;
a,b,c:integer;
M,W,N:string;
SKfile1,SKfile2,SKfile3:text;

procedure SK3;
begin
while eof(SKfile1)=false do
begin
read(SKfile1,x);
if (x=';')then begin
writeln(SKfile3); write(SKfile3,x); end
else if (x='(') or (x='[') then begin
writeln(SKfile3); write(SKfile3,x); end
else if (x=' ') then begin
writeln(SKfile3); writeln(SKfile3,x); end
else write(SKfile3,x);
end;
end;

procedure SK2;
begin
if N='变量' then begin N:='var'; c:=0 end;
if N='整数' then begin N:='integer'; c:=0 end;
if N='开始' then begin N:='begin'; c:=0 end;
if N='读取' then begin N:='readln'; c:=0 end;
if N='输出' then begin N:='writeln'; c:=0 end;
if N='结束' then begin N:='end'; c:=0 end;
if N='如果' then begin N:='if'; c:=0 end;
if N='那么' then begin N:='then'; c:=0 end;
if N='函数' then begin N:=''; c:=0 end;
if N='过程' then begin N:='procedure'; c:=0 end;
if N='当' then begin N:='while'; c:=0 end;
if N='就' then begin N:='do'; c:=0 end;
if N='平方' then begin N:='SQR'; c:=0 end;
if N='开方' then begin N:='SQRT'; c:=0 end;
if N='实数' then begin N:='real'; c:=0 end;
if N='字符' then begin N:='char'; c:=0 end;
if N='重复' then begin N:='repeat'; c:=0 end;
if N='直到' then begin N:='until'; c:=0 end;
if N='与' then begin N:='and'; c:=0 end;
if N='或' then begin N:='or'; c:=0 end;
if c=0 then write(SKfile2,N);
end;

procedure SK1;
begin
a:=1;
while eoln(SKfile3)=false do
begin
read(SKfile3,N);
SK2;
a:=a+1;
if c=0 then
begin
a:=1;
N:='';
c:=1;
end;
end;
write(SKfile2,N);
end;

begin
write('输入你欲编译的 SK-CHINA中文编程源文件(*.SCP) 文件路径/文件名:');
readln(M);
assign(SKfile1,M);
reset(SKfile1);
assign(SKfile3,'Temporary');
rewrite(SKfile3);
write('输入你欲编译后的 SK-CHINA中文编程PASCAL类文件(*.PAS) 文件路径/文件名:');
readln(W);
assign(SKfile2,W);
rewrite(SKfile2);
SK3;
close(SKfile3);
assign(SKfile3,'Temporary');
reset(SKfile3);
while eof(SKfile3)=false do
begin
SK1; readln(SKfile3); writeln(SKfile2);
end;
write(SKfile2,'.');
close(SKfile1);
close(SKfile2);
close(SKfile3);
write('编译完毕!');
end;

begin
writeln('        *                            HELP:      ');
writeln('       ***  __  SK-CHINA  [1] Edit and translate');
writeln('      ***** ||   Chinese  ');
writeln('     ******* |   Program  ');
writeln('    *********             ');
writeln('   *|  _ _  |*   [SK-CP]  ');
writeln('    | |_|_| |             ');
writeln('    | |_|_| |             ');
writeln('    |_______| 2005.11.25  [8] ABOUT [9] EXIT');
writeln('                          [H] HELP');
writeln('         Welcome!         ');
writeln;
100:writeln('What do you want to do?[1-9]');
readln(z);
case z of
'1': SKBY;
'8': begin
writeln('SK-CHINA 孙锴中国');
writeln('基于PASCAL的中文编程');
writeln('中文编程V 0.5');
writeln('2005.11.25');
end;
'9': goto 1000;
end; goto 100;
1000:end.

原创作品 | 阅读 2239 次
文章评论,共0条
游客请输入验证码