updated 3756156 to use table nodes up until comment in grammar.y

This commit is contained in:
Annie
2025-04-04 10:16:45 -04:00
parent 4f62851575
commit 5e749eb1ac

View File

@ -189,9 +189,9 @@ definition:
} }
R_PAREN ASSIGN sblock R_PAREN ASSIGN sblock
| ID //EVERYTHING UP UNTIL THIS POINT HAS BEEN CHECKED FOR $TN TYPES | ID
{ {
TableNode *node = table_lookup(getAncestor(cur), $<words>1); TableNode *node = table_lookup(getAncestor(cur), $1);
if (node == undefined) { if (node == undefined) {
printdebug("null check"); printdebug("null check");
} }
@ -210,7 +210,7 @@ definition:
CreateEntry(cur, getParameter(table_lookup(getAncestor(cur), getType(table_lookup(getAncestor(cur), $<words>1)))), $<words>4, NULL); CreateEntry(cur, getParameter(table_lookup(getAncestor(cur), getType(table_lookup(getAncestor(cur), $<words>1)))), $<words>4, NULL);
}R_PAREN ASSIGN sblock }R_PAREN ASSIGN sblock
| ID { | ID {
TableNode *node = table_lookup(getAncestor(cur), $<words>1); TableNode *node = table_lookup(getAncestor(cur), $1);
if (node == undefined) { if (node == undefined) {
printdebug("function not declared at line %d, column %d", @1.first_line, @1.first_column); printdebug("function not declared at line %d, column %d", @1.first_line, @1.first_column);
}else if(getAdInfoType(node) != TYPE_FUNCTION_DECLARATION){ }else if(getAdInfoType(node) != TYPE_FUNCTION_DECLARATION){
@ -223,7 +223,7 @@ definition:
} }
cur = CreateScope(cur, 0, 0); cur = CreateScope(cur, 0, 0);
}AS L_PAREN { }AS L_PAREN {
TableNode *parameter = getParameter(table_lookup(getAncestor(cur), getType(table_lookup(getAncestor(cur), $<words>1)))); TableNode *parameter = getParameter(table_lookup(getAncestor(cur), getType(table_lookup(getAncestor(cur), $1))));
printdebug("parameter type: %s", getType(parameter)); printdebug("parameter type: %s", getType(parameter));
if (parameter == undefined) { if (parameter == undefined) {
printdebug("function defined with as, but parameter is undefined at line %d, column %d", @1.first_line, @1.first_column); 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) { if (getNextEntry(entry) == NULL) {
printdebug("too many parameters at line %d column %d", @1.first_line, @1.first_column); printdebug("too many parameters at line %d column %d", @1.first_line, @1.first_column);
} }
addName(entry, $<words>1); addName(entry, 1);
} }
COMMA idlist COMMA idlist
{ {
$$ = $<integ>4 + 1; $$ = $4 + 1;
} }
| ID | ID
@ -334,8 +334,8 @@ declaration_list:
declaration: declaration:
id_or_types COLON ID id_or_types COLON ID
{ {
printdebug("ID/TYPE: %s, ID: %s", $<words>1, $<words>3) ; printdebug("ID/TYPE: %s, ID: %s", getName($1), $3) ;
CreateEntry(cur,table_lookup(getAncestor(cur),$<words>1),$<words>3,NULL); CreateEntry(cur,$1,$3,NULL);
} }
; ;
@ -350,7 +350,7 @@ id_or_types:
| 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; $$ = $1;
} }
; ;
@ -377,22 +377,22 @@ compound_statement:
simple_statement: simple_statement:
assignable ASSIGN expression assignable ASSIGN expression
{ {
if(strcmp($1, $3) == 0) { if(strcmp(getType($1), getType($3)) == 0) {
printdebug("Passed standard type check; assignable = expression"); printdebug("Passed standard type check; assignable = expression");
} else if((strcmp(getType(look_up(cur, $1)), "array") == 0) && (strcmp($3, "address") == 0)) { } else if((strcmp(getType($1), "array") == 0) && (strcmp($3, "address") == 0)) {
printdebug("%s[☺] Passed array type check; %s = %s", COLOR_GREEN, $1, $3); printdebug("%s[☺] Passed array type check; %s = %s", COLOR_GREEN, getType($1), getType($3));
} else if((strcmp(getType(look_up(cur, $1)), "record") == 0) && (strcmp($3, "address") == 0)) { } else if((strcmp(getType($1), "record") == 0) && (strcmp($3, "address") == 0)) {
printdebug("%s[☺] Passed address type check; %s = %s", COLOR_GREEN, $1, $3); printdebug("%s[☺] Passed address type check; %s = %s", COLOR_GREEN, getType($1), getType($3));
} else if((strcmp(getType(look_up(cur, $1)), "function type primitive") == 0) && (strcmp($3, "address") == 0)) { } 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, $1, $3); printdebug("%s[☺] Passed function type primitive type check; %s = %s", COLOR_GREEN, getType($1), getType($3));
// } else if () { // } else if () {
// } else if(strcmp(getType(table_lookup(cur, $1)), getType(table_lookup(cur, $3))) == 0) { // } 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); // printdebug("%s[] Passed double lookup type check; %s = %s", COLOR_GREEN, $1, $3);
} else { } 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("%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(" - 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(look_up(cur, $1))); printdebug(" - %sgetType for address: %s", COLOR_YELLOW, getType($1));
} }
} }
@ -409,8 +409,8 @@ rec_op:
ablock: ablock:
L_PAREN argument_list R_PAREN L_PAREN argument_list R_PAREN
{ {
$<integ>$ = $<integ>2; $$ = $2;
printdebug("ablock is %d", $<integ>$); printdebug("ablock is %d", $$);
} }
; ;
@ -419,15 +419,15 @@ ablock:
argument_list: argument_list:
expression COMMA argument_list expression COMMA argument_list
{ {
CreateEntry(cur, look_up(cur, $1), $1, NULL); CreateEntry(cur, $1, getName($1), NULL);
$<integ>$ = $<integ>3 + 1; $$ = $3 + 1;
printdebug("[ARGUMENT_LIST] argument list is %d", $<integ>$); printdebug("[ARGUMENT_LIST] argument list is %d", $$);
} }
| expression | expression
{ {
CreateEntry(cur, look_up(cur, $1), $1, NULL); CreateEntry(cur, $1, getName($1), NULL);
$<integ>$ = 1; printdebug("[ARGUMENT_LIST] argument list is %d", $<integ>$); $$ = 1; printdebug("[ARGUMENT_LIST] argument list is %d", $$);
} }
; ;
@ -437,15 +437,15 @@ expression:
constant constant
{ {
printdebug("constant expression"); printdebug("constant expression");
$$ = $<words>1; $$ = $1;
} }
| SUB_OR_NEG expression %prec UMINUS | SUB_OR_NEG expression %prec UMINUS
{ {
printdebug("negative expression"); 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); printdebug("cant negate something not an integer at line %d and column %d",@2.first_line,@2.first_column);
$$=strdup("undefined"); $$=undefined;
} else { } else {
$$=$2; $$=$2;
} }
@ -454,133 +454,133 @@ expression:
| NOT expression | NOT expression
{ {
printdebug("not expression"); printdebug("not expression");
if(strcmp($2,"Boolean")==0) { if($2 == boo) {
$$=$2; $$=$2;
} else { } else {
$$=strdup("undefined"); $$=undefined;
printdebug("mismatch at line %d and column %d. Invalid type being negated is %s", @1.first_line,@1.first_column,$2); 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 | expression ADD expression
{ {
printdebug("add expression"); printdebug("add expression");
if(strcmp($1,$3)==0 && strcmp($1,"integer")==0) { if($1 == $3 && $1 == integ) {
$$=strdup("integer"); $$=$1;
} else { } else {
printdebug("mismatch at line %d and column %d. Invalid types %s and %s.", @2.first_line,@2.first_column,$1,$3); printdebug("mismatch at line %d and column %d. Invalid types %s and %s.", @2.first_line,@2.first_column,getName($1),getName($3));
$$=strdup("undefined"); $$=undefined;
} }
} }
| expression SUB_OR_NEG expression | expression SUB_OR_NEG expression
{ {
printdebug("sub or neg expression"); printdebug("sub or neg expression");
if(strcmp($1,$3)==0 &&strcmp($1,"integer")==0) { if($1 == $3 && $1 == integ) {
$$=strdup("integer"); $$=$1;
} else { } else {
printdebug("mismatch at line %d and column %d. Invalid types %s and %s.", @2.first_line,@2.first_column,$1,$3); printdebug("mismatch at line %d and column %d. Invalid types %s and %s.", @2.first_line,@2.first_column,getName($1),getName($3));
$$=strdup("undefined"); $$=undefined;
} }
} }
| expression MUL expression | expression MUL expression
{ {
printdebug("multiply expression"); printdebug("multiply expression");
if(strcmp($1,$3)==0 &&strcmp($1,"integer")==0) { if($1 == $3 && $1 == integ) {
$$=strdup("integer"); $$=$1;
} else{ } else{
printdebug("mismatch at line %d and column %d. Invalid types %s and %s.", @2.first_line,@2.first_column,$1,$3); printdebug("mismatch at line %d and column %d. Invalid types %s and %s.", @2.first_line,@2.first_column,getName($1),getName($3));
$$=strdup("undefined"); $$=undefined;
} }
} }
| expression DIV expression | expression DIV expression
{ {
printdebug("divide expression"); printdebug("divide expression");
if(strcmp($1,$3)==0 && strcmp($1,"integer")==0) { if(strcmp($1 == $3 && $1 == integ) {
$$=strdup("integer"); $$=$1;
} else { } else {
printdebug("mismatch at line %d and column %d. Invalid types %s and %s.", @2.first_line,@2.first_column,$1,$3); printdebug("mismatch at line %d and column %d. Invalid types %s and %s.", @2.first_line,@2.first_column,getName($1),getName($3));
$$=strdup("undefined"); $$=undefined;
} }
} }
| expression REM expression | expression REM expression
{ {
printdebug("remainder expression"); printdebug("remainder expression");
if(strcmp($1,$3)==0 && strcmp($1,"integer")==0) { if($1 == $3 && $1 == integ) {
$$=strdup("integer"); $$=$1;
} else { } else {
printdebug("mismatch at line %d and column %d. Invalid types %s and %s.", @2.first_line,@2.first_column,$1,$3); printdebug("mismatch at line %d and column %d. Invalid types %s and %s.", @2.first_line,@2.first_column,getName($1),getName($3));
$$=strdup("undefined"); $$=undefined;
} }
} }
| expression AND expression | expression AND expression
{ {
printdebug("AND expression"); printdebug("AND expression");
if(strcmp($1,$3)==0 && strcmp($1,"Boolean")==0) { if($1 == $3 && $1 == boo {
$$=strdup("Boolean"); $$=$1;
} else{ } else{
printdebug("mismatch at line %d and column %d. Invalid types %s and %s.", @2.first_line,@2.first_column,$1,$3); printdebug("mismatch at line %d and column %d. Invalid types %s and %s.", @2.first_line,@2.first_column,getName($1),getName($3));
$$=strdup("undefined"); $$=undefined;
} }
} }
| expression OR expression | expression OR expression
{ {
printdebug("OR"); printdebug("OR");
if(strcmp($1,$3)==0 && strcmp($1,"Boolean")==0) { if(strcmp($1 == $3 && $1 == boo) {
$$=strdup("Boolean"); $$=$1;
} else { } else {
printdebug("mismatch at line %d and column %d. Invalid types %s and %s.", @2.first_line,@2.first_column,$1,$3); printdebug("mismatch at line %d and column %d. Invalid types %s and %s.", @2.first_line,@2.first_column,getName($1),getName($3));
$$=strdup("undefined"); $$=undefined;
} }
} }
| expression LESS_THAN expression | expression LESS_THAN expression
{ {
printdebug("less than expression"); printdebug("less than expression");
if(strcmp($1,$3)==0 && strcmp($1,"integer")==0) { if($1 == $3 && $1==integ) {
$$=strdup("Boolean"); $$=boo;
} else { } else {
printdebug("mismatch at line %d and column %d. Invalid types %s and %s.", @2.first_line,@2.first_column,$1,$3); printdebug("mismatch at line %d and column %d. Invalid types %s and %s.", @2.first_line,@2.first_column,getName($1),getName($3));
$$=strdup("undefined"); $$=undefined;
} }
} }
| expression EQUAL_TO expression | expression EQUAL_TO expression
{ {
printdebug("equals check expression"); printdebug("equals check expression");
if(strcmp($1,$3)==0) { if($1 == $3 && $1 != undefined) {
$$=strdup("Boolean"); $$=boo;
} else { } else {
printdebug("mismatch at line %d and column %d. Invalid types %s and %s", @2.first_line,@2.first_column,$1,$3); printdebug("mismatch at line %d and column %d. Invalid types %s and %s", @2.first_line,@2.first_column,getName($1),getName($3));
$$=strdup("undefined"); $$ = undefined;
} }
} }
| assignable | assignable
{ {
printdebug("assignable expression. current type is %s",$1); printdebug("assignable expression. current type is %s",$1);
$$=$1; $$= getTypeEntry($1);//idk if this is correct
} }
| L_PAREN expression R_PAREN | L_PAREN expression R_PAREN
{ {
printdebug("paren expression. current type is %s",$2); printdebug("paren expression. current type is %s",getName($2));
$$=$2; $$=$2;
} }
| memOp assignable | memOp assignable
{ {
$$ = strdup("address"); $$ = addr;
} }
; ;
//UPDATED $$ for tablenodes to this point
// prolly right, check back with me later // prolly right, check back with me later
// add array case // add array case