Crash (access violation) 2
why I have Crash???
program Project1;
{$APPTYPE CONSOLE}
{$H+}
const Key: array [1..35] of string = ('AND', 'ARRAY', 'BEGIN'
, 'CASE', 'CLASS', 'CONST', 'DIV', 'DO', 'ELSE', 'END', 'FOR'
, 'FUNCTION', 'IF', 'IMPLEMENTATION', 'INTERFACE', 'MOD'
, 'NOT', 'OF', 'OR', 'PROCEDURE', 'PROGRAM', 'RECORD'
, 'REPEAT', 'SHL', 'SHR', 'STRING', 'THEN', 'TO', 'TYPE'
, 'UNIT', 'UNTIL', 'USES', 'VAR', 'WITH', 'WHILE');
var S, St: String;
Chi, I, J, T: LongInt;
Num, Tochka, Comment, Stri: Boolean;
Ch: Char;
function PosAfter(Sub, S: String; C: LongInt): LongInt;
var T: LongInt;
begin
delete(S, 1, C);
T:=Pos(Sub, S);
if T<>0 then
PosAfter:=C+T
else
PosAfter:=0;
end;
Function UpperCase(S: String): String;
const ChUp: String = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
ChDown: String = 'abcdefghijklmnopqrstuvwxyz';
var I, T: LongInt;
Te: String;
begin
Te:=S;
for I := 1 to Length(S) do
begin
T:=pos(Te[I], ChDown);
if T<>0 then
begin
Te[I]:=ChUp[T];
end;
end;
UpperCase:=Te;
end;
begin
while not seekeof do
begin
readln(S);
I:=0;
if Comment then
begin
T:=Pos('}', S);
if T>0 then
begin
Comment:=False;
insert('</span>', S, T+1);
I:=T+length('</span>');
end
else
begin
writeln(S);
Continue;
end;
end;
if Stri then
begin
T:=Pos('''', S);
if T>0 then
begin
Comment:=False;
insert('</span>', S, T+1);
I:=T+length('</span>');
end
else
begin
writeln(S);
Continue;
end;
end;
while I<=Length(S) do
begin
Inc(I);
if (Num) then
begin
if (S[I] in ['0'..'9', '.']) then
begin
if (S[I]='.')and(not Tochka) then
begin
Tochka:=True;
continue;
end;
if S[I]='.' then
begin
if S[I-1]='.' then
begin
insert('</span>', S, I-1);
inc(I, length('</span>'));
end else
begin
insert('</span>', S, I);
inc(I, length('</span>'));
end;
Tochka:=False;
Num:=False;
end;
continue;
end;
if S[I-1]='.' then
begin
insert('</span>', S, I-1);
inc(I, length('</span>'));
end else
begin
insert('</span>', S, I);
inc(I, length('</span>'));
end;
Tochka:=False;
Num:=False;
end;
if (Chi>0) then
begin
if (Chi=1)and(S[I] in ['0'..'9']) then
begin
insert('<span class=string>', S, I-1);
inc(I, length('<span class=string>'));
Chi:=2;
continue;
end;
if (not (S[I] in ['0'..'9'])) then
begin
if Chi=2 then
begin
insert('</span>', S, I);
inc(I, length('</span>'));
end;
Chi:=0;
end;
end;
if S[I]='{' then
begin
insert('<span class=comment>', S, I);
inc(I, Length('<span class=comment>'));
T:=PosAfter('}', S, I);
if T>0 then
begin
insert('</span>', S, T+1);
I:=T+length('</span>');
continue;
end
else
begin
Comment:=True;
break;
end;
end;
if S[I]='''' then
begin
insert('<span class=string>', S, I);
inc(I, Length('<span class=string>'));
T:=PosAfter('''', S, I);
if T>0 then
begin
insert('</span>', S, T+1);
I:=T+length('</span>');
Continue;
end
else
begin
Stri:=True;
Break;
end;
end;
if S[I]='#' then
begin
Chi:=1;
Continue;
end;
if (copy(S, I, 2)='//') then
begin
insert('<span class=comment>', S, I);
S:=S+'</span>';
Break;
end;
if (Chi=0)and(S[I] in ['0'..'9'])and(not Num) then
begin
if not Num then
begin
insert('<span class=number>', S, I);
inc(I, length('<span class=number>'));
Num:= True;
end;
continue;
end;
for J := 1 to Length(Key) do
begin
St:=copy(S, I, length(Key[J]));
if (UpperCase(St)=Key[J])and((I=1)or
(not (S[I-1] in ['a'..'z', 'A'..'Z'])))and
((I+length(Key[J])=length(S))or
(not(S[length(Key[J])+I] in ['a'..'z', 'A'..'Z'])))
then
begin
insert('</span>', S, I+length(Key[J]));
insert('<span class=keyword>', S, I);
inc(I, Length('<span class=keyword>')+length(Key[J])+length('</span>'));
break;
end;
end;
end;
writeln(S);
end;
end.