Ejemplo n.º 1
0
int main() {
	/* Insert some nodes */
	sym_table_insert("START", 100);
	sym_table_insert("END", 300);
	sym_table_insert("MIDDLE", 200);
	/* Retrieve the nodes */
	fprintf(stdout, "START is at %d\n", sym_table_lookup("START"));
	fprintf(stdout, "MIDDLE is at %d\n", sym_table_lookup("MIDDLE"));
	fprintf(stdout, "END is at %d\n", sym_table_lookup("END"));
	/* This should generate an error */
	sym_table_insert("START", 100);
	return(0);
}
Ejemplo n.º 2
0
// When defining an identifier, define
// a new symbol and insert it into the
// symbol table on top of stack.
// Create the symbol table if it is null.
// Not all blocks have symbols. Do not create
// a symbol table for a given block until it
// has at least one symbol defined in it.
void symbol_stack::define_ident(astree* node) {
    if (stack.back() == nullptr) {
        stack.back() = new symbol_table;
    }
    // Insert new symbol in table
    // on top of symbol stack.
    sym_table_insert(stack.back(), node);
}