diff --git a/Makefile b/Makefile index 8649a5c..815aec5 100644 --- a/Makefile +++ b/Makefile @@ -55,4 +55,4 @@ clean: rm -f *.st rm -rf out rm -rf tmp - rm -f parser \ No newline at end of file + rm -f parser diff --git a/src/symbol_table.c b/src/symbol_table.c index 208eb69..ba57818 100644 --- a/src/symbol_table.c +++ b/src/symbol_table.c @@ -479,7 +479,17 @@ char *getType(TableNode *tn) { return ""; } return tn->theType->theName; } -char *getName(TableNode *tn) { return tn->theName; } +char *getName(TableNode *tn) { + if(tn == NULL){ + printf("passed a NULL table entry to getName\n"); + return ""; + } + if(tn->theType == NULL){ + printf("name of entry is currently NULL, undefined \n"); + return ""; + } + return tn->theName; +} int getLine(SymbolTable *st) { return st->Line_Number; } int getColumn(SymbolTable *st) { return st->Column_Number; } TableNode* addName(TableNode *tn, char* str){ @@ -563,7 +573,6 @@ TableNode *look_up(SymbolTable *table, char *x) { void print_symbol_table(SymbolTable *table, FILE *file_ptr) { - return; if (table->Parent_Scope == NULL) { fprintf(file_ptr, "%-17s: %-6s : %-6s : %-21s: %-28s\n", "NAME", "SCOPE", "PARENT", "TYPE", "Extra annotation"); @@ -586,17 +595,16 @@ void print_symbol_table(SymbolTable *table, FILE *file_ptr) { fprintf(file_ptr, "%-17s: %06d : %06d : %-21s: %-28s\n", "", current_scope, parant_scope, "", "Empty Scope"); } - for (entrie != NULL; entrie = entrie->next;) { + for (;entrie != NULL; entrie = entrie->next) { + if (getAdInfoType(entrie) == TYPE_ARRAY){ if (parant_scope == 0) { - /*have to update*/ if (strcmp(entrie->theType->theName, - "function primitive") || - strcmp(entrie->theType->theName, - "array")) { - } + fprintf(file_ptr, - "%-17s: %06d : : %-21s: %-28s\n", + "%-17s: %06d : : %-21d -> %-21s: %-28s\n", entrie->theName, current_scope, - entrie->theType->theName, "Extra annotation"); + entrie->additionalinfo->ArrayAdInfo->numofdimensions, + entrie->additionalinfo->ArrayAdInfo->typeofarray->theName, + "Type of Array"); } else { fprintf(file_ptr, "%-17s: %06d : %06d : %-21s: %-28s\n", entrie->theName, current_scope, parant_scope, @@ -617,6 +625,10 @@ void print_symbol_table(SymbolTable *table, FILE *file_ptr) { } //get top most symbol table SymbolTable *getAncestor(SymbolTable *table) { + if(table == NULL){ + printf("passing a NULL reference to getAncestor. Invalid.\n"); + return NULL; + } if (table->Parent_Scope == NULL) { // if table has no parent, return itself return table; diff --git a/test-s1 b/test-s1 deleted file mode 100644 index e69de29..0000000 diff --git a/test-s2 b/test-s2 deleted file mode 100644 index e69de29..0000000