diff options
Diffstat (limited to 'miscutils')
-rw-r--r-- | miscutils/bc.c | 79 |
1 files changed, 42 insertions, 37 deletions
diff --git a/miscutils/bc.c b/miscutils/bc.c index d2b74ea90..8556a0e73 100644 --- a/miscutils/bc.c +++ b/miscutils/bc.c | |||
@@ -673,34 +673,39 @@ dc_char_to_LEX[] = { | |||
673 | }; | 673 | }; |
674 | static const //BcInst - should be this type. Using signed narrow type since DC_INST_INVALID is -1 | 674 | static const //BcInst - should be this type. Using signed narrow type since DC_INST_INVALID is -1 |
675 | int8_t | 675 | int8_t |
676 | dc_LEX_to_INST[] = { // (so many INVALIDs b/c dc parser does not generate these LEXs) // corresponding XC/DC_LEX_xyz: | 676 | dc_LEX_to_INST[] = { // starts at XC_LEX_OP_POWER // corresponding XC/DC_LEX_xyz: |
677 | DC_INST_INVALID, DC_INST_INVALID, // EOF INVALID | 677 | XC_INST_POWER, XC_INST_MULTIPLY, // OP_POWER OP_MULTIPLY |
678 | DC_INST_INVALID, DC_INST_INVALID, // NLINE WHITESPACE | 678 | XC_INST_DIVIDE, XC_INST_MODULUS, // OP_DIVIDE OP_MODULUS |
679 | DC_INST_INVALID, DC_INST_INVALID, DC_INST_INVALID, // STR NAME NUMBER | 679 | XC_INST_PLUS, XC_INST_MINUS, // OP_PLUS OP_MINUS |
680 | DC_INST_INVALID, // NEG | 680 | DC_INST_INVALID, DC_INST_INVALID, // OP_REL_EQ OP_REL_LE |
681 | XC_INST_POWER, XC_INST_MULTIPLY, XC_INST_DIVIDE, // OP_POWER OP_MULTIPLY OP_DIVIDE | 681 | DC_INST_INVALID, DC_INST_INVALID, // OP_REL_GE OP_REL_NE |
682 | XC_INST_MODULUS, XC_INST_PLUS, XC_INST_MINUS, // OP_MODULUS OP_PLUS OP_MINUS | 682 | DC_INST_INVALID, DC_INST_INVALID, // OP_REL_LT OP_REL_GT |
683 | DC_INST_INVALID, DC_INST_INVALID, DC_INST_INVALID, DC_INST_INVALID, // OP_REL_EQ OP_REL_LE OP_REL_GE OP_REL_NE | 683 | XC_INST_BOOL_NOT, // DC_LEX_OP_BOOL_NOT |
684 | DC_INST_INVALID, DC_INST_INVALID, // OP_REL_LT OP_REL_GT | 684 | DC_INST_INVALID, // DC_LEX_OP_ASSIGN |
685 | XC_INST_BOOL_NOT, // DC_LEX_OP_BOOL_NOT | 685 | XC_INST_REL_GT, // DC_LEX_LPAREN |
686 | DC_INST_INVALID, // DC_LEX_OP_ASSIGN | 686 | DC_INST_INVALID, // DC_LEX_SCOLON |
687 | XC_INST_REL_GT, // DC_LEX_LPAREN | 687 | DC_INST_INVALID, // DC_LEX_READ |
688 | DC_INST_INVALID, // DC_LEX_SCOLON | 688 | XC_INST_IBASE, // DC_LEX_IBASE |
689 | DC_INST_INVALID, // DC_LEX_READ | 689 | XC_INST_SCALE, // DC_LEX_SCALE |
690 | XC_INST_IBASE, // DC_LEX_IBASE | 690 | XC_INST_OBASE, // DC_LEX_OBASE |
691 | XC_INST_SCALE, // DC_LEX_SCALE | 691 | XC_INST_LENGTH, // DC_LEX_LENGTH |
692 | XC_INST_OBASE, // DC_LEX_OBASE | 692 | XC_INST_PRINT, // DC_LEX_PRINT |
693 | XC_INST_LENGTH, // DC_LEX_LENGTH | 693 | DC_INST_QUIT, // DC_LEX_QUIT |
694 | XC_INST_PRINT, // DC_LEX_PRINT | 694 | XC_INST_SQRT, // DC_LEX_SQRT |
695 | DC_INST_QUIT, // DC_LEX_QUIT | 695 | XC_INST_REL_GE, // DC_LEX_LBRACE |
696 | XC_INST_SQRT, // DC_LEX_SQRT | 696 | XC_INST_REL_EQ, // DC_LEX_EQ_NO_REG |
697 | XC_INST_REL_GE, // DC_LEX_LBRACE | 697 | DC_INST_MODEXP, DC_INST_DIVMOD, // OP_MODEXP OP_DIVMOD |
698 | XC_INST_REL_EQ, DC_INST_MODEXP, DC_INST_DIVMOD, DC_INST_INVALID, // EQ_NO_REG OP_MODEXP OP_DIVMOD COLON | 698 | DC_INST_INVALID, DC_INST_INVALID, // COLON ELSE |
699 | DC_INST_INVALID, DC_INST_EXECUTE, DC_INST_PRINT_STACK, DC_INST_CLEAR_STACK, //ELSE EXECUTE PRINT_STACK CLEAR_STACK | 699 | DC_INST_EXECUTE, // EXECUTE |
700 | DC_INST_STACK_LEN, DC_INST_DUPLICATE, DC_INST_SWAP, XC_INST_POP, // STACK_LEVEL DUPLICATE SWAP POP | 700 | DC_INST_PRINT_STACK, DC_INST_CLEAR_STACK, // PRINT_STACK CLEAR_STACK |
701 | DC_INST_ASCIIFY, DC_INST_PRINT_STREAM, DC_INST_INVALID, DC_INST_INVALID, //ASCIIFY PRINT_STREAM STORE_IBASE STORE_OBASE | 701 | DC_INST_STACK_LEN, DC_INST_DUPLICATE, // STACK_LEVEL DUPLICATE |
702 | DC_INST_INVALID, DC_INST_INVALID, DC_INST_INVALID, DC_INST_INVALID, // STORE_SCALE LOAD LOAD_POP STORE_PUSH | 702 | DC_INST_SWAP, XC_INST_POP, // SWAP POP |
703 | XC_INST_PRINT, DC_INST_NQUIT, XC_INST_SCALE_FUNC, // PRINT_POP NQUIT SCALE_FACTOR | 703 | DC_INST_ASCIIFY, DC_INST_PRINT_STREAM, // ASCIIFY PRINT_STREAM |
704 | DC_INST_INVALID, DC_INST_INVALID, // STORE_IBASE STORE_OBASE | ||
705 | DC_INST_INVALID, DC_INST_INVALID, // STORE_SCALE LOAD | ||
706 | DC_INST_INVALID, DC_INST_INVALID, // LOAD_POP STORE_PUSH | ||
707 | XC_INST_PRINT, DC_INST_NQUIT, // PRINT_POP NQUIT | ||
708 | XC_INST_SCALE_FUNC, // SCALE_FACTOR | ||
704 | // DC_INST_INVALID in this table either means that corresponding LEX | 709 | // DC_INST_INVALID in this table either means that corresponding LEX |
705 | // is not possible for dc, or that it does not compile one-to-one | 710 | // is not possible for dc, or that it does not compile one-to-one |
706 | // to a single INST. | 711 | // to a single INST. |
@@ -5003,17 +5008,17 @@ static BC_STATUS zdc_parse_token(BcParse *p, BcLexType t) | |||
5003 | 5008 | ||
5004 | static BC_STATUS zdc_parse_expr(BcParse *p) | 5009 | static BC_STATUS zdc_parse_expr(BcParse *p) |
5005 | { | 5010 | { |
5006 | BcInst inst; | 5011 | int i; |
5007 | BcStatus s; | ||
5008 | 5012 | ||
5009 | inst = dc_LEX_to_INST[p->l.t.t]; | 5013 | i = (int)p->l.t.t - (int)XC_LEX_OP_POWER; |
5010 | if (inst != DC_INST_INVALID) { | 5014 | if (i >= 0) { |
5011 | bc_parse_push(p, inst); | 5015 | BcInst inst = dc_LEX_to_INST[i]; |
5012 | s = zbc_lex_next(&p->l); | 5016 | if (inst != DC_INST_INVALID) { |
5013 | } else { | 5017 | bc_parse_push(p, inst); |
5014 | s = zdc_parse_token(p, p->l.t.t); | 5018 | RETURN_STATUS(zbc_lex_next(&p->l)); |
5019 | } | ||
5015 | } | 5020 | } |
5016 | RETURN_STATUS(s); | 5021 | RETURN_STATUS(zdc_parse_token(p, p->l.t.t)); |
5017 | } | 5022 | } |
5018 | #define zdc_parse_expr(...) (zdc_parse_expr(__VA_ARGS__) COMMA_SUCCESS) | 5023 | #define zdc_parse_expr(...) (zdc_parse_expr(__VA_ARGS__) COMMA_SUCCESS) |
5019 | 5024 | ||