checking diff

This commit is contained in:
Partho
2025-04-04 21:12:11 -04:00
parent a5e1acefde
commit 6a6677ccb5
3 changed files with 13 additions and 33 deletions

View File

@ -154,7 +154,7 @@ definition:
{ {
//We are scanning through the dblock scope to get the length of the dblock (num of elements) from getRecSize //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. //and then putting it in the entry that we created above.
setRecSize(look_up(cur, $2), getRecSize(cur)); setRecSize(look_up(getParent(cur), $2), getRecSize(cur));
cur = getParent(cur); cur = getParent(cur);
} }
@ -206,27 +206,7 @@ definition:
CreateEntry(cur,type_of_param_type, type_of_param, $4, getAdInfo(type_of_param)); CreateEntry(cur,type_of_param_type, type_of_param, $4, getAdInfo(type_of_param));
} }
R_PAREN ASSIGN sblock //leaving scope is being taken care of in sblock R_PAREN ASSIGN sblock //leaving scope is being taken care of in sblock
/* | ID
{
TableNode *node = table_lookup(getAncestor(cur), $1);
if (node == undefined) {
printdebug("null check");
}
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) {
printdebug("function not declared at line %d, column %d", @1.first_line, @1.first_column);
} else {
setStartLine(node, @1.first_line);
setAsKeyword(node, false);
}
cur = CreateScope(cur, 0, 0);
} L_PAREN ID {
printdebug("Currently see a function definition taking only one parameter (no as) of name %s and argument name %s",
$1,$4);
CreateEntry(cur, getParameter(table_lookup(getAncestor(cur), getType(table_lookup(getAncestor(cur), $<words>1)))), $<words>4, NULL);
}R_PAREN ASSIGN sblock */
| ID { | ID {
TableNode *node = table_lookup(getAncestor(cur), $1); TableNode *node = table_lookup(getAncestor(cur), $1);
if (node == undefined) { if (node == undefined) {
@ -394,7 +374,7 @@ id_or_types:
ID ID
{ {
printdebug("string of id is %s in ID pattern of id_or_type rule.", $1); printdebug("string of id is %s in ID pattern of id_or_type rule.", $1);
$$ = look_up(cur, $1); $$ = table_lookup(getAncestor(cur), $1);
} }
| types | types
@ -428,11 +408,11 @@ simple_statement:
{ {
if(strcmp(getName($1), getName($3)) == 0) { if(strcmp(getName($1), getName($3)) == 0) {
printdebug("Passed standard type check; assignable = expression"); printdebug("Passed standard type check; assignable = expression");
} else if((strcmp(getName($1), "array") == 0) && (strcmp(getName($3), "address") == 0)) { } else if((strcmp(getType($1), "array") == 0) && (strcmp(getName($3), "address") == 0)) {
printdebug("%s[☺] Passed array type check; %s = %s", COLOR_GREEN, getName($1), getName($3)); printdebug("%s[☺] Passed array type check; %s = %s", COLOR_GREEN, getName($1), getName($3));
} else if((strcmp(getName($1), "record") == 0) && (strcmp(getName($3), "address") == 0)) { } else if((strcmp(getType($1), "record") == 0) && (strcmp(getName($3), "address") == 0)) {
printdebug("%s[☺] Passed address type check; %s = %s", COLOR_GREEN, getName($1), getName($3)); printdebug("%s[☺] Passed address type check; %s = %s", COLOR_GREEN, getName($1), getName($3));
} else if((strcmp(getName($1), "function type primitive") == 0) && (strcmp(getName($3), "address") == 0)) { } else if((strcmp(getType($1), "function type primitive") == 0) && (strcmp(getName($3), "address") == 0)) {
printdebug("%s[☺] Passed function type primitive type check; %s = %s", COLOR_GREEN, getName($1), getName($3)); printdebug("%s[☺] Passed function type primitive type check; %s = %s", COLOR_GREEN, getName($1), getName($3));
// } else if () { // } else if () {
@ -613,7 +593,7 @@ expression:
| assignable | assignable
{ {
printdebug("assignable expression. current type is %s",$1); printdebug("assignable expression. current type is %s",$1);
$$= getTypeEntry($1);//idk if this is correct $$= getTypeEntry($1);
} }
| L_PAREN expression R_PAREN | L_PAREN expression R_PAREN
@ -648,7 +628,7 @@ assignable:
} }
ablock ablock
{ {
int type = getAdInfoType(look_up(cur, getName($1))); int type = getAdInfoType(look_up(getParent(cur), getName($1)));
printdebug("%stype is %d", COLOR_PURPLE, type); printdebug("%stype is %d", COLOR_PURPLE, type);
printdebug("%s", $1); printdebug("%s", $1);
@ -658,7 +638,7 @@ assignable:
printdebug("as function"); printdebug("as function");
//char *funtype = getType(look_up(cur, $1)); //char *funtype = getType(look_up(cur, $1));
printdebug("%s", getType(look_up(cur, getName($1)))); printdebug("%s", getType(look_up(cur, getName($1))));
TableNode *param = getParameter(look_up(cur, getType(look_up(cur, getName($1))))); TableNode *param = getParameter(look_up(getParent(cur), getName($1)));
SymbolTable *recList = getRecList(param); SymbolTable *recList = getRecList(param);
TableNode *lastCheckedRef = getFirstEntry(recList); TableNode *lastCheckedRef = getFirstEntry(recList);
TableNode *lastCheckedAct = getFirstEntry(cur); TableNode *lastCheckedAct = getFirstEntry(cur);
@ -669,7 +649,7 @@ assignable:
//this isn't very efficient, but will hopefully work //this isn't very efficient, but will hopefully work
while (lastCheckedAct != NULL && lastCheckedRef != NULL) { while (lastCheckedAct != NULL && lastCheckedRef != NULL) {
if (strcmp(getName(lastCheckedAct), getType(lastCheckedRef)) != 0) { if (strcmp(getName(lastCheckedAct), getName(lastCheckedRef)) != 0) {
printdebug("expected %s. expression in function call got %s. at line %d and column %d",getType(lastCheckedRef), getName(lastCheckedAct), @3.first_line, @3.first_column); printdebug("expected %s. expression in function call got %s. at line %d and column %d",getType(lastCheckedRef), getName(lastCheckedAct), @3.first_line, @3.first_column);
printdebug("%d", strcmp(getName(lastCheckedAct), getName(lastCheckedRef))); printdebug("%d", strcmp(getName(lastCheckedAct), getName(lastCheckedRef)));
} }
@ -691,7 +671,7 @@ assignable:
printdebug("expected %s expression in function call but got %s at line %d and column %d",expected, actual, @3.first_line, @3.first_column); printdebug("expected %s expression in function call but got %s at line %d and column %d",expected, actual, @3.first_line, @3.first_column);
} }
} }
$$ = getReturn((look_up(cur, getType(look_up(cur, getName($1)))))); $$ = getReturn((table_lookup(getAncestor(cur), getType($1))));
printdebug("[ASSIGNABLE - RULE 2] assignable = type: %s | name_func = %s", getName($$), getName($1)); printdebug("[ASSIGNABLE - RULE 2] assignable = type: %s | name_func = %s", getName($$), getName($1));
} else if (type == TYPE_ARRAY_TYPE) { } else if (type == TYPE_ARRAY_TYPE) {

View File

@ -143,7 +143,7 @@ int run(FILE *alpha) {
if (st_flag != NULL) { if (st_flag != NULL) {
yyparse(); yyparse();
print_symbol_table(getAncestor(cur), st_flag); print_symbol_table(top, st_flag);
fclose(st_flag); fclose(st_flag);
if (yyin != NULL) { if (yyin != NULL) {
fclose(yyin); fclose(yyin);

View File

@ -1330,7 +1330,7 @@ SymbolTable *getParent(SymbolTable *st) {
if (st->Parent_Scope == NULL) { if (st->Parent_Scope == NULL) {
printdebug("passed a top level scope to getParent function. " printdebug("passed a top level scope to getParent function. "
"Invalid."); "Invalid.");
return NULL; return st;
} }
return st->Parent_Scope; return st->Parent_Scope;
} }