1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/*
* symtab.h - Declarations for using Symbol Table package.
*
* Author: Russ Fish
* Computer Science Dept.
* University of Utah
* Date: 28 August 1981
*/
/*****************************************************************
* TAG( symtab )
*
* Simple symbol table package. Hash on name string gives buckets within
* hash table, which are bases of lists of id's, rather than reprobing
* within table. Multiple dictionaries are supported.
*/
#ifndef _SYM_TAB /* Only once. */
#define _SYM_TAB
#include "list.h" /* Needs list package. */
/*****************************************************************
* TAG( id )
*
* id - Identifier datatype.
*/
typedef struct _id id;
struct _id
{
TLISTLINKS(id); /* Linked lists within hash buckets. */
string var_name; /* Character string name of id. */
address var_value; /* Ptr to value of variable id. */
};
/*****************************************************************
* TAG( new_symbol find_symbol )
*/
extern id *
new_symbol(); /* Constructor. */
/* ( sym_name, table )
* string sym_name;
* hash_table * table;
*/
extern id *
find_symbol(); /* Locator, NULL if not found. */
/* ( sym_name, table )
* string sym_name;
* hash_table * table;
*/
/*****************************************************************
* TAG( hash_table new_hash_table hash )
*
* Datatype for hash dictionaries.
*/
typedef struct
{
int hash_size; /* Number of entries in table. */
id * hash_id[1]; /* Base of id list on entry. */
}
hash_table;
extern hash_table *
new_hash_table(); /* Constructor, returns cleared table. */
/* ( n_entries )
* int n_entries;
*/
extern id * *
hash(); /* Hashing algorithm, returns ptr to base of an id list in table. */
/* ( sym_name, table )
* string sym_name;
* hash_table * table;
*/
/*****************************************************************
* TAG( ld_table )
*
* Links a vector of already initialiazed id's into a hash table.
* NULL var_name terminates the vector.
*/
extern
ld_table();
/* ( id_vec, table )
* id id_vec[];
* hash_table * table;
*/
/*****************************************************************
* TAG( fr_hash_table )
*
* Dispose of a hash table.
*/
extern
fr_hash_table();
/* ( table )
* hash_table * table;
*/
/* Macros to aid in initializing symbol vectors. */
#define NULLS NULL,NULL
#define VAR_SYM(name_string,var_name) { NULLS, name_string,&var_name, NULL }
#define FN_SYM(name_string,fn_name) { NULLS, name_string, NULL, fn_name }
#endif _SYM_TAB