3 ### An Icon implementation of a `same-fringe' solver.
5 ###--------------------------------------------------------------------------
9 ## Report MSG as an error, and quit.
11 write(&errout, &progname, ": ", msg)
16 procedure same_sequence_p(test, aseq, bseq)
17 ## Succeed if the sequences generated by coexpressions ASEQ and BSEQ equal,
18 ## in the sense that TEST succeeds when applied to corresponding elements,
19 ## and the sequences have the same length.
24 if not (b := @bseq) | not test(a, b) then fail
29 procedure print_sequence(aseq)
30 ## Write the elements of the sequence generated by coexpression ASEQ
31 ## followed by a newline.
37 procedure string_equal_p(a, b)
38 ## Succeed if strings A and B are equal. Useful as a TEST for
44 ###--------------------------------------------------------------------------
47 record Node(left, data, right)
48 ## A simple binary tree structure.
50 procedure fringe(node)
51 ## Generate the elements of the tree headed by NODE inorder.
54 suspend fringe(node.left) | node.data | fringe(node.right)
58 ## Scan a tree from the current subject, advancing the position over it.
59 ## See `parse_tree' for the syntax.
61 local data, left, right
67 data := move(1) | bail("no data")
69 =")" | bail("missing )")
70 return Node(left, data, right)
74 procedure parse_tree(string)
75 ## Parse a tree from STRING and return its root.
77 ## The syntax is as follows.
79 ## tree ::= empty | `(' tree char tree `)'
81 ## Ambiguity is resolved by treating a `(' as starting a tree when a tree
88 if not pos(0) then bail("trailing junk")
93 ###--------------------------------------------------------------------------
100 print_sequence(create fringe(parse_tree(argv[1])))
101 else if *argv = 2 then
102 if same_sequence_p(string_equal_p,
103 create fringe(parse_tree(argv[1])),
104 create fringe(parse_tree(argv[2]))) then
112 ###----- That's all, folks --------------------------------------------------