1 /* $Id: symtab.c,v 1.4 1994/06/24 10:42:24 ceriel Exp $ */
3 * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
4 * See the copyright notice in the ACK home directory, in the file "Copyright".
8 * Contains the routine findident, which builds the symbol table and
13 struct symtab *idtable, *deftable;
16 findident(s, mode, table) char *s; struct symtab **table; {
18 * Look for identifier s in the symboltable referred to by *table.
19 * If mode = LOOKING, no new entry's will be made.
20 * If mode = ENTERING, a new entry will be made if s is not in the
21 * table yet, otherwise an error results
25 register struct symtab *p;
28 if (!*table) { /* No entry for this symbol */
29 if (mode == LOOKING) return (struct symtab *) 0;
33 p = (struct symtab *) malloc(sizeof *p);
34 p->s_left = p->s_right = (struct symtab *) 0;
35 p->s_name = malloc( (unsigned) (strlen(s) + 1));
42 if ((n = strcmp(p->s_name,s)) == 0) { /* This is it! */
43 if (mode == ENTERING) {
44 error("Identifier %s redefined",s);
48 /* Binary tree ..... */
49 if (n < 0) return findident(s,mode,&(p->s_left));
50 return findident(s,mode,&(p->s_right));