diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2018-12-25 01:43:52 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2018-12-25 01:43:52 +0100 |
commit | 73b3ebc0e18f95d9eda7e33dfc878f9792d1b1e1 (patch) | |
tree | 7f656aea1d48558b4928dabdaf10907b51408491 | |
parent | d0238d83f0311cfab52897acc739148879598621 (diff) | |
download | busybox-w32-73b3ebc0e18f95d9eda7e33dfc878f9792d1b1e1.tar.gz busybox-w32-73b3ebc0e18f95d9eda7e33dfc878f9792d1b1e1.tar.bz2 busybox-w32-73b3ebc0e18f95d9eda7e33dfc878f9792d1b1e1.zip |
bc: simplify bc_parse_expr_empty_ok()
function old new delta
bc_parse_expr_empty_ok 1810 1791 -19
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | miscutils/bc.c | 52 |
1 files changed, 32 insertions, 20 deletions
diff --git a/miscutils/bc.c b/miscutils/bc.c index a57de97a5..2b370888c 100644 --- a/miscutils/bc.c +++ b/miscutils/bc.c | |||
@@ -4664,15 +4664,16 @@ static BcStatus bc_parse_expr_empty_ok(BcParse *p, uint8_t flags) | |||
4664 | BcInst prev = XC_INST_PRINT; | 4664 | BcInst prev = XC_INST_PRINT; |
4665 | size_t nexprs = 0, ops_bgn = p->ops.len; | 4665 | size_t nexprs = 0, ops_bgn = p->ops.len; |
4666 | unsigned nparens, nrelops; | 4666 | unsigned nparens, nrelops; |
4667 | bool paren_first, paren_expr, rprn, get_token, assign, bin_last; | 4667 | bool paren_first, paren_expr, rprn, assign, bin_last; |
4668 | 4668 | ||
4669 | dbg_lex_enter("%s:%d entered", __func__, __LINE__); | 4669 | dbg_lex_enter("%s:%d entered", __func__, __LINE__); |
4670 | paren_first = (p->l.lex == BC_LEX_LPAREN); | 4670 | paren_first = (p->l.lex == BC_LEX_LPAREN); |
4671 | nparens = nrelops = 0; | 4671 | nparens = nrelops = 0; |
4672 | paren_expr = rprn = get_token = assign = false; | 4672 | paren_expr = rprn = assign = false; |
4673 | bin_last = true; | 4673 | bin_last = true; |
4674 | 4674 | ||
4675 | for (;;) { | 4675 | for (;;) { |
4676 | bool get_token; | ||
4676 | BcStatus s; | 4677 | BcStatus s; |
4677 | BcLexType t = p->l.lex; | 4678 | BcLexType t = p->l.lex; |
4678 | 4679 | ||
@@ -4680,16 +4681,19 @@ static BcStatus bc_parse_expr_empty_ok(BcParse *p, uint8_t flags) | |||
4680 | break; | 4681 | break; |
4681 | 4682 | ||
4682 | dbg_lex("%s:%d t:%d", __func__, __LINE__, t); | 4683 | dbg_lex("%s:%d t:%d", __func__, __LINE__, t); |
4684 | get_token = false; | ||
4683 | s = BC_STATUS_SUCCESS; | 4685 | s = BC_STATUS_SUCCESS; |
4684 | switch (t) { | 4686 | switch (t) { |
4685 | case BC_LEX_OP_INC: | 4687 | case BC_LEX_OP_INC: |
4686 | case BC_LEX_OP_DEC: | 4688 | case BC_LEX_OP_DEC: |
4687 | s = zbc_parse_incdec(p, &prev, &paren_expr, &nexprs, flags); | 4689 | s = zbc_parse_incdec(p, &prev, &paren_expr, &nexprs, flags); |
4688 | rprn = get_token = bin_last = false; | 4690 | rprn = bin_last = false; |
4691 | //get_token = false; - already is | ||
4689 | break; | 4692 | break; |
4690 | case XC_LEX_OP_MINUS: | 4693 | case XC_LEX_OP_MINUS: |
4691 | s = zbc_parse_minus(p, &prev, ops_bgn, rprn, &nexprs); | 4694 | s = zbc_parse_minus(p, &prev, ops_bgn, rprn, &nexprs); |
4692 | rprn = get_token = false; | 4695 | rprn = false; |
4696 | //get_token = false; - already is | ||
4693 | bin_last = (prev == XC_INST_MINUS); | 4697 | bin_last = (prev == XC_INST_MINUS); |
4694 | break; | 4698 | break; |
4695 | case BC_LEX_OP_ASSIGN_POWER: | 4699 | case BC_LEX_OP_ASSIGN_POWER: |
@@ -4733,16 +4737,18 @@ static BcStatus bc_parse_expr_empty_ok(BcParse *p, uint8_t flags) | |||
4733 | prev = BC_TOKEN_2_INST(t); | 4737 | prev = BC_TOKEN_2_INST(t); |
4734 | bc_parse_operator(p, t, ops_bgn, &nexprs); | 4738 | bc_parse_operator(p, t, ops_bgn, &nexprs); |
4735 | s = zbc_lex_next(&p->l); | 4739 | s = zbc_lex_next(&p->l); |
4736 | rprn = get_token = false; | 4740 | rprn = false; |
4741 | //get_token = false; - already is | ||
4737 | bin_last = (t != BC_LEX_OP_BOOL_NOT); | 4742 | bin_last = (t != BC_LEX_OP_BOOL_NOT); |
4738 | break; | 4743 | break; |
4739 | case BC_LEX_LPAREN: | 4744 | case BC_LEX_LPAREN: |
4740 | if (BC_PARSE_LEAF(prev, rprn)) | 4745 | if (BC_PARSE_LEAF(prev, rprn)) |
4741 | return bc_error_bad_expression(); | 4746 | return bc_error_bad_expression(); |
4747 | bc_vec_push(&p->ops, &t); | ||
4742 | nparens++; | 4748 | nparens++; |
4743 | paren_expr = rprn = bin_last = false; | ||
4744 | get_token = true; | 4749 | get_token = true; |
4745 | bc_vec_push(&p->ops, &t); | 4750 | paren_expr = false; |
4751 | rprn = bin_last = false; | ||
4746 | break; | 4752 | break; |
4747 | case BC_LEX_RPAREN: | 4753 | case BC_LEX_RPAREN: |
4748 | if (bin_last || prev == XC_INST_BOOL_NOT) | 4754 | if (bin_last || prev == XC_INST_BOOL_NOT) |
@@ -4754,27 +4760,30 @@ static BcStatus bc_parse_expr_empty_ok(BcParse *p, uint8_t flags) | |||
4754 | dbg_lex_done("%s:%d done (returning EMPTY_EXP)", __func__, __LINE__); | 4760 | dbg_lex_done("%s:%d done (returning EMPTY_EXP)", __func__, __LINE__); |
4755 | return BC_STATUS_PARSE_EMPTY_EXP; | 4761 | return BC_STATUS_PARSE_EMPTY_EXP; |
4756 | } | 4762 | } |
4763 | s = zbc_parse_rightParen(p, ops_bgn, &nexprs); | ||
4757 | nparens--; | 4764 | nparens--; |
4758 | paren_expr = rprn = true; | 4765 | paren_expr = rprn = true; |
4759 | get_token = bin_last = false; | 4766 | bin_last = false; |
4760 | s = zbc_parse_rightParen(p, ops_bgn, &nexprs); | 4767 | //get_token = false; - already is |
4761 | break; | 4768 | break; |
4762 | case XC_LEX_NAME: | 4769 | case XC_LEX_NAME: |
4763 | if (BC_PARSE_LEAF(prev, rprn)) | 4770 | if (BC_PARSE_LEAF(prev, rprn)) |
4764 | return bc_error_bad_expression(); | 4771 | return bc_error_bad_expression(); |
4765 | paren_expr = true; | ||
4766 | rprn = get_token = bin_last = false; | ||
4767 | s = zbc_parse_name(p, &prev, flags & ~BC_PARSE_NOCALL); | 4772 | s = zbc_parse_name(p, &prev, flags & ~BC_PARSE_NOCALL); |
4773 | paren_expr = true; | ||
4774 | rprn = bin_last = false; | ||
4775 | //get_token = false; - already is | ||
4768 | nexprs++; | 4776 | nexprs++; |
4769 | break; | 4777 | break; |
4770 | case XC_LEX_NUMBER: | 4778 | case XC_LEX_NUMBER: |
4771 | if (BC_PARSE_LEAF(prev, rprn)) | 4779 | if (BC_PARSE_LEAF(prev, rprn)) |
4772 | return bc_error_bad_expression(); | 4780 | return bc_error_bad_expression(); |
4773 | bc_parse_pushNUM(p); | 4781 | bc_parse_pushNUM(p); |
4774 | nexprs++; | ||
4775 | prev = XC_INST_NUM; | 4782 | prev = XC_INST_NUM; |
4776 | paren_expr = get_token = true; | 4783 | get_token = true; |
4784 | paren_expr = true; | ||
4777 | rprn = bin_last = false; | 4785 | rprn = bin_last = false; |
4786 | nexprs++; | ||
4778 | break; | 4787 | break; |
4779 | case BC_LEX_KEY_IBASE: | 4788 | case BC_LEX_KEY_IBASE: |
4780 | case BC_LEX_KEY_LAST: | 4789 | case BC_LEX_KEY_LAST: |
@@ -4783,7 +4792,8 @@ static BcStatus bc_parse_expr_empty_ok(BcParse *p, uint8_t flags) | |||
4783 | return bc_error_bad_expression(); | 4792 | return bc_error_bad_expression(); |
4784 | prev = (char) (t - BC_LEX_KEY_IBASE + XC_INST_IBASE); | 4793 | prev = (char) (t - BC_LEX_KEY_IBASE + XC_INST_IBASE); |
4785 | bc_parse_push(p, (char) prev); | 4794 | bc_parse_push(p, (char) prev); |
4786 | paren_expr = get_token = true; | 4795 | get_token = true; |
4796 | paren_expr = true; | ||
4787 | rprn = bin_last = false; | 4797 | rprn = bin_last = false; |
4788 | nexprs++; | 4798 | nexprs++; |
4789 | break; | 4799 | break; |
@@ -4793,17 +4803,19 @@ static BcStatus bc_parse_expr_empty_ok(BcParse *p, uint8_t flags) | |||
4793 | return bc_error_bad_expression(); | 4803 | return bc_error_bad_expression(); |
4794 | s = zbc_parse_builtin(p, t, flags, &prev); | 4804 | s = zbc_parse_builtin(p, t, flags, &prev); |
4795 | paren_expr = true; | 4805 | paren_expr = true; |
4796 | rprn = get_token = bin_last = false; | 4806 | rprn = bin_last = false; |
4807 | //get_token = false; - already is | ||
4797 | nexprs++; | 4808 | nexprs++; |
4798 | break; | 4809 | break; |
4799 | case BC_LEX_KEY_READ: | 4810 | case BC_LEX_KEY_READ: |
4800 | if (BC_PARSE_LEAF(prev, rprn)) | 4811 | if (BC_PARSE_LEAF(prev, rprn)) |
4801 | return bc_error_bad_expression(); | 4812 | return bc_error_bad_expression(); |
4802 | s = zbc_parse_read(p); | 4813 | s = zbc_parse_read(p); |
4814 | prev = XC_INST_READ; | ||
4803 | paren_expr = true; | 4815 | paren_expr = true; |
4804 | rprn = get_token = bin_last = false; | 4816 | rprn = bin_last = false; |
4817 | //get_token = false; - already is | ||
4805 | nexprs++; | 4818 | nexprs++; |
4806 | prev = XC_INST_READ; | ||
4807 | break; | 4819 | break; |
4808 | case BC_LEX_KEY_SCALE: | 4820 | case BC_LEX_KEY_SCALE: |
4809 | if (BC_PARSE_LEAF(prev, rprn)) | 4821 | if (BC_PARSE_LEAF(prev, rprn)) |
@@ -4811,12 +4823,12 @@ static BcStatus bc_parse_expr_empty_ok(BcParse *p, uint8_t flags) | |||
4811 | s = zbc_parse_scale(p, &prev, flags); | 4823 | s = zbc_parse_scale(p, &prev, flags); |
4812 | prev = XC_INST_SCALE; | 4824 | prev = XC_INST_SCALE; |
4813 | paren_expr = true; | 4825 | paren_expr = true; |
4814 | rprn = get_token = bin_last = false; | 4826 | rprn = bin_last = false; |
4827 | //get_token = false; - already is | ||
4815 | nexprs++; | 4828 | nexprs++; |
4816 | break; | 4829 | break; |
4817 | default: | 4830 | default: |
4818 | s = bc_error_bad_token(); | 4831 | return bc_error_bad_token(); |
4819 | break; | ||
4820 | } | 4832 | } |
4821 | 4833 | ||
4822 | if (s || G_interrupt) // error, or ^C: stop parsing | 4834 | if (s || G_interrupt) // error, or ^C: stop parsing |