|
|
|
@ -28,7 +28,7 @@
|
|
|
|
|
|
|
|
|
|
%locations
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
%token <integ> ACCESS 801
|
|
|
|
|
%type <integ> idlist
|
|
|
|
|
%type <tn> assignable
|
|
|
|
|
%type <tn> expression
|
|
|
|
@ -166,6 +166,8 @@ definition:
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
| ID {
|
|
|
|
|
//printf("ID: %s\n", $1);
|
|
|
|
|
//printf("Type: %s\n", getType(table_lookup(getAncestor(cur), $1)));
|
|
|
|
|
printdebug("see function def rule 1\n");
|
|
|
|
|
TableNode *node = table_lookup(getAncestor(cur), $1);
|
|
|
|
|
if (node == undefined) {
|
|
|
|
@ -251,6 +253,7 @@ definition:
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//counter = 0;
|
|
|
|
|
|
|
|
|
|
printdebug("Created a new scope after seeing a function definition");
|
|
|
|
|
} idlist R_PAREN ASSIGN sblock {
|
|
|
|
|
TableNode *expected = getReturn(getTypeEntry(look_up(cur, $1)));
|
|
|
|
@ -265,6 +268,8 @@ definition:
|
|
|
|
|
} else {
|
|
|
|
|
printdebug("CORRECT RETURN TYPE!!!");
|
|
|
|
|
}
|
|
|
|
|
//printf("Ending ID: %s\n", $1);
|
|
|
|
|
//printf("Ending Type: %s\n", getType(table_lookup(getAncestor(cur), $1)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
;
|
|
|
|
@ -272,8 +277,10 @@ definition:
|
|
|
|
|
function_declaration:
|
|
|
|
|
FUNCTION ID COLON ID
|
|
|
|
|
{
|
|
|
|
|
if(getAdInfoType(look_up(cur, $4))==TYPE_FUNCTION_TYPE){
|
|
|
|
|
CreateEntry(cur,TYPE_FUNCTION_DECLARATION, look_up(cur, $4), $2, CreateFunctionDeclarationInfo(-1, false));
|
|
|
|
|
if(getAdInfoType(table_lookup(cur, $4))==TYPE_FUNCTION_TYPE){
|
|
|
|
|
//printf("%s\n",$2);
|
|
|
|
|
//printf("%s\n",getName(table_lookup(cur, $4)));
|
|
|
|
|
CreateEntry(cur,TYPE_FUNCTION_DECLARATION, table_lookup(cur, $4), $2, CreateFunctionDeclarationInfo(-1, false));
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
throw_error(ERROR_TYPE, "Function declatation (%s) is not a valid function type", $2);
|
|
|
|
@ -565,8 +572,8 @@ WHILE L_PAREN expression R_PAREN sblock {
|
|
|
|
|
$$ = $8;
|
|
|
|
|
} else {
|
|
|
|
|
printdebug("3 differing return types within same function at line %d, column %d", @1.first_line, @1.first_column);
|
|
|
|
|
printf("%s\n", getName((TableNode*)$6));
|
|
|
|
|
printf("%s\n", getName((TableNode*)$8));
|
|
|
|
|
//printf("%s\n", getName((TableNode*)$6));
|
|
|
|
|
//printf("%s\n", getName((TableNode*)$8));
|
|
|
|
|
$$ = undefined;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -590,11 +597,11 @@ simple_statement:
|
|
|
|
|
|
|
|
|
|
node = ((TableNode*)$1);
|
|
|
|
|
} else {
|
|
|
|
|
printf("%d\n",getAdInfoType((getTypeEntry((TableNode*)$1))));
|
|
|
|
|
//printf("%d\n",getAdInfoType((getTypeEntry((TableNode*)$1))));
|
|
|
|
|
throw_error(ERROR_TYPE, "Invalid type passed to assignable.");
|
|
|
|
|
printf("%d, %d\n", @1.first_line, @1.first_column);
|
|
|
|
|
printf("%s\n", getType(getTypeEntry((TableNode*)$1)));
|
|
|
|
|
printf("%s\n\n", getType(getTypeEntry((TableNode*)$3)));
|
|
|
|
|
//printf("%d, %d\n", @1.first_line, @1.first_column);
|
|
|
|
|
//printf("%s\n", getType(getTypeEntry((TableNode*)$1)));
|
|
|
|
|
//printf("%s\n\n", getType(getTypeEntry((TableNode*)$3)));
|
|
|
|
|
node = undefined;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -910,8 +917,8 @@ assignable:
|
|
|
|
|
while(arg_given != NULL && getName(arg_given)[0]!='&'){
|
|
|
|
|
arg_given = getNextEntry(arg_given);
|
|
|
|
|
}
|
|
|
|
|
if(getTypeEntry(arg_given) != param_arg_type){
|
|
|
|
|
throw_error(ERROR_TYPE, "expected %s expression as first argument in function call but got %s", getName(param_arg_type), getType(arg_given));
|
|
|
|
|
if(getTypeEntry(arg_given) != getTypeEntry(param_arg_type)){
|
|
|
|
|
throw_error(ERROR_TYPE, "expected %s expression as first argument in function call but got %s", getType(param_arg_type), getType(arg_given));
|
|
|
|
|
}
|
|
|
|
|
param_arg_type = getNextEntry(param_arg_type);
|
|
|
|
|
arg_given = getNextEntry(arg_given);
|
|
|
|
@ -919,8 +926,8 @@ assignable:
|
|
|
|
|
while(arg_given != NULL && getName(arg_given)[0]=='&'){
|
|
|
|
|
arg_given = getNextEntry(arg_given);
|
|
|
|
|
}
|
|
|
|
|
if(getTypeEntry(arg_given) != param_arg_type){
|
|
|
|
|
throw_error(ERROR_TYPE, "expected %s expression as argument in function call but got %s", getName(param_arg_type), getType(arg_given));
|
|
|
|
|
if(getTypeEntry(arg_given) != getTypeEntry(param_arg_type)){
|
|
|
|
|
throw_error(ERROR_TYPE, "expected %s expression as argument in function call but got %s", getType(param_arg_type), getType(arg_given));
|
|
|
|
|
}
|
|
|
|
|
arg_given = getNextEntry(arg_given);
|
|
|
|
|
param_arg_type = getNextEntry(param_arg_type);
|
|
|
|
@ -937,7 +944,7 @@ assignable:
|
|
|
|
|
}
|
|
|
|
|
TableNode *actual = getTypeEntry(actual_instance);
|
|
|
|
|
if (expected != actual) {
|
|
|
|
|
throw_error(ERROR_TYPE, "expected %s expression in function call but got %s", getName(expected), getName(actual));
|
|
|
|
|
throw_error(ERROR_TYPE, "expected %s expression in function call but got %s", getType(expected), getName(actual));
|
|
|
|
|
}
|
|
|
|
|
if ($3 != 1) {
|
|
|
|
|
throw_error(ERROR_SYNTAX, "expected 1 argument but got %d", $3); }
|
|
|
|
@ -968,8 +975,8 @@ assignable:
|
|
|
|
|
printdebug("[ASSIGNABLE - RULE 2] assignable = type: %s | name_func = %s", getName(typeNode2), getName((TableNode*)$1));
|
|
|
|
|
} else if (type == TYPE_ARRAY_TYPE) {
|
|
|
|
|
printdebug("%sEntering array call", COLOR_LIGHTGREEN);
|
|
|
|
|
if (getNumArrDim(look_up(getParent(cur), getType((TableNode*)$1))) != $<integ>2) {
|
|
|
|
|
throw_error(ERROR_SYNTAX, "expected %d arguments for this array but got %d", getNumArrDim(look_up(cur, getName((TableNode*)$1))), $<integ>2);
|
|
|
|
|
if (getNumArrDim(getTypeEntry((TableNode*)$1)) != $3) {
|
|
|
|
|
throw_error(ERROR_SYNTAX, "expected %d arguments for this array but got %d", getNumArrDim(getTypeEntry((TableNode*)$1)), $3);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
char* temp = temp_var_gen();
|
|
|
|
@ -998,15 +1005,32 @@ assignable:
|
|
|
|
|
}
|
|
|
|
|
cur = getParent(cur);
|
|
|
|
|
}
|
|
|
|
|
| assignable rec_op ACCESS
|
|
|
|
|
{
|
|
|
|
|
if(getAdInfoType((TableNode*)$1) != TYPE_ARRAY){
|
|
|
|
|
throw_error(ERROR_TYPE, "Invalid type passed to array access");
|
|
|
|
|
$$ = undefined;
|
|
|
|
|
}else if($3>getNumArrDim(getTypeEntry((TableNode*)$1))){
|
|
|
|
|
throw_error(ERROR_TYPE, "Invalid trying to access the size of dimension %d but this array only has %d dimensions", $3, getNumArrDim(getTypeEntry((TableNode*)$1)));
|
|
|
|
|
$$ = undefined;
|
|
|
|
|
} else{
|
|
|
|
|
char* temp = temp_var_gen();
|
|
|
|
|
int t = 6;
|
|
|
|
|
//emission
|
|
|
|
|
$$ = CreateEntry(cur,t, integ, temp, NULL);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
| assignable rec_op ID
|
|
|
|
|
| assignable rec_op ID
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
if(getAdInfoType((TableNode*)$1) != TYPE_RECORD){
|
|
|
|
|
throw_error(ERROR_TYPE, "Invalid type passed to record access");
|
|
|
|
|
$$ = undefined;
|
|
|
|
|
}
|
|
|
|
|
else if(undefined != table_lookup(getRecList(table_lookup(getAncestor(cur), getName(getTypeEntry((TableNode*)$1)))), $3)) {
|
|
|
|
|
else if(undefined != table_lookup(getRecList(getTypeEntry((TableNode*)$1)), $3)) {
|
|
|
|
|
|
|
|
|
|
TableNode* type = getTypeEntry(table_lookup(getRecList(table_lookup(getAncestor(cur), getName(getTypeEntry((TableNode*)$1)))), $3));
|
|
|
|
|
TableNode* type = getTypeEntry(table_lookup(getRecList(getTypeEntry((TableNode*)$1)), $3));
|
|
|
|
|
char* temp = temp_var_gen();
|
|
|
|
|
int t = -1;
|
|
|
|
|
if(getAdInfoType(type) == TYPE_PRIMITIVE_TYPE){
|
|
|
|
|