求大家帮帮忙了啊!!!全部分都给了!!program filltable;{文件名}
type myword=record{记录类型,存储每一个扫描的单词}
code:integer; {该单词的内部编码}
content:string; {单词本身}
end;
const length=8; {单词限制的长度}var fi:text;{输入文件}
fo:text; {输出文件}
symbol:array[1..100] of myword;{定义接收不同标识符的数组}
j:integer;
noerror:boolean; {扫描过程中是否有错误}
count:integer; {不同单词的个数}
allinput:integer; {输入单词的总数}
function found(tofind:string):boolean;{true:已经有该单词;false:现有的数组中还没有该单词}
var i:integer;
begin
allinput:=allinput+1;
found:=false;
for i:=1 to count do
if symbol[i].content=tofind then found:=true;
end; procedure fillintotable;
var ch:char;
tempword:string;
i:integer;
begin
i:=0;
tempword:='';
while not eof(fi) do{是否到达文件尾}
begin
while not eoln(fi)do{是否到达行尾}
begin
read(fi,ch);
case ch of
'a'..'z','A'..'Z':if i>=8 then
begin
writeln(fo,'Error:Over length error');{长度超过}
noerror:=false;
break;
end
else
begin
tempword:=tempword+ch;
i:=i+1;
end;
'0'..'9':begin
if i>=8 then
begin
writeln(fo,'Error:Over length error');
noerror:=false;
break;
end;
if i=0 then
begin
writeln(fo,'Error:Digit first error'); {以数字开头}
noerror:=false;
break;
end
else begin
tempword:=tempword+ch;
i:=i+1;
end
end;
',': begin if not found(tempword) then
begin
count:=count+1;
symbol[count].content:=tempword;
symbol[count].code:=100+count;
end;
i:=0;
tempword:='';
end;
';':if not eof(fi) then
begin
writeln(fo,'Error:There are more than 2 ";" ');
{有两个或者两个以上的”;”}
noerror:=false;
break;
end;
else begin
noerror:=false;
writeln(fo,'Error: Illegal input symbol',ch);
{非法的字符输入}
break;
end;
end;
end;
readln(fi);{换行}
end;
end;procedure printid;
var i:integer;
begin
{结果输出到fo文件}
writeln(fo);
writeln(fo,'There are ',allinput,' symbols inputed,and');
writeln(fo,'there are ',count,' different symbols');
writeln(fo,'The different symbols and according codes are as follows');
for i:=1 to count do writeln(fo,symbol[i].code,' ', symbol[i].content);
end;begin
count:=0;
assign(fi,'myinput.txt');{将fi与myinput.txt文件关联上}
assign(fo,'myoutput.txt');{ 将fo与myoutput.txt文件关联上}
rewrite(fo);
reset(fi);
noerror:=true;
fillintotable;
close(fi);
if noerror then printid;
close(fo);
end.
type myword=record{记录类型,存储每一个扫描的单词}
code:integer; {该单词的内部编码}
content:string; {单词本身}
end;
const length=8; {单词限制的长度}var fi:text;{输入文件}
fo:text; {输出文件}
symbol:array[1..100] of myword;{定义接收不同标识符的数组}
j:integer;
noerror:boolean; {扫描过程中是否有错误}
count:integer; {不同单词的个数}
allinput:integer; {输入单词的总数}
function found(tofind:string):boolean;{true:已经有该单词;false:现有的数组中还没有该单词}
var i:integer;
begin
allinput:=allinput+1;
found:=false;
for i:=1 to count do
if symbol[i].content=tofind then found:=true;
end; procedure fillintotable;
var ch:char;
tempword:string;
i:integer;
begin
i:=0;
tempword:='';
while not eof(fi) do{是否到达文件尾}
begin
while not eoln(fi)do{是否到达行尾}
begin
read(fi,ch);
case ch of
'a'..'z','A'..'Z':if i>=8 then
begin
writeln(fo,'Error:Over length error');{长度超过}
noerror:=false;
break;
end
else
begin
tempword:=tempword+ch;
i:=i+1;
end;
'0'..'9':begin
if i>=8 then
begin
writeln(fo,'Error:Over length error');
noerror:=false;
break;
end;
if i=0 then
begin
writeln(fo,'Error:Digit first error'); {以数字开头}
noerror:=false;
break;
end
else begin
tempword:=tempword+ch;
i:=i+1;
end
end;
',': begin if not found(tempword) then
begin
count:=count+1;
symbol[count].content:=tempword;
symbol[count].code:=100+count;
end;
i:=0;
tempword:='';
end;
';':if not eof(fi) then
begin
writeln(fo,'Error:There are more than 2 ";" ');
{有两个或者两个以上的”;”}
noerror:=false;
break;
end;
else begin
noerror:=false;
writeln(fo,'Error: Illegal input symbol',ch);
{非法的字符输入}
break;
end;
end;
end;
readln(fi);{换行}
end;
end;procedure printid;
var i:integer;
begin
{结果输出到fo文件}
writeln(fo);
writeln(fo,'There are ',allinput,' symbols inputed,and');
writeln(fo,'there are ',count,' different symbols');
writeln(fo,'The different symbols and according codes are as follows');
for i:=1 to count do writeln(fo,symbol[i].code,' ', symbol[i].content);
end;begin
count:=0;
assign(fi,'myinput.txt');{将fi与myinput.txt文件关联上}
assign(fo,'myoutput.txt');{ 将fo与myoutput.txt文件关联上}
rewrite(fo);
reset(fi);
noerror:=true;
fillintotable;
close(fi);
if noerror then printid;
close(fo);
end.
改C++供c++builder编译还简单点.
c++builder好像可以直接使用pas文件的