mirror of
https://git.busybox.net/busybox.git
synced 2024-11-27 15:43:26 +08:00
shell/math: remove special code to handle a?b?c:d:e, it works without it now
The "hack" to virtually parenthesize ? EXPR : made this unnecessary. The expression is effectively a?(b?(c):d):e and thus b?c:d is evaluated before continuing with the second : function old new delta evaluate_string 1148 1132 -16 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
parent
5f56a03882
commit
61a4959251
1
shell/ash_test/ash-arith/arith-ternary_nested2.right
Normal file
1
shell/ash_test/ash-arith/arith-ternary_nested2.right
Normal file
@ -0,0 +1 @@
|
||||
3:3
|
2
shell/ash_test/ash-arith/arith-ternary_nested2.tests
Executable file
2
shell/ash_test/ash-arith/arith-ternary_nested2.tests
Executable file
@ -0,0 +1,2 @@
|
||||
exec 2>&1
|
||||
echo 3:$((0?1:2?3:4?5:6?7:8))
|
1
shell/hush_test/hush-arith/arith-ternary_nested2.right
Normal file
1
shell/hush_test/hush-arith/arith-ternary_nested2.right
Normal file
@ -0,0 +1 @@
|
||||
3:3
|
2
shell/hush_test/hush-arith/arith-ternary_nested2.tests
Executable file
2
shell/hush_test/hush-arith/arith-ternary_nested2.tests
Executable file
@ -0,0 +1,2 @@
|
||||
exec 2>&1
|
||||
echo 3:$((0?1:2?3:4?5:6?7:8))
|
12
shell/math.c
12
shell/math.c
@ -840,15 +840,9 @@ evaluate_string(arith_state_t *math_state, const char *expr)
|
||||
if (prev_prec < prec
|
||||
|| (prev_prec == prec && is_right_associative(prec))
|
||||
) {
|
||||
/* Unless a?b?c:d:... and we are at the second : */
|
||||
if (op != TOK_CONDITIONAL_SEP
|
||||
|| prev_op != TOK_CONDITIONAL_SEP
|
||||
) {
|
||||
/* ...x~y@: push @ on opstack */
|
||||
opstackptr++; /* undo removal of ~ op */
|
||||
goto push_op;
|
||||
}
|
||||
/* else: a?b?c:d:. Evaluate b?c:d, replace it on stack with result. Then repeat */
|
||||
/* ...x~y@: push @ on opstack */
|
||||
opstackptr++; /* undo removal of ~ op */
|
||||
goto push_op;
|
||||
}
|
||||
/* else: ...x~y@. Evaluate x~y, replace it on stack with result. Then repeat */
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user