diff options
-rw-r--r-- | miscutils/bc.c | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/miscutils/bc.c b/miscutils/bc.c index 06fcc8efa..b3ffe7bfd 100644 --- a/miscutils/bc.c +++ b/miscutils/bc.c | |||
@@ -2965,7 +2965,7 @@ static BC_STATUS zbc_lex_next(BcLex *l) | |||
2965 | l->buf + l->i); | 2965 | l->buf + l->i); |
2966 | ERROR_RETURN(s =) zcommon_lex_token(l); | 2966 | ERROR_RETURN(s =) zcommon_lex_token(l); |
2967 | } while (!s && l->t.t == BC_LEX_WHITESPACE); | 2967 | } while (!s && l->t.t == BC_LEX_WHITESPACE); |
2968 | dbg_lex("next l->t.t:%d", l->t.t); | 2968 | dbg_lex("l->t.t from string:%d", l->t.t); |
2969 | 2969 | ||
2970 | RETURN_STATUS(s); | 2970 | RETURN_STATUS(s); |
2971 | } | 2971 | } |
@@ -4094,6 +4094,7 @@ static BC_STATUS zbc_parse_endBody(BcParse *p, bool brace) | |||
4094 | bc_vec_pop(&p->flags); | 4094 | bc_vec_pop(&p->flags); |
4095 | 4095 | ||
4096 | flag_ptr = BC_PARSE_TOP_FLAG_PTR(p); | 4096 | flag_ptr = BC_PARSE_TOP_FLAG_PTR(p); |
4097 | dbg_lex("%s:%d setting BC_PARSE_FLAG_IF_END bit", __func__, __LINE__); | ||
4097 | *flag_ptr = (*flag_ptr | BC_PARSE_FLAG_IF_END); | 4098 | *flag_ptr = (*flag_ptr | BC_PARSE_FLAG_IF_END); |
4098 | 4099 | ||
4099 | if (p->l.t.t == BC_LEX_KEY_ELSE) | 4100 | if (p->l.t.t == BC_LEX_KEY_ELSE) |
@@ -4151,6 +4152,7 @@ static void bc_parse_noElse(BcParse *p) | |||
4151 | size_t *label; | 4152 | size_t *label; |
4152 | uint8_t *flag_ptr = BC_PARSE_TOP_FLAG_PTR(p); | 4153 | uint8_t *flag_ptr = BC_PARSE_TOP_FLAG_PTR(p); |
4153 | 4154 | ||
4155 | dbg_lex("%s:%d clearing BC_PARSE_FLAG_IF_END bit", __func__, __LINE__); | ||
4154 | *flag_ptr = (*flag_ptr & ~(BC_PARSE_FLAG_IF_END)); | 4156 | *flag_ptr = (*flag_ptr & ~(BC_PARSE_FLAG_IF_END)); |
4155 | 4157 | ||
4156 | ip = bc_vec_top(&p->exits); | 4158 | ip = bc_vec_top(&p->exits); |
@@ -4200,7 +4202,7 @@ static BC_STATUS zbc_parse_else(BcParse *p) | |||
4200 | { | 4202 | { |
4201 | BcInstPtr ip; | 4203 | BcInstPtr ip; |
4202 | 4204 | ||
4203 | dbg_lex("%s:%d p->l.t.t:%d", __func__, __LINE__, p->l.t.t); | 4205 | dbg_lex_enter("%s:%d entered", __func__, __LINE__); |
4204 | if (!BC_PARSE_IF_END(p)) RETURN_STATUS(bc_error_bad_token()); | 4206 | if (!BC_PARSE_IF_END(p)) RETURN_STATUS(bc_error_bad_token()); |
4205 | 4207 | ||
4206 | ip.idx = p->func->labels.len; | 4208 | ip.idx = p->func->labels.len; |
@@ -4209,12 +4211,14 @@ static BC_STATUS zbc_parse_else(BcParse *p) | |||
4209 | bc_parse_push(p, BC_INST_JUMP); | 4211 | bc_parse_push(p, BC_INST_JUMP); |
4210 | bc_parse_pushIndex(p, ip.idx); | 4212 | bc_parse_pushIndex(p, ip.idx); |
4211 | 4213 | ||
4214 | dbg_lex("%s:%d calling bc_parse_noElse()", __func__, __LINE__); | ||
4212 | bc_parse_noElse(p); | 4215 | bc_parse_noElse(p); |
4213 | 4216 | ||
4214 | bc_vec_push(&p->exits, &ip); | 4217 | bc_vec_push(&p->exits, &ip); |
4215 | bc_vec_push(&p->func->labels, &ip.idx); | 4218 | bc_vec_push(&p->func->labels, &ip.idx); |
4216 | bc_parse_startBody(p, BC_PARSE_FLAG_ELSE); | 4219 | bc_parse_startBody(p, BC_PARSE_FLAG_ELSE); |
4217 | 4220 | ||
4221 | dbg_lex_done("%s:%d done", __func__, __LINE__); | ||
4218 | RETURN_STATUS(zbc_lex_next(&p->l)); | 4222 | RETURN_STATUS(zbc_lex_next(&p->l)); |
4219 | } | 4223 | } |
4220 | #if ERRORS_ARE_FATAL | 4224 | #if ERRORS_ARE_FATAL |
@@ -4520,9 +4524,11 @@ static BC_STATUS zbc_parse_body(BcParse *p, bool brace) | |||
4520 | BcStatus s = BC_STATUS_SUCCESS; | 4524 | BcStatus s = BC_STATUS_SUCCESS; |
4521 | uint8_t *flag_ptr = bc_vec_top(&p->flags); | 4525 | uint8_t *flag_ptr = bc_vec_top(&p->flags); |
4522 | 4526 | ||
4527 | dbg_lex_enter("%s:%d entered", __func__, __LINE__); | ||
4523 | *flag_ptr &= ~(BC_PARSE_FLAG_BODY); | 4528 | *flag_ptr &= ~(BC_PARSE_FLAG_BODY); |
4524 | 4529 | ||
4525 | if (*flag_ptr & BC_PARSE_FLAG_FUNC_INNER) { | 4530 | if (*flag_ptr & BC_PARSE_FLAG_FUNC_INNER) { |
4531 | dbg_lex("%s:%d BC_PARSE_FLAG_FUNC_INNER", __func__, __LINE__); | ||
4526 | if (!brace) RETURN_STATUS(bc_error_bad_token()); | 4532 | if (!brace) RETURN_STATUS(bc_error_bad_token()); |
4527 | 4533 | ||
4528 | p->auto_part = p->l.t.t != BC_LEX_KEY_AUTO; | 4534 | p->auto_part = p->l.t.t != BC_LEX_KEY_AUTO; |
@@ -4535,10 +4541,12 @@ static BC_STATUS zbc_parse_body(BcParse *p, bool brace) | |||
4535 | if (p->l.t.t == BC_LEX_NLINE) s = zbc_lex_next(&p->l); | 4541 | if (p->l.t.t == BC_LEX_NLINE) s = zbc_lex_next(&p->l); |
4536 | } | 4542 | } |
4537 | else { | 4543 | else { |
4544 | dbg_lex("%s:%d !BC_PARSE_FLAG_FUNC_INNER", __func__, __LINE__); | ||
4538 | s = zbc_parse_stmt(p); | 4545 | s = zbc_parse_stmt(p); |
4539 | if (!s && !brace) s = zbc_parse_endBody(p, false); | 4546 | if (!s && !brace) s = zbc_parse_endBody(p, false); |
4540 | } | 4547 | } |
4541 | 4548 | ||
4549 | dbg_lex_done("%s:%d done", __func__, __LINE__); | ||
4542 | RETURN_STATUS(s); | 4550 | RETURN_STATUS(s); |
4543 | } | 4551 | } |
4544 | #if ERRORS_ARE_FATAL | 4552 | #if ERRORS_ARE_FATAL |
@@ -4553,6 +4561,7 @@ static BC_STATUS zbc_parse_stmt(BcParse *p) | |||
4553 | dbg_lex_enter("%s:%d entered, p->l.t.t:%d", __func__, __LINE__, p->l.t.t); | 4561 | dbg_lex_enter("%s:%d entered, p->l.t.t:%d", __func__, __LINE__, p->l.t.t); |
4554 | switch (p->l.t.t) { | 4562 | switch (p->l.t.t) { |
4555 | case BC_LEX_NLINE: | 4563 | case BC_LEX_NLINE: |
4564 | dbg_lex_done("%s:%d done (seen BC_LEX_NLINE)", __func__, __LINE__); | ||
4556 | RETURN_STATUS(zbc_lex_next(&p->l)); | 4565 | RETURN_STATUS(zbc_lex_next(&p->l)); |
4557 | 4566 | ||
4558 | case BC_LEX_KEY_ELSE: | 4567 | case BC_LEX_KEY_ELSE: |
@@ -4564,6 +4573,7 @@ static BC_STATUS zbc_parse_stmt(BcParse *p) | |||
4564 | ++p->nbraces; | 4573 | ++p->nbraces; |
4565 | s = zbc_lex_next(&p->l); | 4574 | s = zbc_lex_next(&p->l); |
4566 | if (s) RETURN_STATUS(s); | 4575 | if (s) RETURN_STATUS(s); |
4576 | dbg_lex_done("%s:%d done (returning zbc_parse_body())", __func__, __LINE__); | ||
4567 | RETURN_STATUS(zbc_parse_body(p, true)); | 4577 | RETURN_STATUS(zbc_parse_body(p, true)); |
4568 | 4578 | ||
4569 | case BC_LEX_KEY_AUTO: | 4579 | case BC_LEX_KEY_AUTO: |
@@ -4573,10 +4583,13 @@ static BC_STATUS zbc_parse_stmt(BcParse *p) | |||
4573 | p->auto_part = false; | 4583 | p->auto_part = false; |
4574 | if (BC_PARSE_IF_END(p)) { | 4584 | if (BC_PARSE_IF_END(p)) { |
4575 | bc_parse_noElse(p); | 4585 | bc_parse_noElse(p); |
4586 | dbg_lex_done("%s:%d done (BC_PARSE_IF_END is true)", __func__, __LINE__); | ||
4576 | RETURN_STATUS(BC_STATUS_SUCCESS); | 4587 | RETURN_STATUS(BC_STATUS_SUCCESS); |
4577 | } | 4588 | } |
4578 | if (BC_PARSE_BODY(p)) | 4589 | if (BC_PARSE_BODY(p)) { |
4590 | dbg_lex_done("%s:%d done (returning zbc_parse_body())", __func__, __LINE__); | ||
4579 | RETURN_STATUS(zbc_parse_body(p, false)); | 4591 | RETURN_STATUS(zbc_parse_body(p, false)); |
4592 | } | ||
4580 | break; | 4593 | break; |
4581 | } | 4594 | } |
4582 | 4595 | ||
@@ -4705,6 +4718,7 @@ static BcStatus bc_parse_expr_empty_ok(BcParse *p, uint8_t flags, BcParseNext ne | |||
4705 | unsigned nparens, nrelops; | 4718 | unsigned nparens, nrelops; |
4706 | bool paren_first, paren_expr, rprn, done, get_token, assign, bin_last; | 4719 | bool paren_first, paren_expr, rprn, done, get_token, assign, bin_last; |
4707 | 4720 | ||
4721 | dbg_lex_enter("%s:%d entered", __func__, __LINE__); | ||
4708 | paren_first = p->l.t.t == BC_LEX_LPAREN; | 4722 | paren_first = p->l.t.t == BC_LEX_LPAREN; |
4709 | nparens = nrelops = 0; | 4723 | nparens = nrelops = 0; |
4710 | paren_expr = rprn = done = get_token = assign = false; | 4724 | paren_expr = rprn = done = get_token = assign = false; |
@@ -4803,8 +4817,10 @@ static BcStatus bc_parse_expr_empty_ok(BcParse *p, uint8_t flags, BcParseNext ne | |||
4803 | get_token = false; | 4817 | get_token = false; |
4804 | break; | 4818 | break; |
4805 | } | 4819 | } |
4806 | else if (!paren_expr) | 4820 | else if (!paren_expr) { |
4821 | dbg_lex_done("%s:%d done (returning EMPTY_EXP)", __func__, __LINE__); | ||
4807 | return BC_STATUS_PARSE_EMPTY_EXP; | 4822 | return BC_STATUS_PARSE_EMPTY_EXP; |
4823 | } | ||
4808 | 4824 | ||
4809 | --nparens; | 4825 | --nparens; |
4810 | paren_expr = rprn = true; | 4826 | paren_expr = rprn = true; |
@@ -4952,6 +4968,7 @@ static BcStatus bc_parse_expr_empty_ok(BcParse *p, uint8_t flags, BcParseNext ne | |||
4952 | bc_parse_push(p, BC_INST_POP); | 4968 | bc_parse_push(p, BC_INST_POP); |
4953 | } | 4969 | } |
4954 | 4970 | ||
4971 | dbg_lex_done("%s:%d done", __func__, __LINE__); | ||
4955 | return s; | 4972 | return s; |
4956 | } | 4973 | } |
4957 | 4974 | ||