git @ Cat's Eye Technologies Dipple / master
Split AssocList demo off into own module. Chris Pressey 7 months ago
3 changed file(s) with 58 addition(s) and 54 deletion(s). Raw diff Collapse all Expand all
8888 PROCEDURE Demo*;
8989 VAR n: ASTPtr;
9090 BEGIN
91 n := MkImpl(MkPropVar("p"), MkPropVar("q"));
91 n := MkImpl(MkConj(MkPropVar("p"), MkPropVar("q")), MkDisj(MkPropVar("p"), MkPropVar("q")));
9292 Display(n);
9393 Out.Ln()
9494 END Demo;
0 MODULE AssocDemo;
1
2 IMPORT Out, AssocList;
3
4 PROCEDURE DisplayValue*(v: AssocList.ValuePtr);
5 BEGIN
6 IF v # NIL THEN
7 Out.String(v^.str);
8 ELSE
9 Out.String("...");
10 END;
11 END DisplayValue;
12
13 PROCEDURE Scan(list: AssocList.ListPtr);
14 VAR
15 k: INTEGER;
16 BEGIN
17 FOR k := 1 TO 10 DO
18 Out.Int(k * 10, 3);
19 Out.String(" ");
20 DisplayValue(AssocList.Lookup(list, k * 10));
21 Out.Ln;
22 END;
23 Out.Ln
24 END Scan;
25
26 PROCEDURE Demo*;
27 VAR
28 a, b: AssocList.ListPtr;
29 r: BOOLEAN;
30 BEGIN
31 a := AssocList.Empty();
32 r := AssocList.Insert(a, 40, "Hello");
33 ASSERT(r);
34 r := AssocList.Insert(a, 80, "World");
35 ASSERT(r);
36 r := AssocList.Insert(a, 20, "!");
37 ASSERT(r);
38 Scan(a);
39 AssocList.Remove(a, 80);
40 Scan(a);
41
42 b := AssocList.Empty();
43 r := AssocList.Insert(b, 30, "Wonderful");
44 ASSERT(r);
45 r := AssocList.Insert(b, 70, "Fantastic");
46 ASSERT(r);
47
48 r := AssocList.Merge(a, b);
49 ASSERT(r);
50 Scan(a)
51
52 END Demo;
53
54 BEGIN
55 END AssocDemo.
44 TYPE
55 ValuePtr* = POINTER TO Value;
66 Value* = RECORD
7 str: ARRAY 256 OF CHAR
7 str*: ARRAY 256 OF CHAR
88 END;
99 ListPtr* = POINTER TO List;
1010 List = RECORD
110110 RETURN successful
111111 END Merge;
112112
113 (* ----------- Procedures for the Demo ---------- *)
114
115 PROCEDURE DisplayValue*(v: ValuePtr);
116 BEGIN
117 IF v # NIL THEN
118 Out.String(v^.str);
119 ELSE
120 Out.String("...");
121 END;
122 END DisplayValue;
123
124 PROCEDURE Scan(list: ListPtr);
125 VAR
126 k: INTEGER;
127 BEGIN
128 FOR k := 1 TO 10 DO
129 Out.Int(k * 10, 3);
130 Out.String(" ");
131 DisplayValue(Lookup(list, k * 10));
132 Out.Ln;
133 END;
134 Out.Ln
135 END Scan;
136
137 PROCEDURE Demo*;
138 VAR
139 a, b: ListPtr;
140 r: BOOLEAN;
141 BEGIN
142 a := Empty();
143 r := Insert(a, 40, "Hello");
144 ASSERT(r);
145 r := Insert(a, 80, "World");
146 ASSERT(r);
147 r := Insert(a, 20, "!");
148 ASSERT(r);
149 Scan(a);
150 Remove(a, 80);
151 Scan(a);
152
153 b := Empty();
154 r := Insert(b, 30, "Wonderful");
155 ASSERT(r);
156 r := Insert(b, 70, "Fantastic");
157 ASSERT(r);
158
159 r := Merge(a, b);
160 ASSERT(r);
161 Scan(a)
162
163 END Demo;
164
165113 BEGIN
166114 END AssocList.