diff options
-rw-r--r-- | miscutils/bc.c | 24 |
1 files changed, 8 insertions, 16 deletions
diff --git a/miscutils/bc.c b/miscutils/bc.c index b3ffe7bfd..e1a4b8f52 100644 --- a/miscutils/bc.c +++ b/miscutils/bc.c | |||
@@ -3611,7 +3611,7 @@ static void bc_parse_create(BcParse *p, size_t func) | |||
3611 | // We can calculate the conversion between tokens and exprs by subtracting the | 3611 | // We can calculate the conversion between tokens and exprs by subtracting the |
3612 | // position of the first operator in the lex enum and adding the position of the | 3612 | // position of the first operator in the lex enum and adding the position of the |
3613 | // first in the expr enum. Note: This only works for binary operators. | 3613 | // first in the expr enum. Note: This only works for binary operators. |
3614 | #define BC_PARSE_TOKEN_INST(t) ((char) ((t) -BC_LEX_NEG + BC_INST_NEG)) | 3614 | #define BC_PARSE_TOKEN_INST(t) ((char) ((t) - BC_LEX_NEG + BC_INST_NEG)) |
3615 | 3615 | ||
3616 | static BC_STATUS zbc_parse_else(BcParse *p); | 3616 | static BC_STATUS zbc_parse_else(BcParse *p); |
3617 | static BC_STATUS zbc_parse_stmt(BcParse *p); | 3617 | static BC_STATUS zbc_parse_stmt(BcParse *p); |
@@ -3623,17 +3623,14 @@ static BcStatus bc_parse_expr_empty_ok(BcParse *p, uint8_t flags, BcParseNext ne | |||
3623 | # define zbc_parse_expr(...) (zbc_parse_expr(__VA_ARGS__), BC_STATUS_SUCCESS) | 3623 | # define zbc_parse_expr(...) (zbc_parse_expr(__VA_ARGS__), BC_STATUS_SUCCESS) |
3624 | #endif | 3624 | #endif |
3625 | 3625 | ||
3626 | static BC_STATUS zbc_parse_operator(BcParse *p, BcLexType type, size_t start, | 3626 | static void bc_parse_operator(BcParse *p, BcLexType type, size_t start, |
3627 | size_t *nexprs, bool next) | 3627 | size_t *nexprs) |
3628 | { | 3628 | { |
3629 | BcStatus s = BC_STATUS_SUCCESS; | ||
3630 | BcLexType t; | ||
3631 | char l, r = bc_parse_op_PREC(type - BC_LEX_OP_INC); | 3629 | char l, r = bc_parse_op_PREC(type - BC_LEX_OP_INC); |
3632 | bool left = bc_parse_op_LEFT(type - BC_LEX_OP_INC); | 3630 | bool left = bc_parse_op_LEFT(type - BC_LEX_OP_INC); |
3633 | 3631 | ||
3634 | while (p->ops.len > start) { | 3632 | while (p->ops.len > start) { |
3635 | 3633 | BcLexType t = BC_PARSE_TOP_OP(p); | |
3636 | t = BC_PARSE_TOP_OP(p); | ||
3637 | if (t == BC_LEX_LPAREN) break; | 3634 | if (t == BC_LEX_LPAREN) break; |
3638 | 3635 | ||
3639 | l = bc_parse_op_PREC(t - BC_LEX_OP_INC); | 3636 | l = bc_parse_op_PREC(t - BC_LEX_OP_INC); |
@@ -3641,17 +3638,11 @@ static BC_STATUS zbc_parse_operator(BcParse *p, BcLexType type, size_t start, | |||
3641 | 3638 | ||
3642 | bc_parse_push(p, BC_PARSE_TOKEN_INST(t)); | 3639 | bc_parse_push(p, BC_PARSE_TOKEN_INST(t)); |
3643 | bc_vec_pop(&p->ops); | 3640 | bc_vec_pop(&p->ops); |
3644 | *nexprs -= t != BC_LEX_OP_BOOL_NOT && t != BC_LEX_NEG; | 3641 | *nexprs -= (t != BC_LEX_OP_BOOL_NOT && t != BC_LEX_NEG); |
3645 | } | 3642 | } |
3646 | 3643 | ||
3647 | bc_vec_push(&p->ops, &type); | 3644 | bc_vec_push(&p->ops, &type); |
3648 | if (next) s = zbc_lex_next(&p->l); | ||
3649 | |||
3650 | RETURN_STATUS(s); | ||
3651 | } | 3645 | } |
3652 | #if ERRORS_ARE_FATAL | ||
3653 | # define zbc_parse_operator(...) (zbc_parse_operator(__VA_ARGS__), BC_STATUS_SUCCESS) | ||
3654 | #endif | ||
3655 | 3646 | ||
3656 | static BC_STATUS zbc_parse_rightParen(BcParse *p, size_t ops_bgn, size_t *nexs) | 3647 | static BC_STATUS zbc_parse_rightParen(BcParse *p, size_t ops_bgn, size_t *nexs) |
3657 | { | 3648 | { |
@@ -3964,7 +3955,7 @@ static BC_STATUS zbc_parse_minus(BcParse *p, BcInst *prev, size_t ops_bgn, | |||
3964 | if (type != BC_LEX_OP_MINUS) | 3955 | if (type != BC_LEX_OP_MINUS) |
3965 | bc_vec_push(&p->ops, &type); | 3956 | bc_vec_push(&p->ops, &type); |
3966 | else | 3957 | else |
3967 | s = zbc_parse_operator(p, type, ops_bgn, nexprs, false); | 3958 | bc_parse_operator(p, type, ops_bgn, nexprs); |
3968 | 3959 | ||
3969 | RETURN_STATUS(s); | 3960 | RETURN_STATUS(s); |
3970 | } | 3961 | } |
@@ -4787,7 +4778,8 @@ static BcStatus bc_parse_expr_empty_ok(BcParse *p, uint8_t flags, BcParseNext ne | |||
4787 | 4778 | ||
4788 | nrelops += t >= BC_LEX_OP_REL_EQ && t <= BC_LEX_OP_REL_GT; | 4779 | nrelops += t >= BC_LEX_OP_REL_EQ && t <= BC_LEX_OP_REL_GT; |
4789 | prev = BC_PARSE_TOKEN_INST(t); | 4780 | prev = BC_PARSE_TOKEN_INST(t); |
4790 | s = zbc_parse_operator(p, t, ops_bgn, &nexprs, true); | 4781 | bc_parse_operator(p, t, ops_bgn, &nexprs); |
4782 | s = zbc_lex_next(&p->l); | ||
4791 | rprn = get_token = false; | 4783 | rprn = get_token = false; |
4792 | bin_last = t != BC_LEX_OP_BOOL_NOT; | 4784 | bin_last = t != BC_LEX_OP_BOOL_NOT; |
4793 | 4785 | ||