MODULE tree_functions; PROCEDURE tree_functions MAIN; ! define a two-level deep tree with a string at the leaves DECLARE translation : TREE ( STRING, STRING ) OF STRING; ! this tree pointer handles pointing from the first interior ! node level down to the leaf nodes DECLARE languages : TREEPTR( STRING ) TO TREE ( STRING ) OF STRING; ! this tree pointer handles pointing from the second ! node level down to the leaf nodes DECLARE words : TREEPTR( STRING ) TO STRING; ! this pointer right to a leaf node, for instance DECLARE foreign_word : POINTER TO STRING; translation( 'FRENCH', 'love' ) = 'amour'; translation( 'FRENCH', 'night' ) = 'nuit'; translation( 'SPANISH', 'chicken' ) = 'pollo'; translation( 'SPANISH', 'house' ) = 'casa'; translation( 'SPANISH', 'love' ) = 'amor'; translation( 'SPANISH', 'night' ) = 'noche'; ! other functions used with trees languages = LAST( translation ); WRITE SUBSCRIPT( languages ); ! SPANISH languages = PRIOR( languages ); WRITE SUBSCRIPT( languages ); ! FRENCH languages = PRIOR( languages ); IF languages = NIL THEN WRITE 'NIL'; ! NIL END IF; languages = LAST( translation ); ! node 'SPANISH' words = LAST( languages ); ! node 'SPANISH', 'night' WRITE SUBSCRIPT( words ); ! night WRITE VALUE( words ); ! noche foreign_word = VALUEPTR( words ); ! string 'noche' WRITE foreign_word->; ! noche foreign_word = POINTER( translation( 'SPANISH', 'night' ) ); WRITE foreign_word->; ! noche ! remove two nodes (words and their translations) from the tree; PRUNE translation( 'FRENCH', 'love' ), translation( 'SPANISH', 'love' ); ! remove a whole language (subtree) from the tree PRUNE translation( 'FRENCH' ); ! remove all nodes from the tree PRUNE translation; END PROCEDURE /* tree_functions */; END MODULE /* tree_functions */;