diff --git a/src/grammar.y b/src/grammar.y index 9e765e2..b464641 100644 --- a/src/grammar.y +++ b/src/grammar.y @@ -1,3 +1,4 @@ + /* Syntax Analyzer with Bison (3.8.2) */ /* The Translators - Spring 2025 */ @@ -245,37 +246,10 @@ simple_statement: ; assignable: -ID {TableNode *node = table_lookup(cur, $1); - printf("%s\n", $1); - if (node == NULL) { - printf("could not find %s in current scope\n", $1); - node = table_lookup(getAncestor(cur), $1); - if (node != NULL && getAdInfoType(node) == TYPE_FUNCTION_DECLARATION) { - if (getAsKeyword(node)) { - node = table_lookup(getAncestor(cur), getType(node)); - $$ = getRecLength(getParameter(node)); - } else { - $$ = 1; - } - } - else { - printf("assignable not defined as correct type at line %d, column %d\n", @1.first_line, @1.first_column); - } - } else if (getAdInfoType(node) == TYPE_ARRAY) { - $$ = getNumArrDim(node); - } else { - $$ = getName(node); - } -} -| assignable ablock {if ($1 != $2) { - printf("invalid number of expressions in ablock at line %d, column %d\n", @1.first_line, @1.first_column); - } - $$ = getName(getReturn(look_up(cur, $1))); -} -| assignable rec_op ID {TableNode * tn; printf("this is assignable.id %s\n", getType(look_up(cur, $1))); - if(NULL != (tn = table_lookup(getRecList(look_up(cur, $1)), $3))) - {$$ = "test";} -} + ID {$$ = $1; } + | assignable ablock {$$ = getName(getReturn(look_up(cur, $1)));} + | assignable rec_op ID {if(undefined != (tn = table_lookup(getRecList(look_up(cur, $1)), $3))) + {$$ = getType(tn);}} ; rec_op : diff --git a/src/symbol_table.c b/src/symbol_table.c index dabcafa..123c6a8 100644 --- a/src/symbol_table.c +++ b/src/symbol_table.c @@ -44,7 +44,8 @@ typedef enum { // size TYPE_PRIMITIVE = 6, //likely NULL - TYPE_ALL_ELSE = 7 + TYPE_ALL_ELSE = 7, + TYPE_UNDEFINED = 8 } types; @@ -214,7 +215,13 @@ int getRecSize(SymbolTable* tn){ } // below function takes a bool to see if parameter should be decomposed or not -// note that functions only take one input and have one output +assignable: + ID {$$ = $1; } + | assignable ablock {$$ = getName(getReturn(look_up(cur, $1)));} + | assignable rec_op ID {TableNode * tn; if(NULL != (tn = table_lookup(getRecList(look_up(cur, $1)), $3))) + {$$ = getType(tn);} + } + ;// note that functions only take one input and have one output // using "as" the input record can be decomposed to give the illusion of // multiple inputs Below function also has the line number where the function is // first defined @@ -488,7 +495,10 @@ int getAdInfoType(TableNode* tn){ if(strcmp(getType(tn),getName(arrayprim))==0){ return TYPE_ARRAY; } - else{ + if(strcmp(getType(tn),getName(undefined))==0){ + return TYPE_UNDEFINED; + } + else{ return TYPE_FUNCTION_DECLARATION; } } @@ -637,6 +647,7 @@ 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");