diff options
author | Denys Vlasenko | 2018-12-25 01:43:52 +0100 |
---|---|---|
committer | Denys Vlasenko | 2018-12-25 01:43:52 +0100 |
commit | 73b3ebc0e18f95d9eda7e33dfc878f9792d1b1e1 (patch) | |
tree | 7f656aea1d48558b4928dabdaf10907b51408491 /miscutils | |
parent | d0238d83f0311cfab52897acc739148879598621 (diff) | |
download | busybox-73b3ebc0e18f95d9eda7e33dfc878f9792d1b1e1.zip busybox-73b3ebc0e18f95d9eda7e33dfc878f9792d1b1e1.tar.gz |
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>
Diffstat (limited to 'miscutils')
-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 a57de97..2b37088 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) BcInst prev = XC_INST_PRINT; size_t nexprs = 0, ops_bgn = p->ops.len; unsigned nparens, nrelops; - bool paren_first, paren_expr, rprn, get_token, assign, bin_last; + bool paren_first, paren_expr, rprn, assign, bin_last; dbg_lex_enter("%s:%d entered", __func__, __LINE__); paren_first = (p->l.lex == BC_LEX_LPAREN); nparens = nrelops = 0; - paren_expr = rprn = get_token = assign = false; + paren_expr = rprn = assign = false; bin_last = true; for (;;) { + bool get_token; BcStatus s; BcLexType t = p->l.lex; @@ -4680,16 +4681,19 @@ static BcStatus bc_parse_expr_empty_ok(BcParse *p, uint8_t flags) break; dbg_lex("%s:%d t:%d", __func__, __LINE__, t); + get_token = false; s = BC_STATUS_SUCCESS; switch (t) { case BC_LEX_OP_INC: case BC_LEX_OP_DEC: s = zbc_parse_incdec(p, &prev, &paren_expr, &nexprs, flags); - rprn = get_token = bin_last = false; + rprn = bin_last = false; + //get_token = false; - already is break; case XC_LEX_OP_MINUS: s = zbc_parse_minus(p, &prev, ops_bgn, rprn, &nexprs); - rprn = get_token = false; + rprn = false; + //get_token = false; - already is bin_last = (prev == XC_INST_MINUS); break; case BC_LEX_OP_ASSIGN_POWER: @@ -4733,16 +4737,18 @@ static BcStatus bc_parse_expr_empty_ok(BcParse *p, uint8_t flags) prev = BC_TOKEN_2_INST(t); bc_parse_operator(p, t, ops_bgn, &nexprs); s = zbc_lex_next(&p->l); - rprn = get_token = false; + rprn = false; + //get_token = false; - already is bin_last = (t != BC_LEX_OP_BOOL_NOT); break; case BC_LEX_LPAREN: if (BC_PARSE_LEAF(prev, rprn)) return bc_error_bad_expression(); + bc_vec_push(&p->ops, &t); nparens++; - paren_expr = rprn = bin_last = false; get_token = true; - bc_vec_push(&p->ops, &t); + paren_expr = false; + rprn = bin_last = false; break; case BC_LEX_RPAREN: if (bin_last || prev == XC_INST_BOOL_NOT) @@ -4754,27 +4760,30 @@ static BcStatus bc_parse_expr_empty_ok(BcParse *p, uint8_t flags) dbg_lex_done("%s:%d done (returning EMPTY_EXP)", __func__, __LINE__); return BC_STATUS_PARSE_EMPTY_EXP; } + s = zbc_parse_rightParen(p, ops_bgn, &nexprs); nparens--; paren_expr = rprn = true; - get_token = bin_last = false; - s = zbc_parse_rightParen(p, ops_bgn, &nexprs); + bin_last = false; + //get_token = false; - already is break; case XC_LEX_NAME: if (BC_PARSE_LEAF(prev, rprn)) return bc_error_bad_expression(); - paren_expr = true; - rprn = get_token = bin_last = false; s = zbc_parse_name(p, &prev, flags & ~BC_PARSE_NOCALL); + paren_expr = true; + rprn = bin_last = false; + //get_token = false; - already is nexprs++; break; case XC_LEX_NUMBER: if (BC_PARSE_LEAF(prev, rprn)) return bc_error_bad_expression(); bc_parse_pushNUM(p); - nexprs++; prev = XC_INST_NUM; - paren_expr = get_token = true; + get_token = true; + paren_expr = true; rprn = bin_last = false; + nexprs++; break; case BC_LEX_KEY_IBASE: case BC_LEX_KEY_LAST: @@ -4783,7 +4792,8 @@ static BcStatus bc_parse_expr_empty_ok(BcParse *p, uint8_t flags) return bc_error_bad_expression(); prev = (char) (t - BC_LEX_KEY_IBASE + XC_INST_IBASE); bc_parse_push(p, (char) prev); - paren_expr = get_token = true; + get_token = true; + paren_expr = true; rprn = bin_last = false; nexprs++; break; @@ -4793,17 +4803,19 @@ static BcStatus bc_parse_expr_empty_ok(BcParse *p, uint8_t flags) return bc_error_bad_expression(); s = zbc_parse_builtin(p, t, flags, &prev); paren_expr = true; - rprn = get_token = bin_last = false; + rprn = bin_last = false; + //get_token = false; - already is nexprs++; break; case BC_LEX_KEY_READ: if (BC_PARSE_LEAF(prev, rprn)) return bc_error_bad_expression(); s = zbc_parse_read(p); + prev = XC_INST_READ; paren_expr = true; - rprn = get_token = bin_last = false; + rprn = bin_last = false; + //get_token = false; - already is nexprs++; - prev = XC_INST_READ; break; case BC_LEX_KEY_SCALE: if (BC_PARSE_LEAF(prev, rprn)) @@ -4811,12 +4823,12 @@ static BcStatus bc_parse_expr_empty_ok(BcParse *p, uint8_t flags) s = zbc_parse_scale(p, &prev, flags); prev = XC_INST_SCALE; paren_expr = true; - rprn = get_token = bin_last = false; + rprn = bin_last = false; + //get_token = false; - already is nexprs++; break; default: - s = bc_error_bad_token(); - break; + return bc_error_bad_token(); } if (s || G_interrupt) // error, or ^C: stop parsing |