shell: small code shrink
function old new delta arith 680 675 -5 Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
This commit is contained in:
17
shell/math.c
17
shell/math.c
@ -635,28 +635,29 @@ arith(const char *expr, int *perrcode, a_e_h_t *math_hooks)
|
|||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
while (stackptr != stack) {
|
while (stackptr != stack) {
|
||||||
|
operator prev_op = *--stackptr;
|
||||||
if (op == TOK_RPAREN) {
|
if (op == TOK_RPAREN) {
|
||||||
/* The algorithm employed here is simple: while we don't
|
/* The algorithm employed here is simple: while we don't
|
||||||
* hit an open paren nor the bottom of the stack, pop
|
* hit an open paren nor the bottom of the stack, pop
|
||||||
* tokens and apply them */
|
* tokens and apply them */
|
||||||
if (stackptr[-1] == TOK_LPAREN) {
|
if (prev_op == TOK_LPAREN) {
|
||||||
--stackptr;
|
|
||||||
/* Any operator directly after a */
|
/* Any operator directly after a */
|
||||||
lasttok = TOK_NUM;
|
lasttok = TOK_NUM;
|
||||||
/* close paren should consider itself binary */
|
/* close paren should consider itself binary */
|
||||||
goto next;
|
goto next;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
operator prev_prec = PREC(stackptr[-1]);
|
operator prev_prec = PREC(prev_op);
|
||||||
convert_prec_is_assign(prec);
|
convert_prec_is_assign(prec);
|
||||||
convert_prec_is_assign(prev_prec);
|
convert_prec_is_assign(prev_prec);
|
||||||
if (prev_prec < prec)
|
if (prev_prec < prec
|
||||||
break;
|
|| (prev_prec == prec && is_right_associativity(prec))
|
||||||
/* check right assoc */
|
) {
|
||||||
if (prev_prec == prec && is_right_associativity(prec))
|
stackptr++;
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
errcode = arith_apply(*--stackptr, numstack, &numstackptr, math_hooks);
|
errcode = arith_apply(prev_op, numstack, &numstackptr, math_hooks);
|
||||||
if (errcode)
|
if (errcode)
|
||||||
goto ret;
|
goto ret;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user