From d1aa7f7e0f570d7ac63e687039f8f0cb88e93fe7 Mon Sep 17 00:00:00 2001 From: Scarlett Date: Fri, 4 Apr 2025 15:42:50 -0400 Subject: [PATCH] =?UTF-8?q?Ready=20for=20Dev!=20=F0=9F=8E=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/grammar.y | 18 ++++++++-- src/runner.c | 14 ++++++-- src/symbol_table.c | 55 ++++++++++++++--------------- tests/sprint2/test/sp2_llnode.alpha | 1 + 4 files changed, 55 insertions(+), 33 deletions(-) diff --git a/src/grammar.y b/src/grammar.y index 63f2034..7b925f6 100644 --- a/src/grammar.y +++ b/src/grammar.y @@ -196,7 +196,7 @@ definition: printdebug("function defined with as, but parameter is type %s at line %d, column %d", getType(parameter),@1.first_line, @1.first_column); } else { for (TableNode* entry = getFirstEntry(getRecList(parameter)); entry!= NULL; entry = getNextEntry(entry)) { - CreateEntry(cur, entry, NULL, NULL); + CreateEntry(cur, entry->theType, NULL, NULL); } } } @@ -258,8 +258,11 @@ idlist: sblock: L_BRACE { - if (getLine(cur) != 0 && getColumn(cur)) { + if (getLine(cur) != 0) { cur = CreateScope(cur,@1.first_line,@1.first_column); + } else { + setLineNumber(cur, @1.first_line); + setColumnNumber(cur,@1.first_line); } } statement_list @@ -288,7 +291,16 @@ sblock: dblock: - L_BRACKET declaration_list R_BRACKET; + L_BRACKET + { + if(getLine(cur)==0) { + setLineNumber(cur, @1.first_line); + setColumnNumber(cur,@1.first_line); + } else { + cur = CreateScope(cur,@1.first_line,@1.first_column); + } + } + declaration_list R_BRACKET; diff --git a/src/runner.c b/src/runner.c index 5f903c3..578fa22 100644 --- a/src/runner.c +++ b/src/runner.c @@ -134,7 +134,16 @@ int run(FILE *alpha) { if (st_flag != NULL) { yyparse(); - print_symbol_table(getAncestor(cur), st_flag); + + if (cur == NULL) { + printdebug("%s[FATAL] cur is null", COLOR_LIGHTRED); + } + + if (top == NULL) { + printdebug("%s[FATAL] top is null", COLOR_LIGHTRED); + } + + print_symbol_table(top, st_flag); fclose(st_flag); if (yyin != NULL) { fclose(yyin); @@ -144,7 +153,8 @@ int run(FILE *alpha) { yyparse(); FILE *f = fdopen(1, "w"); - print_symbol_table(getAncestor(cur), f); + + print_symbol_table(top, f); fclose(f); if (yyin != NULL) { diff --git a/src/symbol_table.c b/src/symbol_table.c index f458769..f749b00 100644 --- a/src/symbol_table.c +++ b/src/symbol_table.c @@ -186,7 +186,7 @@ int getRecSize(SymbolTable *tn) { "passed in NULL SymbolTable for getRecSize. Invalid"); return -1; } - int s = 0; + int s = 1; TableNode *cur = getFirstEntry(tn); if (cur != NULL) { while (getNextEntry(cur) != NULL) { @@ -772,7 +772,6 @@ TableNode *look_up(SymbolTable *table, char *x) { } void print_symbol_table(SymbolTable *table, FILE *file_ptr) { - if (table == NULL) { printdebug( "%s[FATAL] passed in NULL table to print_symbol_table", @@ -781,14 +780,14 @@ void print_symbol_table(SymbolTable *table, FILE *file_ptr) { } if (table->Parent_Scope == NULL) { - fprintf(file_ptr, "%-17s: %-6s : %-6s : %-21s: %-28s\n", "NAME", + fprintf(file_ptr, "%-25s: %-6s : %-6s : %-25s: %-30s\n", "NAME", "SCOPE", "PARENT", "TYPE", "Extra annotation"); } TableNode *entrie = table->entries; - fprintf(file_ptr, "-----------------:--------:--------:----------------" - "------:---------" - "--------------------\n"); + fprintf(file_ptr, + "-------------------------:--------:--------:------------------" + "--------:------------------------------\n"); int parant_scope = 0; int current_scope = 0; if (table->Parent_Scope != NULL) { @@ -800,7 +799,7 @@ void print_symbol_table(SymbolTable *table, FILE *file_ptr) { current_scope = 1001; } if (entrie == NULL) { - fprintf(file_ptr, "%-17s: %06d : %06d : %-21s: %-28s\n", "", + fprintf(file_ptr, "%-25s: %06d : %06d : %-25s: %-30s\n", "", current_scope, parant_scope, "", "Empty Scope"); } for (; entrie != NULL; entrie = getNextEntry(entrie)) { @@ -808,8 +807,8 @@ void print_symbol_table(SymbolTable *table, FILE *file_ptr) { if (parant_scope == 0) { fprintf(file_ptr, - "%-17s: %06d : : %-21d -> " - "%-21s: %-28s\n", + "%-25s: %06d : : %d -> %-20s: " + "%-30s\n", entrie->theName, current_scope, entrie->additionalinfo->ArrayAdInfo ->numofdimensions, @@ -818,8 +817,8 @@ void print_symbol_table(SymbolTable *table, FILE *file_ptr) { "Type of Array"); } else { fprintf(file_ptr, - "%-17s: %06d : %06d : %-21d -> %-21s: " - "%-28s\n", + "%-25s: %06d : : %d -> %-20s: " + "%-30s\n", entrie->theName, current_scope, parant_scope, entrie->additionalinfo->ArrayAdInfo @@ -833,16 +832,16 @@ void print_symbol_table(SymbolTable *table, FILE *file_ptr) { if (parant_scope == 0) { fprintf(file_ptr, - "%-17s: %06d : :%-21s: " - "elements-%-28d\n", + "%-25s: %06d : : %-25s: " + "elements-%-30d\n", entrie->theName, current_scope, "record", entrie->additionalinfo->RecAdInfo ->numofelements); } else { fprintf(file_ptr, - "%-17s: %06d : %06d : %-21s: " - "elements-%-28d\n", + "%-25s: %06d : %06d : %-25s: " + "elements-%-30d\n", entrie->theName, current_scope, parant_scope, "record", entrie->additionalinfo->RecAdInfo @@ -854,14 +853,14 @@ void print_symbol_table(SymbolTable *table, FILE *file_ptr) { fprintf( file_ptr, - "%-17s: %06d : :%-21s: size-%-28d " + "%-25s: %06d : : %-25s: size-%d " "bytes\n", entrie->theName, current_scope, "Primitive", entrie->additionalinfo->PrimAdInfo->size); } else { fprintf( file_ptr, - "%-17s: %06d : %06d : %-21s: size-%-28d " + "%-25s: %06d : %06d : %-25s: size-%-30d " "bytes\n", entrie->theName, current_scope, parant_scope, "Primitive", @@ -872,8 +871,8 @@ void print_symbol_table(SymbolTable *table, FILE *file_ptr) { if (parant_scope == 0) { fprintf(file_ptr, - "%-17s: %06d : : %-21s -> " - "%-21s: %-28s\n", + "%-25s: %06d : : %-25s -> " + "%-25s: %-30s\n", entrie->theName, current_scope, entrie->additionalinfo->FunTypeAdInfo ->parameter->theName, @@ -882,8 +881,8 @@ void print_symbol_table(SymbolTable *table, FILE *file_ptr) { "Type of Function"); } else { fprintf(file_ptr, - "%-17s: %06d : %06d : %-21s -> %-21s: " - "%-28s\n", + "%-25s: %06d : %06d : %-25s -> %-21s: " + "%-30s\n", entrie->theName, current_scope, parant_scope, entrie->additionalinfo->FunTypeAdInfo @@ -897,12 +896,12 @@ void print_symbol_table(SymbolTable *table, FILE *file_ptr) { if (parant_scope == 0) { fprintf(file_ptr, - "%-17s: %06d : :%-21s: %-28s\n", + "%-25s: %06d : : %-25s: %-30s\n", entrie->theName, current_scope, getType(entrie), "User Defined"); } else { fprintf(file_ptr, - "%-17s: %06d : %06d : %-21s: %-28s\n", + "%-25s: %06d : %06d : %-25s: %-30s\n", entrie->theName, current_scope, parant_scope, getType(entrie), "User Defined"); @@ -912,12 +911,12 @@ void print_symbol_table(SymbolTable *table, FILE *file_ptr) { if (parant_scope == 0) { fprintf(file_ptr, - "%-17s: %06d : :%-21s: %-28s\n", + "%-25s: %06d : : %-25s: %-30s\n", entrie->theName, current_scope, "undefined", "undefined entry"); } else { fprintf(file_ptr, - "%-17s: %06d : %06d : %-21s: %-28s\n", + "%-25s: %06d : %06d : %-25s: %-30s\n", entrie->theName, current_scope, parant_scope, "undefined", "undefined entry"); @@ -940,9 +939,9 @@ void print_symbol_table(SymbolTable *table, FILE *file_ptr) { } } if (getParent(table) == NULL) { - fprintf(file_ptr, "-----------------:--------:--------:--------" - "--------------:-------" - "----------------------\n"); + fprintf(file_ptr, + "-------------------------:--------:--------:----------" + "----------------:------------------------------\n"); } } // get top most symbol table diff --git a/tests/sprint2/test/sp2_llnode.alpha b/tests/sprint2/test/sp2_llnode.alpha index 6b4912e..43007ef 100644 --- a/tests/sprint2/test/sp2_llnode.alpha +++ b/tests/sprint2/test/sp2_llnode.alpha @@ -9,6 +9,7 @@ function foo : T1 function bar1 : T2 function bar2 : T2 function make_list : list + make_list(a) := { [integer:orig_a; address: ret; address: curr; address: temp] if (a < 0 | a = 0) then {