Made the infix ops call the normal functions.
This commit is contained in:
parent
b4cd46a1e7
commit
bdca40bae4
@ -21,23 +21,23 @@ ASTNumData exec_call(AST* ast) {
|
|||||||
log_dbg("Started call execution.");
|
log_dbg("Started call execution.");
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
ASTCallData* calldata = (ASTCallData*)ast->data;
|
ASTCallData* calldata = (ASTCallData*)ast->data;
|
||||||
if (!strcmp(calldata->to, "+") && calldata->argc == 2) {
|
if (!strcmp(calldata->to, "sum") && calldata->argc == 2) {
|
||||||
|
|
||||||
ASTNumData n1 = exec_expr(calldata->argv[0]);
|
ASTNumData n1 = exec_expr(calldata->argv[0]);
|
||||||
ASTNumData n2 = exec_expr(calldata->argv[1]);
|
ASTNumData n2 = exec_expr(calldata->argv[1]);
|
||||||
|
|
||||||
return n1 + n2;
|
return n1 + n2;
|
||||||
} else if (!strcmp(calldata->to, "-") && calldata->argc == 2) {
|
} else if (!strcmp(calldata->to, "sub") && calldata->argc == 2) {
|
||||||
ASTNumData n1 = exec_expr(calldata->argv[0]);
|
ASTNumData n1 = exec_expr(calldata->argv[0]);
|
||||||
ASTNumData n2 = exec_expr(calldata->argv[1]);
|
ASTNumData n2 = exec_expr(calldata->argv[1]);
|
||||||
|
|
||||||
return n1 - n2;
|
return n1 - n2;
|
||||||
} else if (!strcmp(calldata->to, "*") && calldata->argc == 2) {
|
} else if (!strcmp(calldata->to, "mul") && calldata->argc == 2) {
|
||||||
ASTNumData n1 = exec_expr(calldata->argv[0]);
|
ASTNumData n1 = exec_expr(calldata->argv[0]);
|
||||||
ASTNumData n2 = exec_expr(calldata->argv[1]);
|
ASTNumData n2 = exec_expr(calldata->argv[1]);
|
||||||
|
|
||||||
return n1 * n2;
|
return n1 * n2;
|
||||||
} else if (!strcmp(calldata->to, "/") && calldata->argc == 2) {
|
} else if (!strcmp(calldata->to, "div") && calldata->argc == 2) {
|
||||||
ASTNumData n1 = exec_expr(calldata->argv[0]);
|
ASTNumData n1 = exec_expr(calldata->argv[0]);
|
||||||
ASTNumData n2 = exec_expr(calldata->argv[1]);
|
ASTNumData n2 = exec_expr(calldata->argv[1]);
|
||||||
|
|
||||||
|
@ -46,74 +46,74 @@ exp:
|
|||||||
AST** argv = calloc(2, sizeof(AST*));
|
AST** argv = calloc(2, sizeof(AST*));
|
||||||
argv[0] = ast_init(AST_TYPE_NUM, ast_num_data_init($1));
|
argv[0] = ast_init(AST_TYPE_NUM, ast_num_data_init($1));
|
||||||
argv[1] = ast_init(AST_TYPE_NUM, ast_num_data_init($3));
|
argv[1] = ast_init(AST_TYPE_NUM, ast_num_data_init($3));
|
||||||
$$ = ast_init(AST_TYPE_CALL, ast_call_data_init("+", 2, argv));
|
$$ = ast_init(AST_TYPE_CALL, ast_call_data_init("sum", 2, argv));
|
||||||
}
|
}
|
||||||
| NEG NUM PLUS NUM {
|
| NEG NUM PLUS NUM {
|
||||||
AST** argv = calloc(2, sizeof(AST*));
|
AST** argv = calloc(2, sizeof(AST*));
|
||||||
argv[0] = ast_init(AST_TYPE_NUM, ast_num_data_init(-$2));
|
argv[0] = ast_init(AST_TYPE_NUM, ast_num_data_init(-$2));
|
||||||
argv[1] = ast_init(AST_TYPE_NUM, ast_num_data_init($4));
|
argv[1] = ast_init(AST_TYPE_NUM, ast_num_data_init($4));
|
||||||
$$ = ast_init(AST_TYPE_CALL, ast_call_data_init("+", 2, argv));
|
$$ = ast_init(AST_TYPE_CALL, ast_call_data_init("sum", 2, argv));
|
||||||
}
|
}
|
||||||
| NUM NEG NUM {
|
| NUM NEG NUM {
|
||||||
AST** argv = calloc(2, sizeof(AST*));
|
AST** argv = calloc(2, sizeof(AST*));
|
||||||
argv[0] = ast_init(AST_TYPE_NUM, ast_num_data_init($1));
|
argv[0] = ast_init(AST_TYPE_NUM, ast_num_data_init($1));
|
||||||
argv[1] = ast_init(AST_TYPE_NUM, ast_num_data_init($3));
|
argv[1] = ast_init(AST_TYPE_NUM, ast_num_data_init($3));
|
||||||
$$ = ast_init(AST_TYPE_CALL, ast_call_data_init("-", 2, argv));
|
$$ = ast_init(AST_TYPE_CALL, ast_call_data_init("sub", 2, argv));
|
||||||
}
|
}
|
||||||
| NEG NUM NEG NUM {
|
| NEG NUM NEG NUM {
|
||||||
AST** argv = calloc(2, sizeof(AST*));
|
AST** argv = calloc(2, sizeof(AST*));
|
||||||
argv[0] = ast_init(AST_TYPE_NUM, ast_num_data_init(-$2));
|
argv[0] = ast_init(AST_TYPE_NUM, ast_num_data_init(-$2));
|
||||||
argv[1] = ast_init(AST_TYPE_NUM, ast_num_data_init($4));
|
argv[1] = ast_init(AST_TYPE_NUM, ast_num_data_init($4));
|
||||||
$$ = ast_init(AST_TYPE_CALL, ast_call_data_init("-", 2, argv));
|
$$ = ast_init(AST_TYPE_CALL, ast_call_data_init("sub", 2, argv));
|
||||||
}
|
}
|
||||||
|
|
||||||
| NUM MULT NUM {
|
| NUM MULT NUM {
|
||||||
AST** argv = calloc(2, sizeof(AST*));
|
AST** argv = calloc(2, sizeof(AST*));
|
||||||
argv[0] = ast_init(AST_TYPE_NUM, ast_num_data_init($1));
|
argv[0] = ast_init(AST_TYPE_NUM, ast_num_data_init($1));
|
||||||
argv[1] = ast_init(AST_TYPE_NUM, ast_num_data_init($3));
|
argv[1] = ast_init(AST_TYPE_NUM, ast_num_data_init($3));
|
||||||
$$ = ast_init(AST_TYPE_CALL, ast_call_data_init("*", 2, argv));
|
$$ = ast_init(AST_TYPE_CALL, ast_call_data_init("mul", 2, argv));
|
||||||
}
|
}
|
||||||
| NEG NUM MULT NUM {
|
| NEG NUM MULT NUM {
|
||||||
AST** argv = calloc(2, sizeof(AST*));
|
AST** argv = calloc(2, sizeof(AST*));
|
||||||
argv[0] = ast_init(AST_TYPE_NUM, ast_num_data_init(-$2));
|
argv[0] = ast_init(AST_TYPE_NUM, ast_num_data_init(-$2));
|
||||||
argv[1] = ast_init(AST_TYPE_NUM, ast_num_data_init($4));
|
argv[1] = ast_init(AST_TYPE_NUM, ast_num_data_init($4));
|
||||||
$$ = ast_init(AST_TYPE_CALL, ast_call_data_init("*", 2, argv));
|
$$ = ast_init(AST_TYPE_CALL, ast_call_data_init("mul", 2, argv));
|
||||||
}
|
}
|
||||||
| NEG NUM MULT NEG NUM {
|
| NEG NUM MULT NEG NUM {
|
||||||
AST** argv = calloc(2, sizeof(AST*));
|
AST** argv = calloc(2, sizeof(AST*));
|
||||||
argv[0] = ast_init(AST_TYPE_NUM, ast_num_data_init(-$2));
|
argv[0] = ast_init(AST_TYPE_NUM, ast_num_data_init(-$2));
|
||||||
argv[1] = ast_init(AST_TYPE_NUM, ast_num_data_init(-$5));
|
argv[1] = ast_init(AST_TYPE_NUM, ast_num_data_init(-$5));
|
||||||
$$ = ast_init(AST_TYPE_CALL, ast_call_data_init("*", 2, argv));
|
$$ = ast_init(AST_TYPE_CALL, ast_call_data_init("mul", 2, argv));
|
||||||
}
|
}
|
||||||
| NUM MULT NEG NUM {
|
| NUM MULT NEG NUM {
|
||||||
AST** argv = calloc(2, sizeof(AST*));
|
AST** argv = calloc(2, sizeof(AST*));
|
||||||
argv[0] = ast_init(AST_TYPE_NUM, ast_num_data_init($1));
|
argv[0] = ast_init(AST_TYPE_NUM, ast_num_data_init($1));
|
||||||
argv[1] = ast_init(AST_TYPE_NUM, ast_num_data_init(-$4));
|
argv[1] = ast_init(AST_TYPE_NUM, ast_num_data_init(-$4));
|
||||||
$$ = ast_init(AST_TYPE_CALL, ast_call_data_init("*", 2, argv));
|
$$ = ast_init(AST_TYPE_CALL, ast_call_data_init("mul", 2, argv));
|
||||||
}
|
}
|
||||||
|
|
||||||
| NUM DIV NUM {
|
| NUM DIV NUM {
|
||||||
AST** argv = calloc(2, sizeof(AST*));
|
AST** argv = calloc(2, sizeof(AST*));
|
||||||
argv[0] = ast_init(AST_TYPE_NUM, ast_num_data_init($1));
|
argv[0] = ast_init(AST_TYPE_NUM, ast_num_data_init($1));
|
||||||
argv[1] = ast_init(AST_TYPE_NUM, ast_num_data_init($3));
|
argv[1] = ast_init(AST_TYPE_NUM, ast_num_data_init($3));
|
||||||
$$ = ast_init(AST_TYPE_CALL, ast_call_data_init("/", 2, argv));
|
$$ = ast_init(AST_TYPE_CALL, ast_call_data_init("div", 2, argv));
|
||||||
}
|
}
|
||||||
| NEG NUM DIV NUM {
|
| NEG NUM DIV NUM {
|
||||||
AST** argv = calloc(2, sizeof(AST*));
|
AST** argv = calloc(2, sizeof(AST*));
|
||||||
argv[0] = ast_init(AST_TYPE_NUM, ast_num_data_init(-$2));
|
argv[0] = ast_init(AST_TYPE_NUM, ast_num_data_init(-$2));
|
||||||
argv[1] = ast_init(AST_TYPE_NUM, ast_num_data_init($4));
|
argv[1] = ast_init(AST_TYPE_NUM, ast_num_data_init($4));
|
||||||
$$ = ast_init(AST_TYPE_CALL, ast_call_data_init("/", 2, argv));
|
$$ = ast_init(AST_TYPE_CALL, ast_call_data_init("div", 2, argv));
|
||||||
}
|
}
|
||||||
| NEG NUM DIV NEG NUM {
|
| NEG NUM DIV NEG NUM {
|
||||||
AST** argv = calloc(2, sizeof(AST*));
|
AST** argv = calloc(2, sizeof(AST*));
|
||||||
argv[0] = ast_init(AST_TYPE_NUM, ast_num_data_init(-$2));
|
argv[0] = ast_init(AST_TYPE_NUM, ast_num_data_init(-$2));
|
||||||
argv[1] = ast_init(AST_TYPE_NUM, ast_num_data_init(-$5));
|
argv[1] = ast_init(AST_TYPE_NUM, ast_num_data_init(-$5));
|
||||||
$$ = ast_init(AST_TYPE_CALL, ast_call_data_init("/", 2, argv));
|
$$ = ast_init(AST_TYPE_CALL, ast_call_data_init("div", 2, argv));
|
||||||
}
|
}
|
||||||
| NUM DIV NEG NUM {
|
| NUM DIV NEG NUM {
|
||||||
AST** argv = calloc(2, sizeof(AST*));
|
AST** argv = calloc(2, sizeof(AST*));
|
||||||
argv[0] = ast_init(AST_TYPE_NUM, ast_num_data_init($1));
|
argv[0] = ast_init(AST_TYPE_NUM, ast_num_data_init($1));
|
||||||
argv[1] = ast_init(AST_TYPE_NUM, ast_num_data_init(-$4));
|
argv[1] = ast_init(AST_TYPE_NUM, ast_num_data_init(-$4));
|
||||||
$$ = ast_init(AST_TYPE_CALL, ast_call_data_init("/", 2, argv));
|
$$ = ast_init(AST_TYPE_CALL, ast_call_data_init("div", 2, argv));
|
||||||
}
|
}
|
||||||
%%
|
%%
|
||||||
|
Loading…
x
Reference in New Issue
Block a user