From 5e749eb1ac80c9338de329db044c2c49580554e6 Mon Sep 17 00:00:00 2001 From: Annie Date: Fri, 4 Apr 2025 10:16:45 -0400 Subject: [PATCH] updated 3756156 to use table nodes up until comment in grammar.y --- src/grammar.y | 144 +++++++++++++++++++++++++------------------------- 1 file changed, 72 insertions(+), 72 deletions(-) diff --git a/src/grammar.y b/src/grammar.y index 8481152..7b39031 100644 --- a/src/grammar.y +++ b/src/grammar.y @@ -189,9 +189,9 @@ definition: } R_PAREN ASSIGN sblock - | ID //EVERYTHING UP UNTIL THIS POINT HAS BEEN CHECKED FOR $TN TYPES + | ID { - TableNode *node = table_lookup(getAncestor(cur), $1); + TableNode *node = table_lookup(getAncestor(cur), $1); if (node == undefined) { printdebug("null check"); } @@ -210,7 +210,7 @@ definition: CreateEntry(cur, getParameter(table_lookup(getAncestor(cur), getType(table_lookup(getAncestor(cur), $1)))), $4, NULL); }R_PAREN ASSIGN sblock | ID { - TableNode *node = table_lookup(getAncestor(cur), $1); + TableNode *node = table_lookup(getAncestor(cur), $1); if (node == undefined) { printdebug("function not declared at line %d, column %d", @1.first_line, @1.first_column); }else if(getAdInfoType(node) != TYPE_FUNCTION_DECLARATION){ @@ -223,7 +223,7 @@ definition: } cur = CreateScope(cur, 0, 0); }AS L_PAREN { - TableNode *parameter = getParameter(table_lookup(getAncestor(cur), getType(table_lookup(getAncestor(cur), $1)))); + TableNode *parameter = getParameter(table_lookup(getAncestor(cur), getType(table_lookup(getAncestor(cur), $1)))); printdebug("parameter type: %s", getType(parameter)); if (parameter == undefined) { printdebug("function defined with as, but parameter is undefined at line %d, column %d", @1.first_line, @1.first_column); @@ -265,11 +265,11 @@ idlist: if (getNextEntry(entry) == NULL) { printdebug("too many parameters at line %d column %d", @1.first_line, @1.first_column); } - addName(entry, $1); + addName(entry, 1); } COMMA idlist { - $$ = $4 + 1; + $$ = $4 + 1; } | ID @@ -334,8 +334,8 @@ declaration_list: declaration: id_or_types COLON ID { - printdebug("ID/TYPE: %s, ID: %s", $1, $3) ; - CreateEntry(cur,table_lookup(getAncestor(cur),$1),$3,NULL); + printdebug("ID/TYPE: %s, ID: %s", getName($1), $3) ; + CreateEntry(cur,$1,$3,NULL); } ; @@ -350,7 +350,7 @@ id_or_types: | types { - printdebug("string of type is %s in types pattern of id_or_type rule.",$1); + printdebug("string of type is %s in types pattern of id_or_type rule.",getName($1)); $$ = $1; } ; @@ -377,22 +377,22 @@ compound_statement: simple_statement: assignable ASSIGN expression { - if(strcmp($1, $3) == 0) { + if(strcmp(getType($1), getType($3)) == 0) { printdebug("Passed standard type check; assignable = expression"); - } else if((strcmp(getType(look_up(cur, $1)), "array") == 0) && (strcmp($3, "address") == 0)) { - printdebug("%s[☺] Passed array type check; %s = %s", COLOR_GREEN, $1, $3); - } else if((strcmp(getType(look_up(cur, $1)), "record") == 0) && (strcmp($3, "address") == 0)) { - printdebug("%s[☺] Passed address type check; %s = %s", COLOR_GREEN, $1, $3); - } else if((strcmp(getType(look_up(cur, $1)), "function type primitive") == 0) && (strcmp($3, "address") == 0)) { - printdebug("%s[☺] Passed function type primitive type check; %s = %s", COLOR_GREEN, $1, $3); + } else if((strcmp(getType($1), "array") == 0) && (strcmp($3, "address") == 0)) { + printdebug("%s[☺] Passed array type check; %s = %s", COLOR_GREEN, getType($1), getType($3)); + } else if((strcmp(getType($1), "record") == 0) && (strcmp($3, "address") == 0)) { + printdebug("%s[☺] Passed address type check; %s = %s", COLOR_GREEN, getType($1), getType($3)); + } else if((strcmp(getType($1), "function type primitive") == 0) && (strcmp(getType($3), "address") == 0)) { + printdebug("%s[☺] Passed function type primitive type check; %s = %s", COLOR_GREEN, getType($1), getType($3)); // } else if () { // } else if(strcmp(getType(table_lookup(cur, $1)), getType(table_lookup(cur, $3))) == 0) { // printdebug("%s[] Passed double lookup type check; %s = %s", COLOR_GREEN, $1, $3); } else { printdebug("%s[TYPE ERROR] %sMismatch at %sline %d and column %d%s", COLOR_ORANGE, COLOR_WHITE, COLOR_YELLOW, @2.first_line, @2.first_column, COLOR_WHITE); - printdebug(" - Invalid types %s$1: %s and $3: %s%s", COLOR_YELLOW, $1, $3, COLOR_WHITE); - printdebug(" - %sgetType for address: %s", COLOR_YELLOW, getType(look_up(cur, $1))); + printdebug(" - Invalid types %s$1: %s and $3: %s%s", COLOR_YELLOW, getType($1), getType($3), COLOR_WHITE); + printdebug(" - %sgetType for address: %s", COLOR_YELLOW, getType($1)); } } @@ -409,8 +409,8 @@ rec_op: ablock: L_PAREN argument_list R_PAREN { - $$ = $2; - printdebug("ablock is %d", $$); + $$ = $2; + printdebug("ablock is %d", $$); } ; @@ -419,15 +419,15 @@ ablock: argument_list: expression COMMA argument_list { - CreateEntry(cur, look_up(cur, $1), $1, NULL); - $$ = $3 + 1; - printdebug("[ARGUMENT_LIST] argument list is %d", $$); + CreateEntry(cur, $1, getName($1), NULL); + $$ = $3 + 1; + printdebug("[ARGUMENT_LIST] argument list is %d", $$); } | expression { - CreateEntry(cur, look_up(cur, $1), $1, NULL); - $$ = 1; printdebug("[ARGUMENT_LIST] argument list is %d", $$); + CreateEntry(cur, $1, getName($1), NULL); + $$ = 1; printdebug("[ARGUMENT_LIST] argument list is %d", $$); } ; @@ -437,15 +437,15 @@ expression: constant { printdebug("constant expression"); - $$ = $1; + $$ = $1; } | SUB_OR_NEG expression %prec UMINUS { printdebug("negative expression"); - if(strcmp($2,"integer") != 0) { + if($2 != integ) { printdebug("cant negate something not an integer at line %d and column %d",@2.first_line,@2.first_column); - $$=strdup("undefined"); + $$=undefined; } else { $$=$2; } @@ -454,133 +454,133 @@ expression: | NOT expression { printdebug("not expression"); - if(strcmp($2,"Boolean")==0) { + if($2 == boo) { $$=$2; } else { - $$=strdup("undefined"); - printdebug("mismatch at line %d and column %d. Invalid type being negated is %s", @1.first_line,@1.first_column,$2); + $$=undefined; + printdebug("mismatch at line %d and column %d. Invalid type being negated is %s", @1.first_line,@1.first_column,getName($2)); } } | expression ADD expression { printdebug("add expression"); - if(strcmp($1,$3)==0 && strcmp($1,"integer")==0) { - $$=strdup("integer"); + if($1 == $3 && $1 == integ) { + $$=$1; } else { - printdebug("mismatch at line %d and column %d. Invalid types %s and %s.", @2.first_line,@2.first_column,$1,$3); - $$=strdup("undefined"); + printdebug("mismatch at line %d and column %d. Invalid types %s and %s.", @2.first_line,@2.first_column,getName($1),getName($3)); + $$=undefined; } } | expression SUB_OR_NEG expression { printdebug("sub or neg expression"); - if(strcmp($1,$3)==0 &&strcmp($1,"integer")==0) { - $$=strdup("integer"); + if($1 == $3 && $1 == integ) { + $$=$1; } else { - printdebug("mismatch at line %d and column %d. Invalid types %s and %s.", @2.first_line,@2.first_column,$1,$3); - $$=strdup("undefined"); + printdebug("mismatch at line %d and column %d. Invalid types %s and %s.", @2.first_line,@2.first_column,getName($1),getName($3)); + $$=undefined; } } | expression MUL expression { printdebug("multiply expression"); - if(strcmp($1,$3)==0 &&strcmp($1,"integer")==0) { - $$=strdup("integer"); + if($1 == $3 && $1 == integ) { + $$=$1; } else{ - printdebug("mismatch at line %d and column %d. Invalid types %s and %s.", @2.first_line,@2.first_column,$1,$3); - $$=strdup("undefined"); + printdebug("mismatch at line %d and column %d. Invalid types %s and %s.", @2.first_line,@2.first_column,getName($1),getName($3)); + $$=undefined; } } | expression DIV expression { printdebug("divide expression"); - if(strcmp($1,$3)==0 && strcmp($1,"integer")==0) { - $$=strdup("integer"); + if(strcmp($1 == $3 && $1 == integ) { + $$=$1; } else { - printdebug("mismatch at line %d and column %d. Invalid types %s and %s.", @2.first_line,@2.first_column,$1,$3); - $$=strdup("undefined"); + printdebug("mismatch at line %d and column %d. Invalid types %s and %s.", @2.first_line,@2.first_column,getName($1),getName($3)); + $$=undefined; } } | expression REM expression { printdebug("remainder expression"); - if(strcmp($1,$3)==0 && strcmp($1,"integer")==0) { - $$=strdup("integer"); + if($1 == $3 && $1 == integ) { + $$=$1; } else { - printdebug("mismatch at line %d and column %d. Invalid types %s and %s.", @2.first_line,@2.first_column,$1,$3); - $$=strdup("undefined"); + printdebug("mismatch at line %d and column %d. Invalid types %s and %s.", @2.first_line,@2.first_column,getName($1),getName($3)); + $$=undefined; } } | expression AND expression { printdebug("AND expression"); - if(strcmp($1,$3)==0 && strcmp($1,"Boolean")==0) { - $$=strdup("Boolean"); + if($1 == $3 && $1 == boo { + $$=$1; } else{ - printdebug("mismatch at line %d and column %d. Invalid types %s and %s.", @2.first_line,@2.first_column,$1,$3); - $$=strdup("undefined"); + printdebug("mismatch at line %d and column %d. Invalid types %s and %s.", @2.first_line,@2.first_column,getName($1),getName($3)); + $$=undefined; } } | expression OR expression { printdebug("OR"); - if(strcmp($1,$3)==0 && strcmp($1,"Boolean")==0) { - $$=strdup("Boolean"); + if(strcmp($1 == $3 && $1 == boo) { + $$=$1; } else { - printdebug("mismatch at line %d and column %d. Invalid types %s and %s.", @2.first_line,@2.first_column,$1,$3); - $$=strdup("undefined"); + printdebug("mismatch at line %d and column %d. Invalid types %s and %s.", @2.first_line,@2.first_column,getName($1),getName($3)); + $$=undefined; } } - + | expression LESS_THAN expression { printdebug("less than expression"); - if(strcmp($1,$3)==0 && strcmp($1,"integer")==0) { - $$=strdup("Boolean"); + if($1 == $3 && $1==integ) { + $$=boo; } else { - printdebug("mismatch at line %d and column %d. Invalid types %s and %s.", @2.first_line,@2.first_column,$1,$3); - $$=strdup("undefined"); + printdebug("mismatch at line %d and column %d. Invalid types %s and %s.", @2.first_line,@2.first_column,getName($1),getName($3)); + $$=undefined; } } | expression EQUAL_TO expression { printdebug("equals check expression"); - if(strcmp($1,$3)==0) { - $$=strdup("Boolean"); + if($1 == $3 && $1 != undefined) { + $$=boo; } else { - printdebug("mismatch at line %d and column %d. Invalid types %s and %s", @2.first_line,@2.first_column,$1,$3); - $$=strdup("undefined"); + printdebug("mismatch at line %d and column %d. Invalid types %s and %s", @2.first_line,@2.first_column,getName($1),getName($3)); + $$ = undefined; } } | assignable { printdebug("assignable expression. current type is %s",$1); - $$=$1; + $$= getTypeEntry($1);//idk if this is correct } | L_PAREN expression R_PAREN { - printdebug("paren expression. current type is %s",$2); + printdebug("paren expression. current type is %s",getName($2)); $$=$2; } | memOp assignable { - $$ = strdup("address"); + $$ = addr; } ; - +//UPDATED $$ for tablenodes to this point // prolly right, check back with me later // add array case