fixed most symbol table structure issues. Working on print symbol table

This commit is contained in:
Partho Bhattacharya
2025-03-27 04:00:30 -04:00
parent 04418cc75d
commit c4ad1547bf
4 changed files with 23 additions and 11 deletions

View File

@ -55,4 +55,4 @@ clean:
rm -f *.st
rm -rf out
rm -rf tmp
rm -f parser
rm -f parser

View File

@ -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;

View File

View File