|
|
1.1 root 1: #include "cem.h"
2: #include "symbol.h"
3:
4: /*
5: * stab is a hash table of pointers to binary trees.
6: */
7: static symbol *stab[STABZ];
8:
9: /*
10: * Map the string 's' to its string table entry, creating a new one
11: * if required.
12: */
13: symbol *
14: find_symbol(s)
15: register char *s;
16: {
17: register int i;
18: register symbol **n;
19: register char *p;
20: register int length;
21: extern char *str_alloc();
22:
23: for (i = 0, length = 1, p = s; *p != '\0'; i += i ^ *p++)
24: length++;
25:
26: if (i < 0)
27: i = -i;
28:
29: n = &stab[i % STABZ];
30:
31: while (*n != NULL)
32: {
33: register char *q;
34:
35: p = s;
36: q = (*n)->sy_name;
37:
38: while ((i = *p ^ *q) == 0 && *p++ != '\0' && *q++ != '\0')
39: ;
40:
41: if (i == 0)
42: return *n;
43:
44: n = i & 1 ? &((*n)->sy_left) : &((*n)->sy_right);
45: }
46:
47: *n = talloc(symbol);
48: (*n)->sy_name = str_alloc(s, length, &((*n)->sy_index));
49: (*n)->sy_left = NULL;
50: (*n)->sy_right = NULL;
51: (*n)->sy_inst = NULL;
52:
53: return *n;
54: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.