diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2018-12-24 14:14:23 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2018-12-24 14:14:23 +0100 |
commit | 69560f42da3deb5c87a9ccdbcaae26a5ff0cabaf (patch) | |
tree | 8c68c6cc0770e13b546a9c4bfb4d9aeaf030a38b /miscutils/bc.c | |
parent | abf6cf67654425a7ede2f9c18e83f35c48cd67f8 (diff) | |
download | busybox-w32-69560f42da3deb5c87a9ccdbcaae26a5ff0cabaf.tar.gz busybox-w32-69560f42da3deb5c87a9ccdbcaae26a5ff0cabaf.tar.bz2 busybox-w32-69560f42da3deb5c87a9ccdbcaae26a5ff0cabaf.zip |
bc: rename several BC_LEX_OPs to XC_LEX_OPs.
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to '')
-rw-r--r-- | miscutils/bc.c | 143 |
1 files changed, 72 insertions, 71 deletions
diff --git a/miscutils/bc.c b/miscutils/bc.c index 3ae88f1a5..f9d654afb 100644 --- a/miscutils/bc.c +++ b/miscutils/bc.c | |||
@@ -388,27 +388,27 @@ typedef struct BcInstPtr { | |||
388 | IF_BC(size_t results_len_before_call;) | 388 | IF_BC(size_t results_len_before_call;) |
389 | } BcInstPtr; | 389 | } BcInstPtr; |
390 | 390 | ||
391 | // BC_LEX_NEG is not used in lexing; it is only for parsing. | 391 | // XC_LEX_NEG is not used in lexing; it is only for parsing. |
392 | typedef enum BcLexType { | 392 | typedef enum BcLexType { |
393 | XC_LEX_EOF, | 393 | XC_LEX_EOF, |
394 | XC_LEX_INVALID, | 394 | XC_LEX_INVALID, |
395 | 395 | ||
396 | BC_LEX_1st_op, | 396 | XC_LEX_1st_op, |
397 | BC_LEX_NEG = BC_LEX_1st_op, // order | 397 | XC_LEX_NEG = XC_LEX_1st_op, // order |
398 | 398 | ||
399 | BC_LEX_OP_POWER, // should | 399 | XC_LEX_OP_POWER, // should |
400 | BC_LEX_OP_MULTIPLY, // match | 400 | XC_LEX_OP_MULTIPLY, // match |
401 | BC_LEX_OP_DIVIDE, // INST | 401 | XC_LEX_OP_DIVIDE, // INST |
402 | BC_LEX_OP_MODULUS, // constants | 402 | XC_LEX_OP_MODULUS, // constants |
403 | BC_LEX_OP_PLUS, // for | 403 | XC_LEX_OP_PLUS, // for |
404 | BC_LEX_OP_MINUS, // these | 404 | XC_LEX_OP_MINUS, // these |
405 | 405 | ||
406 | BC_LEX_OP_REL_EQ, // opeartions | 406 | XC_LEX_OP_REL_EQ, // opeartions |
407 | BC_LEX_OP_REL_LE, // | | 407 | XC_LEX_OP_REL_LE, // | |
408 | BC_LEX_OP_REL_GE, // | | 408 | XC_LEX_OP_REL_GE, // | |
409 | BC_LEX_OP_REL_NE, // | | 409 | XC_LEX_OP_REL_NE, // | |
410 | BC_LEX_OP_REL_LT, // | | 410 | XC_LEX_OP_REL_LT, // | |
411 | BC_LEX_OP_REL_GT, // | | 411 | XC_LEX_OP_REL_GT, // | |
412 | 412 | ||
413 | BC_LEX_OP_BOOL_NOT, // | | 413 | BC_LEX_OP_BOOL_NOT, // | |
414 | BC_LEX_OP_BOOL_OR, // | | 414 | BC_LEX_OP_BOOL_OR, // | |
@@ -593,7 +593,7 @@ static ALWAYS_INLINE long bc_parse_exprs(unsigned i) | |||
593 | } | 593 | } |
594 | 594 | ||
595 | // This is an array of data for operators that correspond to | 595 | // This is an array of data for operators that correspond to |
596 | // [BC_LEX_1st_op...BC_LEX_last_op] token types. | 596 | // [XC_LEX_1st_op...] token types. |
597 | static const uint8_t bc_parse_ops[] = { | 597 | static const uint8_t bc_parse_ops[] = { |
598 | #define OP(p,l) ((int)(l) * 0x10 + (p)) | 598 | #define OP(p,l) ((int)(l) * 0x10 + (p)) |
599 | OP(1, false), // neg | 599 | OP(1, false), // neg |
@@ -617,18 +617,18 @@ static const //BcLexType - should be this type | |||
617 | uint8_t | 617 | uint8_t |
618 | dc_char_to_LEX[] = { | 618 | dc_char_to_LEX[] = { |
619 | /* %&'( */ | 619 | /* %&'( */ |
620 | BC_LEX_OP_MODULUS, XC_LEX_INVALID, XC_LEX_INVALID, BC_LEX_LPAREN, | 620 | XC_LEX_OP_MODULUS, XC_LEX_INVALID, XC_LEX_INVALID, BC_LEX_LPAREN, |
621 | /* )*+, */ | 621 | /* )*+, */ |
622 | XC_LEX_INVALID, BC_LEX_OP_MULTIPLY, BC_LEX_OP_PLUS, XC_LEX_INVALID, | 622 | XC_LEX_INVALID, XC_LEX_OP_MULTIPLY, XC_LEX_OP_PLUS, XC_LEX_INVALID, |
623 | /* -./ */ | 623 | /* -./ */ |
624 | BC_LEX_OP_MINUS, XC_LEX_INVALID, BC_LEX_OP_DIVIDE, | 624 | XC_LEX_OP_MINUS, XC_LEX_INVALID, XC_LEX_OP_DIVIDE, |
625 | /* 0123456789 */ | 625 | /* 0123456789 */ |
626 | XC_LEX_INVALID, XC_LEX_INVALID, XC_LEX_INVALID, XC_LEX_INVALID, | 626 | XC_LEX_INVALID, XC_LEX_INVALID, XC_LEX_INVALID, XC_LEX_INVALID, |
627 | XC_LEX_INVALID, XC_LEX_INVALID, XC_LEX_INVALID, XC_LEX_INVALID, | 627 | XC_LEX_INVALID, XC_LEX_INVALID, XC_LEX_INVALID, XC_LEX_INVALID, |
628 | XC_LEX_INVALID, XC_LEX_INVALID, | 628 | XC_LEX_INVALID, XC_LEX_INVALID, |
629 | /* :;<=>?@ */ | 629 | /* :;<=>?@ */ |
630 | DC_LEX_COLON, BC_LEX_SCOLON, BC_LEX_OP_REL_GT, BC_LEX_OP_REL_EQ, | 630 | DC_LEX_COLON, BC_LEX_SCOLON, XC_LEX_OP_REL_GT, XC_LEX_OP_REL_EQ, |
631 | BC_LEX_OP_REL_LT, BC_LEX_KEY_READ, XC_LEX_INVALID, | 631 | XC_LEX_OP_REL_LT, BC_LEX_KEY_READ, XC_LEX_INVALID, |
632 | /* ABCDEFGH */ | 632 | /* ABCDEFGH */ |
633 | XC_LEX_INVALID, XC_LEX_INVALID, XC_LEX_INVALID, XC_LEX_INVALID, | 633 | XC_LEX_INVALID, XC_LEX_INVALID, XC_LEX_INVALID, XC_LEX_INVALID, |
634 | XC_LEX_INVALID, XC_LEX_INVALID, DC_LEX_EQ_NO_REG, XC_LEX_INVALID, | 634 | XC_LEX_INVALID, XC_LEX_INVALID, DC_LEX_EQ_NO_REG, XC_LEX_INVALID, |
@@ -641,7 +641,7 @@ dc_char_to_LEX[] = { | |||
641 | /* Z[\] */ | 641 | /* Z[\] */ |
642 | BC_LEX_KEY_LENGTH, XC_LEX_INVALID, XC_LEX_INVALID, XC_LEX_INVALID, | 642 | BC_LEX_KEY_LENGTH, XC_LEX_INVALID, XC_LEX_INVALID, XC_LEX_INVALID, |
643 | /* ^_` */ | 643 | /* ^_` */ |
644 | BC_LEX_OP_POWER, BC_LEX_NEG, XC_LEX_INVALID, | 644 | XC_LEX_OP_POWER, XC_LEX_NEG, XC_LEX_INVALID, |
645 | /* abcdefgh */ | 645 | /* abcdefgh */ |
646 | DC_LEX_ASCIIFY, XC_LEX_INVALID, DC_LEX_CLEAR_STACK, DC_LEX_DUPLICATE, | 646 | DC_LEX_ASCIIFY, XC_LEX_INVALID, DC_LEX_CLEAR_STACK, DC_LEX_DUPLICATE, |
647 | DC_LEX_ELSE, DC_LEX_PRINT_STACK, XC_LEX_INVALID, XC_LEX_INVALID, | 647 | DC_LEX_ELSE, DC_LEX_PRINT_STACK, XC_LEX_INVALID, XC_LEX_INVALID, |
@@ -660,7 +660,8 @@ static const //BcInst - should be this type. Using signed narrow type since DC_I | |||
660 | int8_t | 660 | int8_t |
661 | dc_LEX_to_INST[] = { // (so many INVALIDs b/c dc parser does not generate these LEXs) // corresponding BC_LEX_xyz: | 661 | dc_LEX_to_INST[] = { // (so many INVALIDs b/c dc parser does not generate these LEXs) // corresponding BC_LEX_xyz: |
662 | DC_INST_INVALID, DC_INST_INVALID, // EOF INVALID | 662 | DC_INST_INVALID, DC_INST_INVALID, // EOF INVALID |
663 | DC_INST_INVALID, XC_INST_POWER, XC_INST_MULTIPLY, XC_INST_DIVIDE, // NEG OP_POWER OP_MULTIPLY OP_DIVIDE | 663 | DC_INST_INVALID, // NEG |
664 | XC_INST_POWER, XC_INST_MULTIPLY, XC_INST_DIVIDE, // OP_POWER OP_MULTIPLY OP_DIVIDE | ||
664 | XC_INST_MODULUS, XC_INST_PLUS, XC_INST_MINUS, // OP_MODULUS OP_PLUS OP_MINUS | 665 | XC_INST_MODULUS, XC_INST_PLUS, XC_INST_MINUS, // OP_MODULUS OP_PLUS OP_MINUS |
665 | DC_INST_INVALID, DC_INST_INVALID, DC_INST_INVALID, DC_INST_INVALID, // OP_REL_EQ OP_REL_LE OP_REL_GE OP_REL_NE | 666 | DC_INST_INVALID, DC_INST_INVALID, DC_INST_INVALID, DC_INST_INVALID, // OP_REL_EQ OP_REL_LE OP_REL_GE OP_REL_NE |
666 | DC_INST_INVALID, DC_INST_INVALID, // OP_REL_LT OP_REL_GT | 667 | DC_INST_INVALID, DC_INST_INVALID, // OP_REL_LT OP_REL_GT |
@@ -3159,7 +3160,7 @@ static BC_STATUS zbc_lex_token(BcLex *l) | |||
3159 | bc_lex_whitespace(l); | 3160 | bc_lex_whitespace(l); |
3160 | break; | 3161 | break; |
3161 | case '!': | 3162 | case '!': |
3162 | bc_lex_assign(l, BC_LEX_OP_REL_NE, BC_LEX_OP_BOOL_NOT); | 3163 | bc_lex_assign(l, XC_LEX_OP_REL_NE, BC_LEX_OP_BOOL_NOT); |
3163 | if (l->t.t == BC_LEX_OP_BOOL_NOT) { | 3164 | if (l->t.t == BC_LEX_OP_BOOL_NOT) { |
3164 | s = bc_POSIX_does_not_allow_bool_ops_this_is_bad("!"); | 3165 | s = bc_POSIX_does_not_allow_bool_ops_this_is_bad("!"); |
3165 | IF_ERROR_RETURN_POSSIBLE(if (s) RETURN_STATUS(s)); | 3166 | IF_ERROR_RETURN_POSSIBLE(if (s) RETURN_STATUS(s)); |
@@ -3174,7 +3175,7 @@ static BC_STATUS zbc_lex_token(BcLex *l) | |||
3174 | bc_lex_lineComment(l); | 3175 | bc_lex_lineComment(l); |
3175 | break; | 3176 | break; |
3176 | case '%': | 3177 | case '%': |
3177 | bc_lex_assign(l, BC_LEX_OP_ASSIGN_MODULUS, BC_LEX_OP_MODULUS); | 3178 | bc_lex_assign(l, BC_LEX_OP_ASSIGN_MODULUS, XC_LEX_OP_MODULUS); |
3178 | break; | 3179 | break; |
3179 | case '&': | 3180 | case '&': |
3180 | c2 = l->buf[l->i]; | 3181 | c2 = l->buf[l->i]; |
@@ -3193,7 +3194,7 @@ static BC_STATUS zbc_lex_token(BcLex *l) | |||
3193 | l->t.t = (BcLexType)(c - '(' + BC_LEX_LPAREN); | 3194 | l->t.t = (BcLexType)(c - '(' + BC_LEX_LPAREN); |
3194 | break; | 3195 | break; |
3195 | case '*': | 3196 | case '*': |
3196 | bc_lex_assign(l, BC_LEX_OP_ASSIGN_MULTIPLY, BC_LEX_OP_MULTIPLY); | 3197 | bc_lex_assign(l, BC_LEX_OP_ASSIGN_MULTIPLY, XC_LEX_OP_MULTIPLY); |
3197 | break; | 3198 | break; |
3198 | case '+': | 3199 | case '+': |
3199 | c2 = l->buf[l->i]; | 3200 | c2 = l->buf[l->i]; |
@@ -3201,7 +3202,7 @@ static BC_STATUS zbc_lex_token(BcLex *l) | |||
3201 | ++l->i; | 3202 | ++l->i; |
3202 | l->t.t = BC_LEX_OP_INC; | 3203 | l->t.t = BC_LEX_OP_INC; |
3203 | } else | 3204 | } else |
3204 | bc_lex_assign(l, BC_LEX_OP_ASSIGN_PLUS, BC_LEX_OP_PLUS); | 3205 | bc_lex_assign(l, BC_LEX_OP_ASSIGN_PLUS, XC_LEX_OP_PLUS); |
3205 | break; | 3206 | break; |
3206 | case ',': | 3207 | case ',': |
3207 | l->t.t = BC_LEX_COMMA; | 3208 | l->t.t = BC_LEX_COMMA; |
@@ -3212,7 +3213,7 @@ static BC_STATUS zbc_lex_token(BcLex *l) | |||
3212 | ++l->i; | 3213 | ++l->i; |
3213 | l->t.t = BC_LEX_OP_DEC; | 3214 | l->t.t = BC_LEX_OP_DEC; |
3214 | } else | 3215 | } else |
3215 | bc_lex_assign(l, BC_LEX_OP_ASSIGN_MINUS, BC_LEX_OP_MINUS); | 3216 | bc_lex_assign(l, BC_LEX_OP_ASSIGN_MINUS, XC_LEX_OP_MINUS); |
3216 | break; | 3217 | break; |
3217 | case '.': | 3218 | case '.': |
3218 | if (isdigit(l->buf[l->i])) | 3219 | if (isdigit(l->buf[l->i])) |
@@ -3227,7 +3228,7 @@ static BC_STATUS zbc_lex_token(BcLex *l) | |||
3227 | if (c2 == '*') | 3228 | if (c2 == '*') |
3228 | s = zbc_lex_comment(l); | 3229 | s = zbc_lex_comment(l); |
3229 | else | 3230 | else |
3230 | bc_lex_assign(l, BC_LEX_OP_ASSIGN_DIVIDE, BC_LEX_OP_DIVIDE); | 3231 | bc_lex_assign(l, BC_LEX_OP_ASSIGN_DIVIDE, XC_LEX_OP_DIVIDE); |
3231 | break; | 3232 | break; |
3232 | case '0': | 3233 | case '0': |
3233 | case '1': | 3234 | case '1': |
@@ -3251,13 +3252,13 @@ static BC_STATUS zbc_lex_token(BcLex *l) | |||
3251 | l->t.t = BC_LEX_SCOLON; | 3252 | l->t.t = BC_LEX_SCOLON; |
3252 | break; | 3253 | break; |
3253 | case '<': | 3254 | case '<': |
3254 | bc_lex_assign(l, BC_LEX_OP_REL_LE, BC_LEX_OP_REL_LT); | 3255 | bc_lex_assign(l, XC_LEX_OP_REL_LE, XC_LEX_OP_REL_LT); |
3255 | break; | 3256 | break; |
3256 | case '=': | 3257 | case '=': |
3257 | bc_lex_assign(l, BC_LEX_OP_REL_EQ, BC_LEX_OP_ASSIGN); | 3258 | bc_lex_assign(l, XC_LEX_OP_REL_EQ, BC_LEX_OP_ASSIGN); |
3258 | break; | 3259 | break; |
3259 | case '>': | 3260 | case '>': |
3260 | bc_lex_assign(l, BC_LEX_OP_REL_GE, BC_LEX_OP_REL_GT); | 3261 | bc_lex_assign(l, XC_LEX_OP_REL_GE, XC_LEX_OP_REL_GT); |
3261 | break; | 3262 | break; |
3262 | case '[': | 3263 | case '[': |
3263 | case ']': | 3264 | case ']': |
@@ -3271,7 +3272,7 @@ static BC_STATUS zbc_lex_token(BcLex *l) | |||
3271 | s = bc_error_bad_character(c); | 3272 | s = bc_error_bad_character(c); |
3272 | break; | 3273 | break; |
3273 | case '^': | 3274 | case '^': |
3274 | bc_lex_assign(l, BC_LEX_OP_ASSIGN_POWER, BC_LEX_OP_POWER); | 3275 | bc_lex_assign(l, BC_LEX_OP_ASSIGN_POWER, XC_LEX_OP_POWER); |
3275 | break; | 3276 | break; |
3276 | case 'a': | 3277 | case 'a': |
3277 | case 'b': | 3278 | case 'b': |
@@ -3395,8 +3396,8 @@ static BC_STATUS zdc_lex_token(BcLex *l) | |||
3395 | static const //BcLexType - should be this type, but narrower type saves size: | 3396 | static const //BcLexType - should be this type, but narrower type saves size: |
3396 | uint8_t | 3397 | uint8_t |
3397 | dc_lex_regs[] = { | 3398 | dc_lex_regs[] = { |
3398 | BC_LEX_OP_REL_EQ, BC_LEX_OP_REL_LE, BC_LEX_OP_REL_GE, BC_LEX_OP_REL_NE, | 3399 | XC_LEX_OP_REL_EQ, XC_LEX_OP_REL_LE, XC_LEX_OP_REL_GE, XC_LEX_OP_REL_NE, |
3399 | BC_LEX_OP_REL_LT, BC_LEX_OP_REL_GT, BC_LEX_SCOLON, DC_LEX_COLON, | 3400 | XC_LEX_OP_REL_LT, XC_LEX_OP_REL_GT, BC_LEX_SCOLON, DC_LEX_COLON, |
3400 | DC_LEX_ELSE, DC_LEX_LOAD, DC_LEX_LOAD_POP, BC_LEX_OP_ASSIGN, | 3401 | DC_LEX_ELSE, DC_LEX_LOAD, DC_LEX_LOAD_POP, BC_LEX_OP_ASSIGN, |
3401 | DC_LEX_STORE_PUSH, | 3402 | DC_LEX_STORE_PUSH, |
3402 | }; | 3403 | }; |
@@ -3446,11 +3447,11 @@ static BC_STATUS zdc_lex_token(BcLex *l) | |||
3446 | case '!': | 3447 | case '!': |
3447 | c2 = l->buf[l->i]; | 3448 | c2 = l->buf[l->i]; |
3448 | if (c2 == '=') | 3449 | if (c2 == '=') |
3449 | l->t.t = BC_LEX_OP_REL_NE; | 3450 | l->t.t = XC_LEX_OP_REL_NE; |
3450 | else if (c2 == '<') | 3451 | else if (c2 == '<') |
3451 | l->t.t = BC_LEX_OP_REL_LE; | 3452 | l->t.t = XC_LEX_OP_REL_LE; |
3452 | else if (c2 == '>') | 3453 | else if (c2 == '>') |
3453 | l->t.t = BC_LEX_OP_REL_GE; | 3454 | l->t.t = XC_LEX_OP_REL_GE; |
3454 | else | 3455 | else |
3455 | RETURN_STATUS(bc_error_bad_character(c)); | 3456 | RETURN_STATUS(bc_error_bad_character(c)); |
3456 | ++l->i; | 3457 | ++l->i; |
@@ -3686,7 +3687,7 @@ static size_t bc_program_addFunc(char *name) | |||
3686 | // We can calculate the conversion between tokens and exprs by subtracting the | 3687 | // We can calculate the conversion between tokens and exprs by subtracting the |
3687 | // position of the first operator in the lex enum and adding the position of the | 3688 | // position of the first operator in the lex enum and adding the position of the |
3688 | // first in the expr enum. Note: This only works for binary operators. | 3689 | // first in the expr enum. Note: This only works for binary operators. |
3689 | #define BC_TOKEN_2_INST(t) ((char) ((t) - BC_LEX_OP_POWER + XC_INST_POWER)) | 3690 | #define BC_TOKEN_2_INST(t) ((char) ((t) - XC_LEX_OP_POWER + XC_INST_POWER)) |
3690 | 3691 | ||
3691 | static BcStatus bc_parse_expr_empty_ok(BcParse *p, uint8_t flags); | 3692 | static BcStatus bc_parse_expr_empty_ok(BcParse *p, uint8_t flags); |
3692 | 3693 | ||
@@ -3726,19 +3727,19 @@ static BC_STATUS zbc_parse_stmt_allow_NLINE_before(BcParse *p, const char *after | |||
3726 | static void bc_parse_operator(BcParse *p, BcLexType type, size_t start, | 3727 | static void bc_parse_operator(BcParse *p, BcLexType type, size_t start, |
3727 | size_t *nexprs) | 3728 | size_t *nexprs) |
3728 | { | 3729 | { |
3729 | char l, r = bc_parse_op_PREC(type - BC_LEX_1st_op); | 3730 | char l, r = bc_parse_op_PREC(type - XC_LEX_1st_op); |
3730 | bool left = bc_parse_op_LEFT(type - BC_LEX_1st_op); | 3731 | bool left = bc_parse_op_LEFT(type - XC_LEX_1st_op); |
3731 | 3732 | ||
3732 | while (p->ops.len > start) { | 3733 | while (p->ops.len > start) { |
3733 | BcLexType t = BC_PARSE_TOP_OP(p); | 3734 | BcLexType t = BC_PARSE_TOP_OP(p); |
3734 | if (t == BC_LEX_LPAREN) break; | 3735 | if (t == BC_LEX_LPAREN) break; |
3735 | 3736 | ||
3736 | l = bc_parse_op_PREC(t - BC_LEX_1st_op); | 3737 | l = bc_parse_op_PREC(t - XC_LEX_1st_op); |
3737 | if (l >= r && (l != r || !left)) break; | 3738 | if (l >= r && (l != r || !left)) break; |
3738 | 3739 | ||
3739 | bc_parse_push(p, BC_TOKEN_2_INST(t)); | 3740 | bc_parse_push(p, BC_TOKEN_2_INST(t)); |
3740 | bc_vec_pop(&p->ops); | 3741 | bc_vec_pop(&p->ops); |
3741 | *nexprs -= (t != BC_LEX_OP_BOOL_NOT && t != BC_LEX_NEG); | 3742 | *nexprs -= (t != BC_LEX_OP_BOOL_NOT && t != XC_LEX_NEG); |
3742 | } | 3743 | } |
3743 | 3744 | ||
3744 | bc_vec_push(&p->ops, &type); | 3745 | bc_vec_push(&p->ops, &type); |
@@ -3756,7 +3757,7 @@ static BC_STATUS zbc_parse_rightParen(BcParse *p, size_t ops_bgn, size_t *nexs) | |||
3756 | bc_parse_push(p, BC_TOKEN_2_INST(top)); | 3757 | bc_parse_push(p, BC_TOKEN_2_INST(top)); |
3757 | 3758 | ||
3758 | bc_vec_pop(&p->ops); | 3759 | bc_vec_pop(&p->ops); |
3759 | *nexs -= (top != BC_LEX_OP_BOOL_NOT && top != BC_LEX_NEG); | 3760 | *nexs -= (top != BC_LEX_OP_BOOL_NOT && top != XC_LEX_NEG); |
3760 | 3761 | ||
3761 | if (p->ops.len <= ops_bgn) | 3762 | if (p->ops.len <= ops_bgn) |
3762 | RETURN_STATUS(bc_error_bad_expression()); | 3763 | RETURN_STATUS(bc_error_bad_expression()); |
@@ -4032,13 +4033,13 @@ static BC_STATUS zbc_parse_minus(BcParse *p, BcInst *prev, size_t ops_bgn, | |||
4032 | 4033 | ||
4033 | type = rparen || etype == BC_INST_INC_POST || etype == BC_INST_DEC_POST || | 4034 | type = rparen || etype == BC_INST_INC_POST || etype == BC_INST_DEC_POST || |
4034 | (etype >= XC_INST_NUM && etype <= XC_INST_SQRT) ? | 4035 | (etype >= XC_INST_NUM && etype <= XC_INST_SQRT) ? |
4035 | BC_LEX_OP_MINUS : | 4036 | XC_LEX_OP_MINUS : |
4036 | BC_LEX_NEG; | 4037 | XC_LEX_NEG; |
4037 | *prev = BC_TOKEN_2_INST(type); | 4038 | *prev = BC_TOKEN_2_INST(type); |
4038 | 4039 | ||
4039 | // We can just push onto the op stack because this is the largest | 4040 | // We can just push onto the op stack because this is the largest |
4040 | // precedence operator that gets pushed. Inc/dec does not. | 4041 | // precedence operator that gets pushed. Inc/dec does not. |
4041 | if (type != BC_LEX_OP_MINUS) | 4042 | if (type != XC_LEX_OP_MINUS) |
4042 | bc_vec_push(&p->ops, &type); | 4043 | bc_vec_push(&p->ops, &type); |
4043 | else | 4044 | else |
4044 | bc_parse_operator(p, type, ops_bgn, nexprs); | 4045 | bc_parse_operator(p, type, ops_bgn, nexprs); |
@@ -4523,9 +4524,9 @@ static BC_STATUS zbc_parse_stmt_possibly_auto(BcParse *p, bool auto_allowed) | |||
4523 | 4524 | ||
4524 | dbg_lex("%s:%d p->l.t.t:%d", __func__, __LINE__, p->l.t.t); | 4525 | dbg_lex("%s:%d p->l.t.t:%d", __func__, __LINE__, p->l.t.t); |
4525 | switch (p->l.t.t) { | 4526 | switch (p->l.t.t) { |
4527 | case XC_LEX_OP_MINUS: | ||
4526 | case BC_LEX_OP_INC: | 4528 | case BC_LEX_OP_INC: |
4527 | case BC_LEX_OP_DEC: | 4529 | case BC_LEX_OP_DEC: |
4528 | case BC_LEX_OP_MINUS: | ||
4529 | case BC_LEX_OP_BOOL_NOT: | 4530 | case BC_LEX_OP_BOOL_NOT: |
4530 | case BC_LEX_LPAREN: | 4531 | case BC_LEX_LPAREN: |
4531 | case BC_LEX_NAME: | 4532 | case BC_LEX_NAME: |
@@ -4642,7 +4643,7 @@ static BcStatus bc_parse_expr_empty_ok(BcParse *p, uint8_t flags) | |||
4642 | s = zbc_parse_incdec(p, &prev, &paren_expr, &nexprs, flags); | 4643 | s = zbc_parse_incdec(p, &prev, &paren_expr, &nexprs, flags); |
4643 | rprn = get_token = bin_last = false; | 4644 | rprn = get_token = bin_last = false; |
4644 | break; | 4645 | break; |
4645 | case BC_LEX_OP_MINUS: | 4646 | case XC_LEX_OP_MINUS: |
4646 | s = zbc_parse_minus(p, &prev, ops_bgn, rprn, &nexprs); | 4647 | s = zbc_parse_minus(p, &prev, ops_bgn, rprn, &nexprs); |
4647 | rprn = get_token = false; | 4648 | rprn = get_token = false; |
4648 | bin_last = prev == XC_INST_MINUS; | 4649 | bin_last = prev == XC_INST_MINUS; |
@@ -4665,17 +4666,17 @@ static BcStatus bc_parse_expr_empty_ok(BcParse *p, uint8_t flags) | |||
4665 | break; | 4666 | break; |
4666 | } | 4667 | } |
4667 | // Fallthrough. | 4668 | // Fallthrough. |
4668 | case BC_LEX_OP_POWER: | 4669 | case XC_LEX_OP_POWER: |
4669 | case BC_LEX_OP_MULTIPLY: | 4670 | case XC_LEX_OP_MULTIPLY: |
4670 | case BC_LEX_OP_DIVIDE: | 4671 | case XC_LEX_OP_DIVIDE: |
4671 | case BC_LEX_OP_MODULUS: | 4672 | case XC_LEX_OP_MODULUS: |
4672 | case BC_LEX_OP_PLUS: | 4673 | case XC_LEX_OP_PLUS: |
4673 | case BC_LEX_OP_REL_EQ: | 4674 | case XC_LEX_OP_REL_EQ: |
4674 | case BC_LEX_OP_REL_LE: | 4675 | case XC_LEX_OP_REL_LE: |
4675 | case BC_LEX_OP_REL_GE: | 4676 | case XC_LEX_OP_REL_GE: |
4676 | case BC_LEX_OP_REL_NE: | 4677 | case XC_LEX_OP_REL_NE: |
4677 | case BC_LEX_OP_REL_LT: | 4678 | case XC_LEX_OP_REL_LT: |
4678 | case BC_LEX_OP_REL_GT: | 4679 | case XC_LEX_OP_REL_GT: |
4679 | case BC_LEX_OP_BOOL_NOT: | 4680 | case BC_LEX_OP_BOOL_NOT: |
4680 | case BC_LEX_OP_BOOL_OR: | 4681 | case BC_LEX_OP_BOOL_OR: |
4681 | case BC_LEX_OP_BOOL_AND: | 4682 | case BC_LEX_OP_BOOL_AND: |
@@ -4684,12 +4685,12 @@ static BcStatus bc_parse_expr_empty_ok(BcParse *p, uint8_t flags) | |||
4684 | ) { | 4685 | ) { |
4685 | return bc_error_bad_expression(); | 4686 | return bc_error_bad_expression(); |
4686 | } | 4687 | } |
4687 | nrelops += t >= BC_LEX_OP_REL_EQ && t <= BC_LEX_OP_REL_GT; | 4688 | nrelops += (t >= XC_LEX_OP_REL_EQ && t <= XC_LEX_OP_REL_GT); |
4688 | prev = BC_TOKEN_2_INST(t); | 4689 | prev = BC_TOKEN_2_INST(t); |
4689 | bc_parse_operator(p, t, ops_bgn, &nexprs); | 4690 | bc_parse_operator(p, t, ops_bgn, &nexprs); |
4690 | s = zbc_lex_next(&p->l); | 4691 | s = zbc_lex_next(&p->l); |
4691 | rprn = get_token = false; | 4692 | rprn = get_token = false; |
4692 | bin_last = t != BC_LEX_OP_BOOL_NOT; | 4693 | bin_last = (t != BC_LEX_OP_BOOL_NOT); |
4693 | break; | 4694 | break; |
4694 | case BC_LEX_LPAREN: | 4695 | case BC_LEX_LPAREN: |
4695 | if (BC_PARSE_LEAF(prev, rprn)) | 4696 | if (BC_PARSE_LEAF(prev, rprn)) |
@@ -4793,7 +4794,7 @@ static BcStatus bc_parse_expr_empty_ok(BcParse *p, uint8_t flags) | |||
4793 | 4794 | ||
4794 | bc_parse_push(p, BC_TOKEN_2_INST(top)); | 4795 | bc_parse_push(p, BC_TOKEN_2_INST(top)); |
4795 | 4796 | ||
4796 | nexprs -= (top != BC_LEX_OP_BOOL_NOT && top != BC_LEX_NEG); | 4797 | nexprs -= (top != BC_LEX_OP_BOOL_NOT && top != XC_LEX_NEG); |
4797 | bc_vec_pop(&p->ops); | 4798 | bc_vec_pop(&p->ops); |
4798 | } | 4799 | } |
4799 | 4800 | ||
@@ -4912,14 +4913,14 @@ static BC_STATUS zdc_parse_token(BcParse *p, BcLexType t) | |||
4912 | s = BC_STATUS_SUCCESS; | 4913 | s = BC_STATUS_SUCCESS; |
4913 | get_token = true; | 4914 | get_token = true; |
4914 | switch (t) { | 4915 | switch (t) { |
4915 | case BC_LEX_OP_REL_EQ: | 4916 | case XC_LEX_OP_REL_EQ: |
4916 | case BC_LEX_OP_REL_LE: | 4917 | case XC_LEX_OP_REL_LE: |
4917 | case BC_LEX_OP_REL_GE: | 4918 | case XC_LEX_OP_REL_GE: |
4918 | case BC_LEX_OP_REL_NE: | 4919 | case XC_LEX_OP_REL_NE: |
4919 | case BC_LEX_OP_REL_LT: | 4920 | case XC_LEX_OP_REL_LT: |
4920 | case BC_LEX_OP_REL_GT: | 4921 | case XC_LEX_OP_REL_GT: |
4921 | dbg_lex("%s:%d LEX_OP_REL_xyz", __func__, __LINE__); | 4922 | dbg_lex("%s:%d LEX_OP_REL_xyz", __func__, __LINE__); |
4922 | s = zdc_parse_cond(p, t - BC_LEX_OP_REL_EQ + XC_INST_REL_EQ); | 4923 | s = zdc_parse_cond(p, t - XC_LEX_OP_REL_EQ + XC_INST_REL_EQ); |
4923 | get_token = false; | 4924 | get_token = false; |
4924 | break; | 4925 | break; |
4925 | case BC_LEX_SCOLON: | 4926 | case BC_LEX_SCOLON: |
@@ -4931,7 +4932,7 @@ static BC_STATUS zdc_parse_token(BcParse *p, BcLexType t) | |||
4931 | dbg_lex("%s:%d LEX_STR", __func__, __LINE__); | 4932 | dbg_lex("%s:%d LEX_STR", __func__, __LINE__); |
4932 | dc_parse_string(p); | 4933 | dc_parse_string(p); |
4933 | break; | 4934 | break; |
4934 | case BC_LEX_NEG: | 4935 | case XC_LEX_NEG: |
4935 | dbg_lex("%s:%d LEX_NEG", __func__, __LINE__); | 4936 | dbg_lex("%s:%d LEX_NEG", __func__, __LINE__); |
4936 | s = zbc_lex_next(&p->l); | 4937 | s = zbc_lex_next(&p->l); |
4937 | if (s) RETURN_STATUS(s); | 4938 | if (s) RETURN_STATUS(s); |