From 3fc7a6371a9abe377fea41f1f8a473f7b24d3aab Mon Sep 17 00:00:00 2001 From: Partho Date: Fri, 11 Apr 2025 19:00:24 -0400 Subject: [PATCH] have to finish idlist rules --- src/grammar.y | 25 +++++++++++-- src/symbol_table.c | 36 +++++++++++-------- src/symbol_table.h | 1 + .../sprint3/test/sp3_record_size_check.alpha | 2 ++ 4 files changed, 47 insertions(+), 17 deletions(-) create mode 100644 tests/sprint3/test/sp3_record_size_check.alpha diff --git a/src/grammar.y b/src/grammar.y index 579ebd5..dfc8db3 100644 --- a/src/grammar.y +++ b/src/grammar.y @@ -21,6 +21,7 @@ void yyerror(const char *err); int token_tracker; TableNode * tn; + int counter; %} %union { @@ -137,6 +138,8 @@ definition: //We are scanning through the dblock scope to get the length of the dblock (num of elements) from getRecSize //and then putting it in the entry that we created above. setRecSize(look_up(getParent(cur), $2), getRecSize(cur)); + //putting in all the offsets + setRecOffsetInfo(cur, look_up(getParent(cur),$2)); printdebug("Moving up a scope after seeing a record definition"); cur = getParent(cur); } @@ -236,6 +239,8 @@ definition: } } } + counter = 0; + printdebug("Created a new scope after seeing a function definition"); } idlist { printdebug("Currently see a function definition taking one paramter (with as) of name %s and number of arguments %d", $1,$5); } R_PAREN ASSIGN sblock //check sblock type @@ -273,7 +278,15 @@ function_declaration: idlist: ID { + counter ++; TableNode *entry = getFirstEntry(cur); + int count = 1; + while(count largest) { largest = s; @@ -222,7 +222,7 @@ TableNode *setRecOffsetInfo(SymbolTable* scope, TableNode *node) { counter++; this = getNextEntry(this); } - else if(getAdInfoType(this) == TYPE_ARRAY_TYPE){ + else if(getAdInfoType(this) == TYPE_ARRAY){ int s = 8; if (s > largest) { largest = s; @@ -237,12 +237,14 @@ TableNode *setRecOffsetInfo(SymbolTable* scope, TableNode *node) { counter++; this = getNextEntry(this); } - else if(getAdInfoType(this) == TYPE_RECORD_TYPE){ - int s = getRecTotal(this); + else if((getAdInfoType(this) == TYPE_RECORD) && (node != getTypeEntry(this))){ + int s = getRecTotal(getTypeEntry(this)); if (s > largest) { largest = s; } //make sure current location is aligned properly + printTableNode(this); + printTableNode(node); offsets[counter] = (total_size % s); total_size = total_size + offsets[counter]; counter++; @@ -253,7 +255,7 @@ TableNode *setRecOffsetInfo(SymbolTable* scope, TableNode *node) { this = getNextEntry(this); } else if(getAdInfoType(this) == TYPE_PRIMITIVE){ - int s = getPrimSize(this); + int s = getPrimSize(getTypeEntry(this)); if (s > largest) { largest = s; } @@ -1049,8 +1051,12 @@ TableNode *look_up(SymbolTable *table, char *x) { } int col_widths[5] = {30, 8, 8, 35, 35}; -void printline(FILE *file_ptr); -void printline(FILE *file_ptr) { +void printline(FILE *file_ptr, bool b); +void printline(FILE *file_ptr, bool b) { + if (b) { + fprintf(file_ptr, "oop\n"); + } + for (int i = 0; i < 5; i++) { for (int ii = 0; ii < col_widths[i]; ii++) { fprintf(file_ptr, "-"); @@ -1095,7 +1101,7 @@ void print_symbol_table(SymbolTable *table, FILE *file_ptr) { } TableNode *entry = table->entries; - printline(file_ptr); + printline(file_ptr, false); int parentScopeNum = 0; int currentScopeNum = 0; @@ -1213,7 +1219,7 @@ void print_symbol_table(SymbolTable *table, FILE *file_ptr) { } if (getParent(table) == NULL) { - printline(file_ptr); + printline(file_ptr, true); } } // get top most symbol table diff --git a/src/symbol_table.h b/src/symbol_table.h index 5f04f7c..6a33974 100644 --- a/src/symbol_table.h +++ b/src/symbol_table.h @@ -111,6 +111,7 @@ char *getType(TableNode *tn); char *getName(TableNode *tn); int getLine(SymbolTable *st); int getColumn(SymbolTable *st); +TableNode *getTypeEntry(TableNode *tn); TableNode *addName(TableNode *tn, char *str); SymbolTable *setLineNumber(SymbolTable *st, int line); SymbolTable *setColumnNumber(SymbolTable *st, int column); diff --git a/tests/sprint3/test/sp3_record_size_check.alpha b/tests/sprint3/test/sp3_record_size_check.alpha new file mode 100644 index 0000000..a6217fe --- /dev/null +++ b/tests/sprint3/test/sp3_record_size_check.alpha @@ -0,0 +1,2 @@ +type tom : [integer : x; integer: y] +type rec : [integer : x; tom : prev; character : c; character : d; Boolean: b; integer : y] \ No newline at end of file