Final code produced from the sample program
(only lines from original code are numbered to help
the reader see what has been added):
01 program Demo;
02 const NbDays = 7;
03 type WeekDays=(Su,Mo,Tu,We,Th,Fr,Sa);
04 Element=record
05 Name: string;
06 Next: ^Element;
07 end;
08 var Num : real
09 S : string;
10 Day : WeekDays;
11 WorkDays : set of WeekDays;
www_WorkDays: WeekDays;
12 Matrix : array['a'..'z',1..10] of integer;
www_Matrix_1: 'a'..'z';
www_Matrix_2: 1..10;
13 Chain : ^Element;
14 begin
(* create symbol table entries for objects declared in this block *)
www_AllocateConst(2,'NbDays','7');
www_Allocate(8,'Num',addr(Num));
www_Allocate(9,'S',addr(S));
www_AllocateEnumeration(10,'Day',addr(Day),'Su,Mo,Tu,We,Th,Fr,Sa');
www_AllocateSet(11,'WorkDays',addr(WorkDays),'Su,Mo,Tu,We,Th,Fr,Sa');
(* add entry for Matrix as structure *)
www_AllocateStructure(12,'Matrix',addr(Matrix));
for www_Matrix_1 := 'a' to 'z' do begin
(* add entry for Matrix[www_Matrix_1] as structure *)
www_AllocateStructure(0,concat('[',www_Matrix_1,']'),
addr(Matrix[www_Matrix_1]));
for www_Matrix_2 := 1 to 10 do begin
(* add entry for Matrix[www_Matrix_1][www_Matrix_2] *)
www_Allocate(0,concat('[',IntToStr(www_Matrix_2),']'),
addr(Matrix[www_Matrix_1,www_Matrix_2]));
end;
www_EndStructure; (* done adding entries for Matrix[www_Matrix_1] *)
end;
www_EndStructure; (* done adding entries for Matrix *)
www_AllocatePointer(13,'Chain',addr(Chain)); (* add entry for Chain *)
Step;
15 Num := 3.1415;
www_RedefineReal(09,'Num',Num); (* define value for Num *)
Step;
16 S := 'Hi there';
www_RedefineString(10,'S',S); (* define value for S *)
Step;
17 Day := Tu;
www_RedefineEnumaration(11,'Day',ord(Day)); (* define value for Day *)
Step;
18 WorkDays := [Mo..Fr];
for www_WorkDays := Su to Sa do
(* for each value in WeekDays,
define whether it is in the set or not *)
www_RedefineSet(12,'WorkDays',ord(www_WorkDays),
www_WorkDays in WorkDays);
Step;
19 Matrix['d',3] := 67;
www_RedefineStructure(19,'Matrix'); (* modify struc. Matrix *)
www_RedefineStructure(0,'[''d'']'));(* modify substruc. Matrix['d'] *)
(* define value for Matrix['d'][3] *)
www_RedefineInteger(19,'[3]',Matrix['d',3]);
www_EndStructure; (* done with Matrix['d'] *)
www_EndStructure; (* done with Matrix *)
Step;
20 new(Chain);
www_New(20,'Chain',Chain); (* define value for Chain *)
(* add entry for Chain^ as structure
(no name is given because it can be pointed to by many pointers) *)
www_AllocateStructure(0,'',addr(Chain^));
www_Allocate(0,'Name',addr(Chain^.Name));(* add entry for 1st field *)
www_Allocate(0,'Next',addr(Chain^.Next));(* add entry for 2nd field *)
www_EndStructure; (* done adding entries for Chain^ *)
Step;
21 Chain^.Name := 'Brown';
www_RedefineDyn(21,'Chain');
www_RedefineStructure(0,'');(* modify struc. Chain^ (has no name) *)
www_RedefineString(0,'.Name',Chain^.Name);(* define value for Name field *)
www_EndStructure; (* done with Chain^ *)
Step;
22 Chain^.Next := nil;
www_RedefineDyn(22,'Chain');
www_RedefineStructure(0,'');(* modify struc. Chain^ *)
www_RedefinePointer(0,'.Next',Chain^.Next);(* define value for Next field *)
www_EndStructure; (* done with Chain^ *)
Step;
(* what follows is to remove all local objects from symbol table
before exiting the block *)
www_Remove(08,'Num');
www_Remove(09,'S');
www_Remove(10,'Day');
www_Remove(11,'WorkDays');
www_Remove(12,'Matrix');
www_Remove(13,'Chain');
23 end.