diff --git a/src/grammar.y b/src/grammar.y index 4b36a61..8eff344 100644 --- a/src/grammar.y +++ b/src/grammar.y @@ -282,7 +282,7 @@ rec_op : ablock: - L_PAREN argument_list {$$ = $2;} R_PAREN +L_PAREN argument_list R_PAREN {$$ = $2; printdebug("ablock is %d", $$);} ; argument_list: @@ -372,7 +372,19 @@ expression: // 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 ablock {$$ = getName(getReturn(table_lookup(getAncestor(cur), $1))); printdebug("[ASSIGNABLE - RULE 2] assignable = type: %s | name_func = %s", $$, $1);} // add array case + | assignable ablock { + int type = getAdInfoType(look_up(cur, $1)); + if (type == TYPE_FUNCTION_TYPE) { + $$ = 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(cur, $1)) != $2) { + printdebug("expected %d arguments but had %d at line %d and column %d\n", getNumArrDim(look_up(cur, $1)), $2, @2.first_line, @2.first_column); + } + $$ = $1; + printdebug("[ASSIGNABLE - RULE 2] assignable = type: %s | name_func = %s", $$, $1); + } + } | 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);} ;