blob: 7f199ad4bc581aaa47ef5ce54818b8993ebabd80 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
-- Programmed by Jedidiah Barber
-- Licensed under the Sunset License v1.0
-- See license.txt for further details
with
Ada.Containers.Multiway_Trees,
Ada.Text_IO,
Kompsos.Advanced_Reify,
Kompsos.Pretty_Print;
procedure Trees is
package TIO renames Ada.Text_IO;
package InKomp is new Kompsos (Integer);
use InKomp;
type Integer_Array is array (Positive range <>) of Integer;
function Var_Minus_One
(Item : in Term)
return Integer is
begin
return -1;
end Var_Minus_One;
package Int_Trees is new Ada.Containers.Multiway_Trees (Integer);
package Reify is new InKomp.Advanced_Reify
(Element_Array => Integer_Array,
Null_Element => 0,
Variable_Convert => Var_Minus_One,
Element_Trees => Int_Trees);
package Printer is new InKomp.Pretty_Print (Integer'Image);
Test_Item : constant Term := T (T (T (1) & T (2) & T (3)) & T (T (10) & T (20)));
Result : constant Int_Trees.Tree := Reify.To_Tree (Test_Item);
begin
TIO.Put_Line ("Test term is " & Printer.Image (Test_Item));
TIO.New_Line;
TIO.Put_Line ("Root has " &
Printer.Image (Integer (Int_Trees.Child_Count (Result.Root))) & " children.");
for Child in Result.Iterate_Children (Result.Root) loop
TIO.Put ("Child has " &
Printer.Image (Integer (Int_Trees.Child_Count (Child))) & " children:");
for Child_Child in Result.Iterate_Children (Child) loop
TIO.Put (" " & Printer.Image (Int_Trees.Element (Child_Child)));
end loop;
TIO.New_Line;
end loop;
end Trees;
|