diff --git a/src/exec.c b/src/exec.c index bb62d6f..ae2b956 100644 --- a/src/exec.c +++ b/src/exec.c @@ -21,23 +21,23 @@ ASTNumData exec_call(AST* ast) { log_dbg("Started call execution."); fflush(stdout); 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 n2 = exec_expr(calldata->argv[1]); 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 n2 = exec_expr(calldata->argv[1]); 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 n2 = exec_expr(calldata->argv[1]); 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 n2 = exec_expr(calldata->argv[1]); diff --git a/src/grammar.y b/src/grammar.y index 870af2f..a6d7d32 100644 --- a/src/grammar.y +++ b/src/grammar.y @@ -46,74 +46,74 @@ exp: AST** argv = calloc(2, sizeof(AST*)); argv[0] = ast_init(AST_TYPE_NUM, ast_num_data_init($1)); 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 { AST** argv = calloc(2, sizeof(AST*)); argv[0] = ast_init(AST_TYPE_NUM, ast_num_data_init(-$2)); 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 { AST** argv = calloc(2, sizeof(AST*)); argv[0] = ast_init(AST_TYPE_NUM, ast_num_data_init($1)); 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 { AST** argv = calloc(2, sizeof(AST*)); argv[0] = ast_init(AST_TYPE_NUM, ast_num_data_init(-$2)); 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 { AST** argv = calloc(2, sizeof(AST*)); argv[0] = ast_init(AST_TYPE_NUM, ast_num_data_init($1)); 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 { AST** argv = calloc(2, sizeof(AST*)); argv[0] = ast_init(AST_TYPE_NUM, ast_num_data_init(-$2)); 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 { AST** argv = calloc(2, sizeof(AST*)); argv[0] = ast_init(AST_TYPE_NUM, ast_num_data_init(-$2)); 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 { AST** argv = calloc(2, sizeof(AST*)); argv[0] = ast_init(AST_TYPE_NUM, ast_num_data_init($1)); 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 { AST** argv = calloc(2, sizeof(AST*)); argv[0] = ast_init(AST_TYPE_NUM, ast_num_data_init($1)); 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 { AST** argv = calloc(2, sizeof(AST*)); argv[0] = ast_init(AST_TYPE_NUM, ast_num_data_init(-$2)); 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 { AST** argv = calloc(2, sizeof(AST*)); argv[0] = ast_init(AST_TYPE_NUM, ast_num_data_init(-$2)); 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 { AST** argv = calloc(2, sizeof(AST*)); argv[0] = ast_init(AST_TYPE_NUM, ast_num_data_init($1)); 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)); } %%