diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2018-12-25 17:07:51 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2018-12-25 17:07:51 +0100 |
commit | 5fa74b9efc538b55ec164ce3886eeea782016487 (patch) | |
tree | a83a0aeb487e238aec783b51446885c242a01cd2 | |
parent | d4b721cc8b708a2fa4ddd821179c00865c11619e (diff) | |
download | busybox-w32-5fa74b9efc538b55ec164ce3886eeea782016487.tar.gz busybox-w32-5fa74b9efc538b55ec164ce3886eeea782016487.tar.bz2 busybox-w32-5fa74b9efc538b55ec164ce3886eeea782016487.zip |
bc: allow {break} and {continue} (allow RBRACE to terminate them)
function old new delta
zbc_parse_stmt_possibly_auto 1599 1560 -39
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | miscutils/bc.c | 18 | ||||
-rwxr-xr-x | testsuite/bc.tests | 7 |
2 files changed, 11 insertions, 14 deletions
diff --git a/miscutils/bc.c b/miscutils/bc.c index ec2f86133..7c8edcf33 100644 --- a/miscutils/bc.c +++ b/miscutils/bc.c | |||
@@ -3927,7 +3927,7 @@ static BC_STATUS zbc_parse_read(BcParse *p) | |||
3927 | 3927 | ||
3928 | bc_parse_push(p, XC_INST_READ); | 3928 | bc_parse_push(p, XC_INST_READ); |
3929 | 3929 | ||
3930 | RETURN_STATUS(zbc_lex_next(&p->l)); | 3930 | RETURN_STATUS(s); |
3931 | } | 3931 | } |
3932 | #define zbc_parse_read(...) (zbc_parse_read(__VA_ARGS__) COMMA_SUCCESS) | 3932 | #define zbc_parse_read(...) (zbc_parse_read(__VA_ARGS__) COMMA_SUCCESS) |
3933 | 3933 | ||
@@ -3953,7 +3953,7 @@ static BC_STATUS zbc_parse_builtin(BcParse *p, BcLexType type, uint8_t flags, | |||
3953 | *prev = (type == BC_LEX_KEY_LENGTH) ? XC_INST_LENGTH : XC_INST_SQRT; | 3953 | *prev = (type == BC_LEX_KEY_LENGTH) ? XC_INST_LENGTH : XC_INST_SQRT; |
3954 | bc_parse_push(p, *prev); | 3954 | bc_parse_push(p, *prev); |
3955 | 3955 | ||
3956 | RETURN_STATUS(zbc_lex_next(&p->l)); | 3956 | RETURN_STATUS(s); |
3957 | } | 3957 | } |
3958 | #define zbc_parse_builtin(...) (zbc_parse_builtin(__VA_ARGS__) COMMA_SUCCESS) | 3958 | #define zbc_parse_builtin(...) (zbc_parse_builtin(__VA_ARGS__) COMMA_SUCCESS) |
3959 | 3959 | ||
@@ -4328,7 +4328,6 @@ static BC_STATUS zbc_parse_for(BcParse *p) | |||
4328 | 4328 | ||
4329 | static BC_STATUS zbc_parse_break_or_continue(BcParse *p, BcLexType type) | 4329 | static BC_STATUS zbc_parse_break_or_continue(BcParse *p, BcLexType type) |
4330 | { | 4330 | { |
4331 | BcStatus s; | ||
4332 | size_t i; | 4331 | size_t i; |
4333 | 4332 | ||
4334 | if (type == BC_LEX_KEY_BREAK) { | 4333 | if (type == BC_LEX_KEY_BREAK) { |
@@ -4338,15 +4337,8 @@ static BC_STATUS zbc_parse_break_or_continue(BcParse *p, BcLexType type) | |||
4338 | } else { | 4337 | } else { |
4339 | i = *(size_t*)bc_vec_top(&p->conds); | 4338 | i = *(size_t*)bc_vec_top(&p->conds); |
4340 | } | 4339 | } |
4341 | |||
4342 | bc_parse_pushJUMP(p, i); | 4340 | bc_parse_pushJUMP(p, i); |
4343 | 4341 | ||
4344 | s = zbc_lex_next(&p->l); | ||
4345 | if (s) RETURN_STATUS(s); | ||
4346 | |||
4347 | if (p->l.lex != BC_LEX_SCOLON && p->l.lex != XC_LEX_NLINE) | ||
4348 | RETURN_STATUS(bc_error_bad_token()); | ||
4349 | |||
4350 | RETURN_STATUS(zbc_lex_next(&p->l)); | 4342 | RETURN_STATUS(zbc_lex_next(&p->l)); |
4351 | } | 4343 | } |
4352 | #define zbc_parse_break_or_continue(...) (zbc_parse_break_or_continue(__VA_ARGS__) COMMA_SUCCESS) | 4344 | #define zbc_parse_break_or_continue(...) (zbc_parse_break_or_continue(__VA_ARGS__) COMMA_SUCCESS) |
@@ -4800,9 +4792,9 @@ static BcStatus bc_parse_expr_empty_ok(BcParse *p, uint8_t flags) | |||
4800 | if (BC_PARSE_LEAF(prev, rprn)) | 4792 | if (BC_PARSE_LEAF(prev, rprn)) |
4801 | return bc_error_bad_expression(); | 4793 | return bc_error_bad_expression(); |
4802 | s = zbc_parse_builtin(p, t, flags, &prev); | 4794 | s = zbc_parse_builtin(p, t, flags, &prev); |
4795 | get_token = true; | ||
4803 | paren_expr = true; | 4796 | paren_expr = true; |
4804 | rprn = bin_last = false; | 4797 | rprn = bin_last = false; |
4805 | //get_token = false; - already is | ||
4806 | nexprs++; | 4798 | nexprs++; |
4807 | break; | 4799 | break; |
4808 | case BC_LEX_KEY_READ: | 4800 | case BC_LEX_KEY_READ: |
@@ -4810,9 +4802,9 @@ static BcStatus bc_parse_expr_empty_ok(BcParse *p, uint8_t flags) | |||
4810 | return bc_error_bad_expression(); | 4802 | return bc_error_bad_expression(); |
4811 | s = zbc_parse_read(p); | 4803 | s = zbc_parse_read(p); |
4812 | prev = XC_INST_READ; | 4804 | prev = XC_INST_READ; |
4805 | get_token = true; | ||
4813 | paren_expr = true; | 4806 | paren_expr = true; |
4814 | rprn = bin_last = false; | 4807 | rprn = bin_last = false; |
4815 | //get_token = false; - already is | ||
4816 | nexprs++; | 4808 | nexprs++; |
4817 | break; | 4809 | break; |
4818 | case BC_LEX_KEY_SCALE: | 4810 | case BC_LEX_KEY_SCALE: |
@@ -4820,9 +4812,9 @@ static BcStatus bc_parse_expr_empty_ok(BcParse *p, uint8_t flags) | |||
4820 | return bc_error_bad_expression(); | 4812 | return bc_error_bad_expression(); |
4821 | s = zbc_parse_scale(p, &prev, flags); | 4813 | s = zbc_parse_scale(p, &prev, flags); |
4822 | prev = XC_INST_SCALE; | 4814 | prev = XC_INST_SCALE; |
4815 | //get_token = false; - already is | ||
4823 | paren_expr = true; | 4816 | paren_expr = true; |
4824 | rprn = bin_last = false; | 4817 | rprn = bin_last = false; |
4825 | //get_token = false; - already is | ||
4826 | nexprs++; | 4818 | nexprs++; |
4827 | break; | 4819 | break; |
4828 | default: | 4820 | default: |
diff --git a/testsuite/bc.tests b/testsuite/bc.tests index c84a2987c..42fe83013 100755 --- a/testsuite/bc.tests +++ b/testsuite/bc.tests | |||
@@ -66,7 +66,7 @@ testing "bc if 0 else if 1" \ | |||
66 | "2\n9\n" \ | 66 | "2\n9\n" \ |
67 | "" "if (0) 1 else if (1) 2; 9" | 67 | "" "if (0) 1 else if (1) 2; 9" |
68 | 68 | ||
69 | testing "bc for(;;)" \ | 69 | testing "bc for (;;)" \ |
70 | "bc" \ | 70 | "bc" \ |
71 | "2\n3\n2\n9\n" \ | 71 | "2\n3\n2\n9\n" \ |
72 | "" "i=2; for (;;) { 2; if(--i==0) break; 3; }; 9" | 72 | "" "i=2; for (;;) { 2; if(--i==0) break; 3; }; 9" |
@@ -86,6 +86,11 @@ testing "bc for (init;cond;upd)" \ | |||
86 | "1\n2\n3\n9\n" \ | 86 | "1\n2\n3\n9\n" \ |
87 | "" "for(i=1;i<4;i++)i; 9" | 87 | "" "for(i=1;i<4;i++)i; 9" |
88 | 88 | ||
89 | testing "bc for (;;) {break}" \ | ||
90 | "bc" \ | ||
91 | "2\n9\n" \ | ||
92 | "" "for (;;) {2;break}; 9" | ||
93 | |||
89 | testing "bc define auto" \ | 94 | testing "bc define auto" \ |
90 | "bc" \ | 95 | "bc" \ |
91 | "8\n9\n" \ | 96 | "8\n9\n" \ |