From 970ecabc1ad30fa74e58f3d4ad9ccf41baffb8b0 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Sat, 19 Dec 2009 19:16:33 -0500 Subject: Implement a symbol table. --- dimension/main.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'dimension/main.c') diff --git a/dimension/main.c b/dimension/main.c index 2c2aea5..561ee99 100644 --- a/dimension/main.c +++ b/dimension/main.c @@ -155,28 +155,40 @@ main(int argc, char **argv) { } } + /* Construct the symbol table */ + dmnsn_symbol_table *symtable = dmnsn_new_symbol_table(); + dmnsn_push_symbol(symtable, "__file__", dmnsn_new_ast_string(input)); + /* Debugging option - output the abstract syntax tree as an S-expression */ if (parse) { - dmnsn_array *astree = dmnsn_parse(input_file, input); + dmnsn_astree *astree = dmnsn_parse(input_file, symtable); if (!astree) { fprintf(stderr, "Error parsing input file!\n"); + dmnsn_delete_symbol_table(symtable); + fclose(input_file); return EXIT_FAILURE; } dmnsn_print_astree_sexpr(stdout, astree); dmnsn_delete_astree(astree); + dmnsn_delete_symbol_table(symtable); fclose(input_file); return EXIT_SUCCESS; } /* Realize the input */ printf("Parsing scene ...\n"); - dmnsn_scene *scene = dmnsn_realize(input_file, input); + dmnsn_scene *scene = dmnsn_realize(input_file, symtable); if (!scene) { fprintf(stderr, "Error realizing input file!\n"); + dmnsn_delete_symbol_table(symtable); + fclose(input_file); return EXIT_FAILURE; } + dmnsn_delete_symbol_table(symtable); + fclose(input_file); + /* Allocate a canvas */ scene->canvas = dmnsn_new_canvas(width, height); if (!scene->canvas) { -- cgit v1.2.3