TYPE_STRUCT dummy_type = { /* for bad type defs */
NO_FORM, /* form */
0, /* size */
NULL /* type id */
};
/***************************************************************************/
/* search_symtab(name, np) Search for a name in the symbol table. */
/* return pointer to entry if found, else NULL. */
SYMTAB_NODE_PTR search_symtab(name, np)
char *name; /* name to look for */
SYMTAB_NODE_PTR np; /* pointer to symtab root */
{
int cmp;
entry_debug("search_symtab");
/* loop to check each node. If not found, continue down the left */
/* or right subtree. Return when a match */
while (np != NULL) {
cmp = strcmp(name, np->name);
if (cmp == 0) { /* got it */
exit_debug("search_symtab at found");
return(np);
}
np = cmp < 0 ? np->left : np->right; /* continue */
}
exit_debug("search_symtab at not found");
return(NULL); /* not found */
} /* end search_symtab */
/***************************************************************************/
/***************************************************************************/
/* search_symtab_display(name) Search all the symbol tables in the */
/* symbol table display for a name. */
/* return the pointer to the entry if found, else NULL */
SYMTAB_NODE_PTR search_symtab_display(name)
char *name;
{
short i;
SYMTAB_NODE_PTR np; /* pointer to symbol table node */
entry_debug("search_symtab_display");
for (i = level; i >= 0; --i) {
np =search_symtab(name, symtab_display[i]);
if (np != NULL) {
exit_debug("search_symtab_display at found");
return(np);
}
}
exit_debug("search_symtab_display at not found");
return(NULL);
} /* end search_symtab_display */
/***************************************************************************/
/***************************************************************************/
/* enter_symtab(name, npp) Enter a name into the symtab */
/* return pointer to the entry */
SYMTAB_NODE_PTR enter_symtab(name, npp)
char *name; /* name to enter */
SYMTAB_NODE_PTR *npp; /* ptr to ptr to symtab root */
{
int cmp; /* result of strcmp */
SYMTAB_NODE_PTR new_nodep; /* ptr to new entry */
SYMTAB_NODE_PTR np; /* ptr to node to test */
entry_debug("enter_symtab");
/* create the new node for name */
new_nodep = alloc_struct(SYMTAB_NODE);
new_nodep->name = alloc_bytes(strlen(name) + 1);
strcpy(new_nodep->name, name);
new_nodep->left = new_nodep->right = new_nodep->next = NULL;
new_nodep->info = NULL;
new_nodep->defn.key = UNDEFINED;
new_nodep->typep = NULL;
new_nodep->level = level;
new_nodep->label_index = 0;
/* loop to find the insertion point (binary tree) */
while ((np = *npp) != NULL) {
cmp = strcmp(name, np->name);
npp = cmp < 0 ? &(np->left) : &(np->right);
}
*npp = new_nodep; /* replace */
exit_debug("enter_symtab");
return(new_nodep);
} /* end enter_symtab */
/***************************************************************************/
/***************************************************************************/
/* init_symtab() Initialise the symtab with predefined identifiers, */
/* types, and routines */
init_symtab() /* ---------------------- in final */
{
SYMTAB_NODE_PTR integer_idp, real_idp, boolean_idp;
SYMTAB_NODE_PTR logical_idp, binary_idp,
generic_idp, anytype_idp;
int temp;
time_t tp1, tp2;
struct tm *ts;
/* temporarily switch off any debugging output */
temp = DEBUG;
DEBUG = 0;
/* initialise the level 0 (the global?) symbol table */
symtab_display[0] = NULL;
/***************************************************************************/
/* enter_standard_routine(name, routine_key, defn_key) Enter a standard */
/* procedure or function name into the symtab */
} /* end enter_standard_routine */
/***************************************************************************/
/***************************************************************************/
/* enter_scope(symtab_root) Enter a new nesting level by creating a new */
/* scope. Push the given symbol table onto the display stack */
exit_debug("enter_scope");
return;
} /* end enter_scope */
/***************************************************************************/
/***************************************************************************/
/* exit_scope(symtab_root) Exit the current new nesting level by closing */
/* the current scope. Pop the current symbol table off the */
/* display stack, and return a pointer to it */