diff --git a/parser/expr/expr.c b/parser/expr/expr.c index ae9dc40..ec0bdf2 100644 --- a/parser/expr/expr.c +++ b/parser/expr/expr.c @@ -320,7 +320,7 @@ parser_node *parse_expr_prec(typed_token **tkns_ptr, parser_node *lhs, int min_p while (1) { int look_prec = op_prec(tkn->type_id); - if (look_prec < prec) + if (look_prec <= prec) // <= for left assoc and < for right assoc { break; } diff --git a/tests/output/inp2.c_asm_output.txt b/tests/output/inp2.c_asm_output.txt index bd44c56..2fb11ac 100644 --- a/tests/output/inp2.c_asm_output.txt +++ b/tests/output/inp2.c_asm_output.txt @@ -53,51 +53,51 @@ mov rbp, rsp sub rsp, __main_size mov [rsp+0], rdi mov [rsp+8], rsi +mov rax, __temp_str_3 +mov rbx, __temp_str_4 +add rax, rbx +mov [rsp + 24], rax mov rax, __temp_str_5 mov rbx, __temp_str_6 mul rbx -mov [rsp + 24], rax -mov rax, __temp_str_7 -mov rbx, __temp_str_8 -add rax, rbx mov [rsp + 32], rax mov rax, [rsp + 24] mov rbx, [rsp + 32] add rax, rbx mov [rsp + 40], rax -mov rax, __temp_str_4 -mov rbx, [rsp + 40] +mov rax, [rsp + 40] +mov rbx, __temp_str_7 add rax, rbx mov [rsp + 48], rax -mov rax, __temp_str_3 -mov rbx, [rsp + 48] +mov rax, [rsp + 48] +mov rbx, __temp_str_8 add rax, rbx mov [rsp + 56], rax mov rax, [rsp + 56] mov [rsp+16], rax -mov rax, __temp_str_11 -mov rbx, __temp_str_12 +mov rax, __temp_str_9 +mov rbx, __temp_str_10 add rax, rbx mov [rsp + 72], rax -mov rax, __temp_str_10 -mov rbx, [rsp + 72] +mov rax, __temp_str_11 +mov rbx, __temp_str_12 add rax, rbx mov [rsp + 80], rax -mov rax, __temp_str_9 +mov rax, [rsp + 72] mov rbx, [rsp + 80] add rax, rbx mov [rsp + 88], rax mov rax, [rsp + 88] mov [rsp+64], rax -mov rax, __temp_str_15 -mov rbx, __temp_str_16 +mov rax, __temp_str_13 +mov rbx, __temp_str_14 add rax, rbx mov [rsp + 96], rax -mov rax, __temp_str_14 -mov rbx, [rsp + 96] +mov rax, __temp_str_15 +mov rbx, __temp_str_16 add rax, rbx mov [rsp + 104], rax -mov rax, __temp_str_13 +mov rax, [rsp + 96] mov rbx, [rsp + 104] add rax, rbx mov [rsp + 112], rax @@ -105,17 +105,17 @@ mov rax, [rsp + 112] mov [rsp+64], rax call hey mov [rsp + 120], rax -call func -mov [rsp + 128], rax -mov rax, __temp_str_18 -mov rbx, [rsp + 128] +mov rax, [rsp + 120] +mov rbx, __temp_str_17 add rax, rbx +mov [rsp + 128], rax +call func mov [rsp + 136], rax -mov rax, __temp_str_17 +mov rax, __temp_str_18 mov rbx, [rsp + 136] add rax, rbx mov [rsp + 144], rax -mov rax, [rsp + 120] +mov rax, [rsp + 128] mov rbx, [rsp + 144] add rax, rbx mov [rsp + 152], rax diff --git a/tests/output/inp2.c_tree_output.txt b/tests/output/inp2.c_tree_output.txt index e1bcdfd..3ed21e1 100644 --- a/tests/output/inp2.c_tree_output.txt +++ b/tests/output/inp2.c_tree_output.txt @@ -52,73 +52,73 @@ Program( Value: BinaryOp(Op: 72) Left: - Literal(Type: 33, Value: 1) - Right: BinaryOp(Op: 72) Left: - Literal(Type: 33, Value: 2) - Right: BinaryOp(Op: 72) Left: - BinaryOp(Op: 78) + BinaryOp(Op: 72) Left: - Literal(Type: 33, Value: 3) + Literal(Type: 33, Value: 1) Right: - Literal(Type: 33, Value: 4) + Literal(Type: 33, Value: 2) Right: - BinaryOp(Op: 72) + BinaryOp(Op: 78) Left: - Literal(Type: 33, Value: 5) + Literal(Type: 33, Value: 3) Right: - Literal(Type: 33, Value: 6) + Literal(Type: 33, Value: 4) + Right: + Literal(Type: 33, Value: 5) + Right: + Literal(Type: 33, Value: 6) VarDecl(b): Type(TKN_INT) Value: BinaryOp(Op: 72) Left: - Literal(Type: 33, Value: 234) - Right: BinaryOp(Op: 72) Left: + Literal(Type: 33, Value: 234) + Right: Literal(Type: 33, Value: 2) + Right: + BinaryOp(Op: 72) + Left: + Literal(Type: 33, Value: 23) Right: - BinaryOp(Op: 72) - Left: - Literal(Type: 33, Value: 23) - Right: - Literal(Type: 33, Value: 1) + Literal(Type: 33, Value: 1) Assign(b): Value: BinaryOp(Op: 72) Left: - Literal(Type: 33, Value: 2) - Right: BinaryOp(Op: 72) Left: + Literal(Type: 33, Value: 2) + Right: Literal(Type: 33, Value: 3) + Right: + BinaryOp(Op: 72) + Left: + Literal(Type: 33, Value: 4) Right: - BinaryOp(Op: 72) - Left: - Literal(Type: 33, Value: 4) - Right: - Literal(Type: 33, Value: 5) + Literal(Type: 33, Value: 5) Assign(a): Value: BinaryOp(Op: 72) Left: - FunctionCall(Name: hey) - Args: - Right: BinaryOp(Op: 72) Left: + FunctionCall(Name: hey) + Args: + Right: Literal(Type: 33, Value: ab) + Right: + BinaryOp(Op: 72) + Left: + Literal(Type: 33, Value: cd) Right: - BinaryOp(Op: 72) - Left: - Literal(Type: 33, Value: cd) - Right: - FunctionCall(Name: func) - Args: + FunctionCall(Name: func) + Args: FunctionCall(Name: salam) Args: CompoundStatement diff --git a/tests/output/inp3.c_asm_output.txt b/tests/output/inp3.c_asm_output.txt index 4987944..05a2db1 100644 --- a/tests/output/inp3.c_asm_output.txt +++ b/tests/output/inp3.c_asm_output.txt @@ -247,23 +247,23 @@ mov rax, [rsp + 120] mov [rsp+104], rax mov rax, __temp_str_8 mov [rsp + 128], rax -mov rax, [rsp + 80] -mov rbx, [rsp + 72] +mov rax, [rsp + 88] +mov rbx, [rsp + 88] add rax, rbx mov [rsp + 136], rax mov rax, [rsp + 136] -mov rbx, [rsp + 72] -mul rbx +mov rbx, [rsp + 104] +add rax, rbx mov [rsp + 144], rax -mov rax, [rsp + 104] -mov rbx, [rsp + 144] +mov rax, [rsp + 80] +mov rbx, [rsp + 72] add rax, rbx mov [rsp + 152], rax -mov rax, [rsp + 88] -mov rbx, [rsp + 152] -add rax, rbx +mov rax, [rsp + 152] +mov rbx, [rsp + 72] +mul rbx mov [rsp + 160], rax -mov rax, [rsp + 88] +mov rax, [rsp + 144] mov rbx, [rsp + 160] add rax, rbx mov [rsp + 168], rax diff --git a/tests/output/inp3.c_tree_output.txt b/tests/output/inp3.c_tree_output.txt index b73ab03..0ce310d 100644 --- a/tests/output/inp3.c_tree_output.txt +++ b/tests/output/inp3.c_tree_output.txt @@ -152,25 +152,25 @@ Program( ) BinaryOp(Op: 72) Left: - Variable(c) - Right: BinaryOp(Op: 72) Left: - Variable(c) + BinaryOp(Op: 72) + Left: + Variable(c) + Right: + Variable(c) Right: + Variable(d) + Right: + BinaryOp(Op: 78) + Left: BinaryOp(Op: 72) Left: - Variable(d) + Variable(b) Right: - BinaryOp(Op: 78) - Left: - BinaryOp(Op: 72) - Left: - Variable(b) - Right: - Variable(a) - Right: - Variable(a) + Variable(a) + Right: + Variable(a) VarDecl(cc): Type(TKN_INT*) Value: