working on tabel

This commit is contained in:
Partho Bhattacharya
2025-03-28 14:49:17 -04:00
parent 37dedf1818
commit cca01eb0b5
2 changed files with 19 additions and 34 deletions

View File

@ -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, $<words>1);
printf("%s\n", $1);
if (node == NULL) {
printf("could not find %s in current scope\n", $<words>1);
node = table_lookup(getAncestor(cur), $<words>1);
if (node != NULL && getAdInfoType(node) == TYPE_FUNCTION_DECLARATION) {
if (getAsKeyword(node)) {
node = table_lookup(getAncestor(cur), getType(node));
$<integ>$ = getRecLength(getParameter(node));
} else {
$<integ>$ = 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) {
$<integ>$ = getNumArrDim(node);
} else {
$<words>$ = getName(node);
}
}
| assignable ablock {if ($<integ>1 != $<integ>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 :