/* * symtab.h - header for simple symbol tables * CSE 413 au07 assignment 5 * (to be modified later for compiler project) */ #ifndef SYMTAB_H #define SYMTAB_H /*----- data definitions ------*/ /* Pointer to a symbol table node */ typedef struct sym* symptr; /* BST node for a single symbol */ typedef struct sym { char * name; /* name of this symbol (also node key) */ symptr left; /* pointer to left subtree or NULL if empty */ symptr right; /* pointer to right subtree or NULL if empty */ } symbol; /* Symbol table data structure */ typedef struct { symptr root; /* root of unbalanced binary search tree of symbols, */ /* or NULL if the tree is empty */ } symtab; /*----- operations ------*/ /* * Initialize new symbol table st (must be called before any use of st). * Precondition: Pointer variables inside of st do not refer to * any dynamically allocated data. */ void st_init(symtab* st); /* * Add a new symbol with string (key) s to the symbol table st if not * already present in st, otherwise do nothing. * Return a pointer to the new symbol's node if it was added to the tree, * or return NULL if the tree was not changed. */ symptr st_add(char* s, symtab* st); /* * Return a pointer to the node containing symbol s if present in st, * otherwise return NULL. */ symptr st_find(char* s, symtab* st); /* * Set st to empty and delete any dynamic data previously allocated to it. */ void st_delete(symtab* st); #endif