continuing. need fix of makefile

This commit is contained in:
Partho
2025-03-28 18:02:40 -04:00
parent f217500b55
commit 227cec0b73
3 changed files with 144 additions and 90 deletions

View File

@ -650,7 +650,6 @@ TableNode *look_up(SymbolTable *table, char *x) {
}
void print_symbol_table(SymbolTable *table, FILE *file_ptr) {
if (table->Parent_Scope == NULL) {
fprintf(file_ptr, "%-17s: %-6s : %-6s : %-21s: %-28s\n", "NAME",
"SCOPE", "PARENT", "TYPE", "Extra annotation");
@ -673,87 +672,23 @@ 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) {
if (getAdInfoType(entrie) == TYPE_ARRAY){
for (; entrie != NULL; entrie = entrie->next) {
if (parant_scope == 0) {
/*have to update*/ if (strcmp(entrie->theType->theName,
"function primitive") ||
strcmp(entrie->theType->theName,
"array")) {
}
fprintf(file_ptr,
"%-17s: %06d : : %-21d -> %-21s: %-28s\n",
"%-17s: %06d : : %-21s: %-28s\n",
entrie->theName, current_scope,
entrie->additionalinfo->ArrayAdInfo->numofdimensions,
entrie->additionalinfo->ArrayAdInfo->typeofarray->theName,
"Type of Array");
} else {
fprintf(file_ptr, "%-17s: %06d : %06d : %-21d -> %-21s: %-28s\n",
entrie->theName, current_scope, parant_scope,
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");
entrie->theType->theName, "Extra annotation");
} else {
fprintf(file_ptr, "%-17s: %06d : %06d : %-21s: %-28s\n",
entrie->theName, current_scope, parant_scope,
getType(entrie),
"Function");
entrie->theType->theName, "Extra annotation");
}
}
}
if (table->Children_Scope != NULL) {
ListOfTable *node = table->Children_Scope;
for (; node != NULL; node = node->next) {
@ -766,6 +701,123 @@ void print_symbol_table(SymbolTable *table, FILE *file_ptr) {
"----------------------\n");
}
}
// void print_symbol_table(SymbolTable *table, FILE *file_ptr) {
// if (table->Parent_Scope == NULL) {
// fprintf(file_ptr, "%-17s: %-6s : %-6s : %-21s: %-28s\n", "NAME",
// "SCOPE", "PARENT", "TYPE", "Extra annotation");
// }
// TableNode *entrie = table->entries;
// fprintf(file_ptr, "-----------------:--------:--------:----------------"
// "------:---------"
// "--------------------\n");
// int parant_scope = 0;
// int current_scope = 0;
// if (table->Parent_Scope != NULL) {
// parant_scope = table->Parent_Scope->Line_Number * 1000 +
// table->Parent_Scope->Column_Number;
// current_scope =
// table->Line_Number * 1000 + table->Column_Number;
// } else {
// current_scope = 1001;
// }
// if (entrie == NULL) {
// fprintf(file_ptr, "%-17s: %06d : %06d : %-21s: %-28s\n", "",
// current_scope, parant_scope, "", "Empty Scope");
// }
// for (;entrie != NULL; entrie = entrie->next) {
// if (getAdInfoType(entrie) == TYPE_ARRAY){
// if (parant_scope == 0) {
// fprintf(file_ptr,
// "%-17s: %06d : : %-21d -> %-21s: %-28s\n",
// entrie->theName, current_scope,
// entrie->additionalinfo->ArrayAdInfo->numofdimensions,
// entrie->additionalinfo->ArrayAdInfo->typeofarray->theName,
// "Type of Array");
// } else {
// fprintf(file_ptr, "%-17s: %06d : %06d : %-21d -> %-21s: %-28s\n",
// entrie->theName, current_scope, parant_scope,
// 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) {
// print_symbol_table(node->table, file_ptr);
// }
// }
// if (table->Parent_Scope == NULL) {
// fprintf(file_ptr, "-----------------:--------:--------:--------"
// "--------------:-------"
// "----------------------\n");
// }
// }
//get top most symbol table
SymbolTable *getAncestor(SymbolTable *table) {
if(table == NULL){