This commit is contained in:
Scarlett
2025-04-02 15:03:29 -04:00
parent 20c372f134
commit 77c4106b1b
3 changed files with 63 additions and 45 deletions

View File

@ -132,7 +132,9 @@ definition:
| TYPE ID COLON C_INTEGER ARROW id_or_types
{printdebug("Currently see a array definition of name %s,storing type %s, of dimensions %d",
$2, $6, $4);
CreateEntry(cur, arrayprim, $2, CreateArrayInfo($4, look_up(cur, $6)));}
CreateEntry(cur, arrayprim, $2, CreateArrayInfo($4, look_up(cur, $6)));
printdebug("%sID: %s, dimensions: %d, typeOfArray: %s", COLOR_GREEN, $2, $4, $6);
}
| function_declaration
| TYPE ID COLON id_or_types ARROW id_or_types {
printdebug("Currently see a function type definition of name %s,parameter type %s, of return type %s",
@ -237,8 +239,12 @@ declaration_list:
;
declaration:
id_or_types COLON ID {printdebug("ID/TYPE: %s, ID: %s", $<words>1, $<words>3) ; CreateEntry(cur,table_lookup(getAncestor(cur),$<words>1),$<words>3,NULL); }
;
id_or_types COLON ID
{
printdebug("ID/TYPE: %s, ID: %s", $<words>1, $<words>3) ;
CreateEntry(cur,table_lookup(getAncestor(cur),$<words>1),$<words>3,NULL);
}
;
id_or_types:
ID {printdebug("string of id is %s in ID pattern of id_or_type rule.", $1); $$ = $1;}
@ -394,15 +400,21 @@ expression:
// add array case
// include type check for ablock in arrays - ablock is always the int of the elements in array/rec
assignable:
ID {$$ = getType(look_up(cur,$1)); printdebug("[ASSIGNABLE - RULE 1] assignable = type: %s | ID = %s", $$, $1);}
| assignable
ID
{
$$ = getType(look_up(cur,$1));
printdebug("[ASSIGNABLE - RULE 1] assignable = type: %s | ID = %s", $$, $1);}
| assignable
{
printdebug("%sBeginning rule 2 of assignable.", COLOR_CYAN);
cur = CreateScope(cur, -1,-1);
}
ablock
{
ablock {
int type = getAdInfoType(look_up(getParent(cur), $1));
printdebug("%stype is %d", COLOR_PURPLE, type);
if (type == TYPE_FUNCTION_DECLARATION) {
printdebug("%sEntering function call", COLOR_LIGHTGREEN);
if (getAsKeyword(look_up(getParent(cur), $1))) {
TableNode *param = getParameter(look_up(getParent(cur), $1));
SymbolTable *recList = getRecList(param);
@ -414,7 +426,7 @@ assignable:
//this isn't very efficient, but will hopefully work
while (lastCheckedAct != NULL && lastCheckedRef != NULL) {
if (strcmp(getName(lastCheckedAct), getName(lastCheckedRef)) != 0) {
printdebug("expected %s expression in function call but got %s at line %d and column %d",getName(lastCheckedRef), getName(lastCheckedAct), @3.first_line, @3.first_column);
printdebug("expected %s expression in function call but got %s at line %d and column %d",getType(lastCheckedRef), getName(lastCheckedAct), @3.first_line, @3.first_column);
}
lastCheckedAct = getNextEntry(lastCheckedAct);
TableNode *tn = getFirstEntry(recList);
@ -424,33 +436,39 @@ assignable:
lastCheckedRef = tn;
}
} else {
char *expected = getName(getParameter(look_up(getParent(cur), $1)));
char *actual = getType(getFirstEntry(cur));
if (strcmp(expected, actual) != 0) {
printdebug("expected %s expression in function call but got %s at line %d and column %d",expected, actual, @3.first_line, @3.first_column);
}
}
$$ = getName(getReturn(table_lookup(getAncestor(cur), $1)));
printdebug("[ASSIGNABLE - RULE 2] assignable = type: %s | name_func = %s", $$, $1);
} else if (type == TYPE_ARRAY) {
if (getNumArrDim(look_up(getParent(cur), $1)) != $<integ>2) {
printdebug("expected %d arguments but had %d at line %d and column %d\n", getNumArrDim(look_up(cur, $1)), $<integ>2, @2.first_line, @2.first_column);
}
for (TableNode *tn = getFirstEntry(cur); tn != NULL; tn = getNextEntry(tn)) {
if (strcmp(getName(tn), "integer") != 0) {
printdebug("expected only integer expressions in array ablock at line %d column %d", @3.first_line, @3.first_column);
}
}
$$ = getName(getArrType(look_up(getParent(cur), $1)));
printdebug("[ASSIGNABLE - RULE 2] assignable = type: %s | name_func = %s", $$, $1);
}
cur = getParent(cur);
}
| assignable rec_op ID {if(undefined != table_lookup(getRecList(table_lookup(getAncestor(cur), $1)), $3)){
{$$ = getName(table_lookup(getRecList(table_lookup(getAncestor(cur), $1)), $3));}}; printdebug("[ASSIGNABLE - RULE 3] assignable = type: %s | ID = %s", $$, $1);}
;
} else {
char *expected = getName(getParameter(look_up(getParent(cur), $1)));
char *actual = getType(getFirstEntry(cur));
if (strcmp(expected, actual) != 0) {
printdebug("expected %s expression in function call but got %s at line %d and column %d",expected, actual, @3.first_line, @3.first_column);
}
}
$$ = getName(getReturn(table_lookup(getAncestor(cur), $1)));
printdebug("[ASSIGNABLE - RULE 2] assignable = type: %s | name_func = %s", $$, $1);
} else if (type == TYPE_ARRAY_TYPE) {
printdebug("%sEntering array call", COLOR_LIGHTGREEN);
if (getNumArrDim(look_up(getParent(cur), $1)) != $<integ>2) {
printdebug("expected %d arguments but had %d at line %d and column %d\n", getNumArrDim(look_up(cur, $1)), $<integ>2, @2.first_line, @2.first_column);
}
// for (TableNode *tn = getFirstEntry(cur); tn != NULL; tn = getNextEntry(tn)) {
// if (strcmp(getName(tn), "integer") != 0) {
// printdebug("expected only integer expressions in array ablock at line %d column %d", @3.first_line, @3.first_column);
// }
// }
$$ = getName(getArrType(look_up(getParent(cur), $1)));
printdebug("[ASSIGNABLE - RULE 2] assignable = type: %s | name_func = %s", $$, $1);
}
cur = getParent(cur);
}
| assignable rec_op ID
{
if(undefined != table_lookup(getRecList(table_lookup(getAncestor(cur), $1)), $3)) {
$$ = getName(table_lookup(getRecList(table_lookup(getAncestor(cur), $1)), $3));
}
printdebug("[ASSIGNABLE - RULE 3] assignable = type: %s | ID = %s", $$, $1);
}
;
memOp:
RESERVE {printdebug("reserve expression");}