diff --git a/.gitignore b/.gitignore index d332a97..31fcf21 100644 --- a/.gitignore +++ b/.gitignore @@ -1,11 +1,10 @@ # vscode settings .vscode/ -# dicho -dicho.c - # ignore generated parser calc.c # ignore compiled parser calc + +a.out diff --git a/draft.c b/draft.c index 18bcee0..52f32b1 100644 --- a/draft.c +++ b/draft.c @@ -10,7 +10,6 @@ typedef struct symbol_t { int value; } symbol_t; - typedef struct table_t { symbol_t **array; int size; @@ -69,13 +68,13 @@ symbol_t *intern(char *ident, bool create) bsearch_t res = binary_search(table.array, 0, table.size - 1, ident); printf("pos:%d\n", res.pos); if (create) { - symbol_t *new_symbol = malloc(sizeof(symbol_t)); - new_symbol->ident = strdup(ident); - new_symbol->defined = false; + symbol_t *new_symbol; if (res.found) { - free(table.array[res.pos]); - table.array[res.pos] = new_symbol; + new_symbol = table.array[res.pos]; } else { + new_symbol = malloc(sizeof(symbol_t)); + new_symbol->ident = strdup(ident); + new_symbol->defined = false; printf("insert:%d\n", insert(&table, new_symbol, res.pos)); } return new_symbol;