From 3686a64948d8453370bae0199c672a97fce669e9 Mon Sep 17 00:00:00 2001 From: Partho Bhattacharya Date: Thu, 27 Mar 2025 04:44:13 -0400 Subject: [PATCH] symbol_table print almost done but have to figure out seg fault --- src/symbol_table.c | 71 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 69 insertions(+), 2 deletions(-) diff --git a/src/symbol_table.c b/src/symbol_table.c index ba57818..9ba911f 100644 --- a/src/symbol_table.c +++ b/src/symbol_table.c @@ -505,6 +505,7 @@ SymbolTable* setLineNumber(SymbolTable *st,int line){ return st; } st->Line_Number = line; + return st; } SymbolTable* setColumnNumber(SymbolTable *st,int column){ @@ -513,6 +514,7 @@ SymbolTable* setColumnNumber(SymbolTable *st,int column){ return st; } st->Line_Number = column; + return st; } /* //we use false for type defs and true for functions for parameter of typeOf @@ -606,11 +608,76 @@ void print_symbol_table(SymbolTable *table, FILE *file_ptr) { entrie->additionalinfo->ArrayAdInfo->typeofarray->theName, "Type of Array"); } else { - fprintf(file_ptr, "%-17s: %06d : %06d : %-21s: %-28s\n", + fprintf(file_ptr, "%-17s: %06d : %06d : %-21d -> %-21s: %-28s\n", entrie->theName, current_scope, parant_scope, - entrie->theType->theName, "Extra annotation"); + entrie->additionalinfo->ArrayAdInfo->numofdimensions, + entrie->additionalinfo->ArrayAdInfo->typeofarray->theName, + "Type of Array"); } } + if (getAdInfoType(entrie) == TYPE_RECORD){ + if (parant_scope == 0) { + + fprintf(file_ptr, + "%-17s: %06d : :%-21s: elements-%-28d\n", + entrie->theName, current_scope, + "record", + entrie->additionalinfo->RecAdInfo->numofelements); + } else { + fprintf(file_ptr, "%-17s: %06d : %06d : %-21s: elements-%-28d\n", + entrie->theName, current_scope, parant_scope, + "record", + entrie->additionalinfo->RecAdInfo->numofelements); + } + } + if (getAdInfoType(entrie) == TYPE_PRIMITIVE){ + if (parant_scope == 0) { + + fprintf(file_ptr, + "%-17s: %06d : :%-21s: size-%-28d bytes\n", + entrie->theName, current_scope, + "Primitive", + entrie->additionalinfo->PrimAdInfo->size); + } else { + fprintf(file_ptr, "%-17s: %06d : %06d : %-21s: size-%-28d bytes\n", + entrie->theName, current_scope, parant_scope, + "Primitive", + entrie->additionalinfo->PrimAdInfo->size); + } + } + if (getAdInfoType(entrie) == TYPE_FUNCTION_TYPE){ + if (parant_scope == 0) { + + fprintf(file_ptr, + "%-17s: %06d : : %-21s -> %-21s: %-28s\n", + entrie->theName, current_scope, + entrie->additionalinfo->FunTypeAdInfo->parameter->theName, + entrie->additionalinfo->FunTypeAdInfo->returntype->theName, + "Type of Function"); + } else { + fprintf(file_ptr, "%-17s: %06d : %06d : %-21s -> %-21s: %-28s\n", + entrie->theName, current_scope, parant_scope, + entrie->additionalinfo->FunTypeAdInfo->parameter->theName, + entrie->additionalinfo->FunTypeAdInfo->returntype->theName, + "Type of Function"); + } + } + if (getAdInfoType(entrie) == TYPE_FUNCTION_DECLARATION){ + if (parant_scope == 0) { + + fprintf(file_ptr, + "%-17s: %06d : :%-21s: %-28s\n", + entrie->theName, current_scope, + getType(entrie), + "Function"); + } else { + fprintf(file_ptr, "%-17s: %06d : %06d : %-21s: %-28s\n", + entrie->theName, current_scope, parant_scope, + getType(entrie), + "Function"); + } + } +} if (table->Children_Scope != NULL) { ListOfTable *node = table->Children_Scope; for (; node != NULL; node = node->next) {