| 1 |
(* SymbolKey.def binary tree operations for storing symbols. |
| 2 |
|
| 3 |
Copyright (C) 2001-2025 Free Software Foundation, Inc. |
| 4 |
Contributed by Gaius Mulley <[email protected]>. |
| 5 |
|
| 6 |
This file is part of GNU Modula-2. |
| 7 |
|
| 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) |
| 11 |
any later version. |
| 12 |
|
| 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. |
| 17 |
|
| 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/>. *) |
| 21 |
|
| 22 |
DEFINITION MODULE SymbolKey ; |
| 23 |
|
| 24 |
(* |
| 25 |
Author : Gaius Mulley |
| 26 |
Title : SymbolKey |
| 27 |
Date : 4/3/87 |
| 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 |
| 32 |
*) |
| 33 |
|
| 34 |
FROM SYSTEM IMPORT WORD ; |
| 35 |
FROM NameKey IMPORT Name ; |
| 36 |
EXPORT QUALIFIED NulKey, SymbolTree, |
| 37 |
IsSymbol, PerformOperation, |
| 38 |
InitTree, KillTree, GetSymKey, PutSymKey, DelSymKey, |
| 39 |
IsEmptyTree, |
| 40 |
DoesTreeContainAny, ForeachNodeDo, ContainsSymKey, |
| 41 |
NoOfNodes, ForeachNodeConditionDo ; |
| 42 |
|
| 43 |
CONST |
| 44 |
NulKey = 0 ; |
| 45 |
|
| 46 |
TYPE |
| 47 |
SymbolTree ; |
| 48 |
|
| 49 |
IsSymbol = PROCEDURE (WORD) : BOOLEAN ; |
| 50 |
PerformOperation = PROCEDURE (WORD) ; |
| 51 |
|
| 52 |
|
| 53 |
(* |
| 54 |
InitTree - Initializes a SymbolTree pointed to by t. |
| 55 |
*) |
| 56 |
|
| 57 |
PROCEDURE InitTree (VAR t: SymbolTree) ; |
| 58 |
|
| 59 |
|
| 60 |
(* |
| 61 |
KillTree - Destroys the SymbolTree pointed to by t. |
| 62 |
*) |
| 63 |
|
| 64 |
PROCEDURE KillTree (VAR t: SymbolTree) ; |
| 65 |
|
| 66 |
|
| 67 |
(* |
| 68 |
GetSymKey - Searches the SymbolTree t for an entry NameKey. If |
| 69 |
found then the SymKey is returned. NulKey = not found. |
| 70 |
*) |
| 71 |
|
| 72 |
PROCEDURE GetSymKey (t: SymbolTree; NameKey: Name) : WORD ; |
| 73 |
|
| 74 |
|
| 75 |
(* |
| 76 |
PutSymKey - Puts an symbol entry NameKey in the SymbolTree t. |
| 77 |
SymKey is the value stored with NameKey. |
| 78 |
*) |
| 79 |
|
| 80 |
PROCEDURE PutSymKey (t: SymbolTree; NameKey: Name; SymKey: WORD) ; |
| 81 |
|
| 82 |
|
| 83 |
(* |
| 84 |
DelSymKey - Deletes a symbol entry NameKey in the SymbolTree t. |
| 85 |
*) |
| 86 |
|
| 87 |
PROCEDURE DelSymKey (t: SymbolTree; NameKey: Name) ; |
| 88 |
|
| 89 |
|
| 90 |
(* |
| 91 |
IsEmptyTree - returns true if SymbolTree, t, is empty. |
| 92 |
*) |
| 93 |
|
| 94 |
PROCEDURE IsEmptyTree (t: SymbolTree) : BOOLEAN ; |
| 95 |
|
| 96 |
|
| 97 |
(* |
| 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. |
| 101 |
*) |
| 102 |
|
| 103 |
PROCEDURE DoesTreeContainAny (t: SymbolTree; P: IsSymbol) : BOOLEAN ; |
| 104 |
|
| 105 |
|
| 106 |
(* |
| 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. |
| 110 |
*) |
| 111 |
|
| 112 |
PROCEDURE ForeachNodeDo (t: SymbolTree; P: PerformOperation) ; |
| 113 |
|
| 114 |
|
| 115 |
(* |
| 116 |
ContainsSymKey - return TRUE if tree, t, contains an entry for, NameKey. |
| 117 |
*) |
| 118 |
|
| 119 |
PROCEDURE ContainsSymKey (t: SymbolTree; NameKey: Name) : BOOLEAN ; |
| 120 |
|
| 121 |
|
| 122 |
(* |
| 123 |
NoOfNodes - returns the number of nodes in the tree t. |
| 124 |
*) |
| 125 |
|
| 126 |
PROCEDURE NoOfNodes (t: SymbolTree; condition: IsSymbol) : CARDINAL ; |
| 127 |
|
| 128 |
|
| 129 |
(* |
| 130 |
ForeachNodeConditionDo - traverse the tree t and for any node which satisfied |
| 131 |
condition call P. |
| 132 |
*) |
| 133 |
|
| 134 |
PROCEDURE ForeachNodeConditionDo (t: SymbolTree; |
| 135 |
condition: IsSymbol; |
| 136 |
P: PerformOperation) ; |
| 137 |
|
| 138 |
|
| 139 |
END SymbolKey. |