From 5fa74b9efc538b55ec164ce3886eeea782016487 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 25 Dec 2018 17:07:51 +0100 Subject: [PATCH] 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 --- miscutils/bc.c | 18 +++++------------- 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) bc_parse_push(p, XC_INST_READ); - RETURN_STATUS(zbc_lex_next(&p->l)); + RETURN_STATUS(s); } #define zbc_parse_read(...) (zbc_parse_read(__VA_ARGS__) COMMA_SUCCESS) @@ -3953,7 +3953,7 @@ static BC_STATUS zbc_parse_builtin(BcParse *p, BcLexType type, uint8_t flags, *prev = (type == BC_LEX_KEY_LENGTH) ? XC_INST_LENGTH : XC_INST_SQRT; bc_parse_push(p, *prev); - RETURN_STATUS(zbc_lex_next(&p->l)); + RETURN_STATUS(s); } #define zbc_parse_builtin(...) (zbc_parse_builtin(__VA_ARGS__) COMMA_SUCCESS) @@ -4328,7 +4328,6 @@ static BC_STATUS zbc_parse_for(BcParse *p) static BC_STATUS zbc_parse_break_or_continue(BcParse *p, BcLexType type) { - BcStatus s; size_t i; if (type == BC_LEX_KEY_BREAK) { @@ -4338,15 +4337,8 @@ static BC_STATUS zbc_parse_break_or_continue(BcParse *p, BcLexType type) } else { i = *(size_t*)bc_vec_top(&p->conds); } - bc_parse_pushJUMP(p, i); - s = zbc_lex_next(&p->l); - if (s) RETURN_STATUS(s); - - if (p->l.lex != BC_LEX_SCOLON && p->l.lex != XC_LEX_NLINE) - RETURN_STATUS(bc_error_bad_token()); - RETURN_STATUS(zbc_lex_next(&p->l)); } #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) if (BC_PARSE_LEAF(prev, rprn)) return bc_error_bad_expression(); s = zbc_parse_builtin(p, t, flags, &prev); + get_token = true; paren_expr = true; rprn = bin_last = false; - //get_token = false; - already is nexprs++; break; case BC_LEX_KEY_READ: @@ -4810,9 +4802,9 @@ static BcStatus bc_parse_expr_empty_ok(BcParse *p, uint8_t flags) return bc_error_bad_expression(); s = zbc_parse_read(p); prev = XC_INST_READ; + get_token = true; paren_expr = true; rprn = bin_last = false; - //get_token = false; - already is nexprs++; break; case BC_LEX_KEY_SCALE: @@ -4820,9 +4812,9 @@ static BcStatus bc_parse_expr_empty_ok(BcParse *p, uint8_t flags) return bc_error_bad_expression(); s = zbc_parse_scale(p, &prev, flags); prev = XC_INST_SCALE; + //get_token = false; - already is paren_expr = true; rprn = bin_last = false; - //get_token = false; - already is nexprs++; break; 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" \ "2\n9\n" \ "" "if (0) 1 else if (1) 2; 9" -testing "bc for(;;)" \ +testing "bc for (;;)" \ "bc" \ "2\n3\n2\n9\n" \ "" "i=2; for (;;) { 2; if(--i==0) break; 3; }; 9" @@ -86,6 +86,11 @@ testing "bc for (init;cond;upd)" \ "1\n2\n3\n9\n" \ "" "for(i=1;i<4;i++)i; 9" +testing "bc for (;;) {break}" \ + "bc" \ + "2\n9\n" \ + "" "for (;;) {2;break}; 9" + testing "bc define auto" \ "bc" \ "8\n9\n" \