1 (* SymbolKey.def binary tree operations for storing symbols.
3 Copyright (C) 2001-2024 Free Software Foundation, Inc.
4 Contributed by Gaius Mulley <gaius.mulley@southwales.ac.uk>.
6 This file is part of GNU Modula-2.
8 GNU Modula-2 is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3, or (at your option)
13 GNU Modula-2 is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU Modula-2; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. *)
22 DEFINITION MODULE SymbolKey ;
28 Description: Provides binary tree operations for storing symbols.
29 Used by the MODULE SymbolTable to provide scoping of symbols.
30 Last update: Date: Wed 31-01-1990 Time: 18:20:32.63
31 Mon Aug 30 12:07:12 BST 1999
34 FROM SYSTEM IMPORT WORD ;
35 FROM NameKey IMPORT Name ;
36 EXPORT QUALIFIED NulKey, SymbolTree,
37 IsSymbol, PerformOperation,
38 InitTree, KillTree, GetSymKey, PutSymKey, DelSymKey,
40 DoesTreeContainAny, ForeachNodeDo, ContainsSymKey,
41 NoOfNodes, ForeachNodeConditionDo ;
49 IsSymbol = PROCEDURE (WORD) : BOOLEAN ;
50 PerformOperation = PROCEDURE (WORD) ;
54 InitTree - Initializes a SymbolTree pointed to by t.
57 PROCEDURE InitTree (VAR t: SymbolTree) ;
61 KillTree - Destroys the SymbolTree pointed to by t.
64 PROCEDURE KillTree (VAR t: SymbolTree) ;
68 GetSymKey - Searches the SymbolTree t for an entry NameKey. If
69 found then the SymKey is returned. NulKey = not found.
72 PROCEDURE GetSymKey (t: SymbolTree; NameKey: Name) : WORD ;
76 PutSymKey - Puts an symbol entry NameKey in the SymbolTree t.
77 SymKey is the value stored with NameKey.
80 PROCEDURE PutSymKey (t: SymbolTree; NameKey: Name; SymKey: WORD) ;
84 DelSymKey - Deletes a symbol entry NameKey in the SymbolTree t.
87 PROCEDURE DelSymKey (t: SymbolTree; NameKey: Name) ;
91 IsEmptyTree - returns true if SymbolTree, t, is empty.
94 PROCEDURE IsEmptyTree (t: SymbolTree) : BOOLEAN ;
98 DoesTreeContainAny - returns true if SymbolTree, t, contains any
99 symbols which in turn return true when procedure,
100 P, is called with a symbol as its parameter.
103 PROCEDURE DoesTreeContainAny (t: SymbolTree; P: IsSymbol) : BOOLEAN ;
107 ForeachNodeDo - for each node in SymbolTree, t, a procedure, P,
108 is called with the node symbol as its parameter.
109 It traverse the tree in order.
112 PROCEDURE ForeachNodeDo (t: SymbolTree; P: PerformOperation) ;
116 ContainsSymKey - return TRUE if tree, t, contains an entry for, NameKey.
119 PROCEDURE ContainsSymKey (t: SymbolTree; NameKey: Name) : BOOLEAN ;
123 NoOfNodes - returns the number of nodes in the tree t.
126 PROCEDURE NoOfNodes (t: SymbolTree; condition: IsSymbol) : CARDINAL ;
130 ForeachNodeConditionDo - traverse the tree t and for any node which satisfied
134 PROCEDURE ForeachNodeConditionDo (t: SymbolTree;
136 P: PerformOperation) ;