Вот так сказать что на данный момент получается :
{$R-}
uses crt;
const
op : array [1..3] of string[2] = ('//','{','(*');
cl : array [1..3] of string[2] = ('','}','*)');
type
TType = string;
PArray = record
P : ^TArray;
size : word;
end;
TArray = array [1..1] of TType;
TFile = text;
function OpenFile(var f : TFile; path : TType) : boolean;
begin
assign(f, path);
{$I-}
reset(f);
{$I+}
OpenFile := (IOResult = 0);
end;
procedure SaveChanges(var f : text; arr : PArray);
var
i : word;
begin
rewrite(f);
for i := 1 to arr.size do writeln(f,arr.p^[i]);
close(f);
end;
procedure InitArray(var arr : PArray);
begin
arr.size := 0;
GetMem(arr.p, arr.size * sizeof(TType));
end;
procedure FillArray(var arr : PArray; var f : TFile);
var
temp : TType;
newArr : ^Tarray;
i : word;
begin
i := 0;
while not(eof(f)) do begin
readln(f, temp);
inc(i);
GetMem(newArr, arr.size * sizeof(TType) + sizeof(TType));
move(arr.p^[1], newArr^[1], arr.size * sizeof(TType));
FreeMem(arr.p, arr.size * sizeof(TType));
arr.p := newArr;
inc(arr.size);
arr.p^[i] := temp;
end;
end;
procedure ClearArray(var arr : PArray);
begin
FreeMem(arr.p, arr.size * sizeof(TType));
end;
procedure Check(var arr : PArray);
var
s : TType;
i,j,k : word;
begin
i := 1;
while (i <= arr.size) do begin
s := arr.p^[i];
for k := 1 to 3 do
if (pos(op[k],s) <> 0) then begin
j := 1;
while (j <= length(s)) do begin
if s[j] = '''' then repeat
inc(j);
if j = length(s) then begin
arr.p^[i] := s;
inc(i);
s := arr.p^[i];
end;
until s[j] = '''';
if s[j] = '''' then inc(j);
if op[k] = copy(s,j,length(op[k])) then
if k = 1 then delete(s,j,255)
else
while (copy(s,j,length(cl[k])) <> cl[k]) do begin
if j = length(s) then begin
delete(s,j,1);
arr.p^[i] := s;
inc(i);
s := arr.p^[i];
j := 1;
end;
delete(s,j,1);
end else inc(j);
if copy(s,j,length(cl[k])) = cl[k] then delete(s,j,length(cl[k]));
end;
end;
arr.p^[i] := s;
inc(i);
end;
end;
var
filePath : TType;
checkFile : TFile;
temp : PArray;
begin
clrscr;
filePath := 'c:\input.txt';
if OpenFile (checkFile, filePath) then begin
InitArray(temp);
FillArray(temp, checkFile);
Check(temp);
SaveChanges(checkFile, temp);
ClearArray(temp);
end
else writeln('Can"t open file : ' + filePath);
writeln('Done !');
readln;
end.
in :
//comment1
{comment2} no comment2 // comment3
no comment3 {comment3}
{comment4} no comment4 {comment5}
{connent6} writeln('{no comment5}'); {comment7}
(*comment8*) no com{COMMENT}ment6
no comment7 (*comment9*)
(*comment10*) writeln('(*no comment8*)') (*comment11*)
type
TSet = set of char = ['{','}'];
out :
no comment2
no comment3
no comment4
writeln('{no comment5}');
no comment6
no comment7
writeln('(*no comment8*)')
type
TSet = set of char = ['{','}'];
Сообщение отредактировано: klem4 -