Remove building with NOCRYPTO option
[minix3.git] / external / bsd / byacc / dist / symtab.c
blob5f743a5ad299287d900493593d4caea115385ae6
1 /* $NetBSD: symtab.c,v 1.8 2015/01/03 23:22:52 christos Exp $ */
3 /* Id: symtab.c,v 1.11 2014/03/26 00:17:09 Tom.Shields Exp */
5 #include "defs.h"
7 #include <sys/cdefs.h>
8 __RCSID("$NetBSD: symtab.c,v 1.8 2015/01/03 23:22:52 christos Exp $");
10 /* TABLE_SIZE is the number of entries in the symbol table. */
11 /* TABLE_SIZE must be a power of two. */
13 #define TABLE_SIZE 1024
15 static bucket **symbol_table = 0;
16 bucket *first_symbol;
17 bucket *last_symbol;
19 static int
20 hash(const char *name)
22 const char *s;
23 int c, k;
25 assert(name && *name);
26 s = name;
27 k = *s;
28 while ((c = *++s) != 0)
29 k = (31 * k + c) & (TABLE_SIZE - 1);
31 return (k);
34 bucket *
35 make_bucket(const char *name)
37 bucket *bp;
39 assert(name != 0);
41 bp = TMALLOC(bucket, 1);
42 NO_SPACE(bp);
44 bp->link = 0;
45 bp->next = 0;
47 bp->name = TMALLOC(char, strlen(name) + 1);
48 NO_SPACE(bp->name);
50 bp->tag = 0;
51 bp->value = UNDEFINED;
52 bp->index = 0;
53 bp->prec = 0;
54 bp->class = UNKNOWN;
55 bp->assoc = TOKEN;
56 #if defined(YYBTYACC)
57 bp->args = -1;
58 bp->argnames = 0;
59 bp->argtags = 0;
60 bp->destructor = 0;
61 #endif
62 strcpy(bp->name, name);
64 return (bp);
67 bucket *
68 lookup(const char *name)
70 bucket *bp, **bpp;
72 bpp = symbol_table + hash(name);
73 bp = *bpp;
75 while (bp)
77 if (strcmp(name, bp->name) == 0)
78 return (bp);
79 bpp = &bp->link;
80 bp = *bpp;
83 *bpp = bp = make_bucket(name);
84 last_symbol->next = bp;
85 last_symbol = bp;
87 return (bp);
90 void
91 create_symbol_table(void)
93 int i;
94 bucket *bp;
96 symbol_table = TMALLOC(bucket *, TABLE_SIZE);
97 NO_SPACE(symbol_table);
99 for (i = 0; i < TABLE_SIZE; i++)
100 symbol_table[i] = 0;
102 bp = make_bucket("error");
103 bp->index = 1;
104 bp->class = TERM;
106 first_symbol = bp;
107 last_symbol = bp;
108 symbol_table[hash("error")] = bp;
111 void
112 free_symbol_table(void)
114 FREE(symbol_table);
115 symbol_table = 0;
118 void
119 free_symbols(void)
121 bucket *p, *q;
123 for (p = first_symbol; p; p = q)
125 q = p->next;
126 FREE(p);