R-WHILE Playground
R-WHILE code
(* Chen and Udding, Program inversion: More than fun!, 1990, p.7 * Generating preorder and inorder traversals of a binary tree *) read U; T ^= (('dummy.'dummy).nil); from =? P nil loop if =? (=? U nil) nil then cons U (cons D R) <= U; (* left subtree, node, right subtree *) D' ^= D; P <= cons P D; T <= cons (cons D' R) T else cons (cons D U) T <= T; Q <= cons Q D fi =? (hd (hd T)) (tl P) until =? (tl T) U; (* Are T and U empty? *) T ^= (('dummy.'dummy).nil); U <= cons P Q; write U
Input data
(((nil.('a.nil)).('b.nil)).('c.((nil.('d.(nil.('e.nil)))).('f.nil))))
Options
Inversion
Program2data
Expand macros
Execute
Sample programs and data
reverse
swap
translation from a tree to its preorder and inorder traversal (piorder)
self-interpretation of an identity function
self-interpretation of reverse
self-interpretation of piorder
self-interpretation of self-interpretation of reverse (This will probably time out in this playground.)
Infinite loop (in *both* directions)
Enumeration of trees