diff options
-rw-r--r-- | miscutils/bc.c | 90 |
1 files changed, 45 insertions, 45 deletions
diff --git a/miscutils/bc.c b/miscutils/bc.c index 85eeb6743..d2583313c 100644 --- a/miscutils/bc.c +++ b/miscutils/bc.c @@ -572,7 +572,7 @@ enum { + (EXBITS(1,1,1,0,0,1,1,0) << (3*8)) // 24: += -= = NL WS ( ) [ + (EXBITS(0,0,0,0,0,0,1,1) << (4*8)) // 32: , ] { ; } STR NAME NUM + (EXBITS(0,0,0,0,0,0,0,1) << (5*8)) // 40: auto break cont define else for halt ibase - + (EXBITS(1,0,1,1,1,0,0,1) << (6*8)) // 48: obase if last len limits print quit read - bug, why "limits" is allowed? + + (EXBITS(1,0,1,1,0,0,0,1) << (6*8)) // 48: obase if last length limits print quit read + (EXBITS(0,1,1,0,0,0,0,0) << (7*8)) // 56: return scale sqrt while #undef EXBITS }; @@ -613,6 +613,49 @@ static const uint8_t bc_parse_ops[] = { #endif // ENABLE_BC #if ENABLE_DC +static const //BcLexType - should be this type +uint8_t +dc_char_to_LEX[] = { + /* %&'( */ + BC_LEX_OP_MODULUS, BC_LEX_INVALID, BC_LEX_INVALID, BC_LEX_LPAREN, + /* )*+, */ + BC_LEX_INVALID, BC_LEX_OP_MULTIPLY, BC_LEX_OP_PLUS, BC_LEX_INVALID, + /* -./ */ + BC_LEX_OP_MINUS, BC_LEX_INVALID, BC_LEX_OP_DIVIDE, + /* 0123456789 */ + BC_LEX_INVALID, BC_LEX_INVALID, BC_LEX_INVALID, BC_LEX_INVALID, + BC_LEX_INVALID, BC_LEX_INVALID, BC_LEX_INVALID, BC_LEX_INVALID, + BC_LEX_INVALID, BC_LEX_INVALID, + /* :;<=>?@ */ + BC_LEX_COLON, BC_LEX_SCOLON, BC_LEX_OP_REL_GT, BC_LEX_OP_REL_EQ, + BC_LEX_OP_REL_LT, BC_LEX_KEY_READ, BC_LEX_INVALID, + /* ABCDEFGH */ + BC_LEX_INVALID, BC_LEX_INVALID, BC_LEX_INVALID, BC_LEX_INVALID, + BC_LEX_INVALID, BC_LEX_INVALID, BC_LEX_EQ_NO_REG, BC_LEX_INVALID, + /* IJKLMNOP */ + BC_LEX_KEY_IBASE, BC_LEX_INVALID, BC_LEX_KEY_SCALE, BC_LEX_LOAD_POP, + BC_LEX_INVALID, BC_LEX_OP_BOOL_NOT, BC_LEX_KEY_OBASE, BC_LEX_PRINT_STREAM, + /* QRSTUVWXY */ + BC_LEX_NQUIT, BC_LEX_POP, BC_LEX_STORE_PUSH, BC_LEX_INVALID, BC_LEX_INVALID, + BC_LEX_INVALID, BC_LEX_INVALID, BC_LEX_SCALE_FACTOR, BC_LEX_INVALID, + /* Z[\] */ + BC_LEX_KEY_LENGTH, BC_LEX_INVALID, BC_LEX_INVALID, BC_LEX_INVALID, + /* ^_` */ + BC_LEX_OP_POWER, BC_LEX_NEG, BC_LEX_INVALID, + /* abcdefgh */ + BC_LEX_ASCIIFY, BC_LEX_INVALID, BC_LEX_CLEAR_STACK, BC_LEX_DUPLICATE, + BC_LEX_ELSE, BC_LEX_PRINT_STACK, BC_LEX_INVALID, BC_LEX_INVALID, + /* ijklmnop */ + BC_LEX_STORE_IBASE, BC_LEX_INVALID, BC_LEX_STORE_SCALE, BC_LEX_LOAD, + BC_LEX_INVALID, BC_LEX_PRINT_POP, BC_LEX_STORE_OBASE, BC_LEX_KEY_PRINT, + /* qrstuvwx */ + BC_LEX_KEY_QUIT, BC_LEX_SWAP, BC_LEX_OP_ASSIGN, BC_LEX_INVALID, + BC_LEX_INVALID, BC_LEX_KEY_SQRT, BC_LEX_INVALID, BC_LEX_EXECUTE, + /* yz */ + BC_LEX_INVALID, BC_LEX_STACK_LEVEL, + /* {|}~ */ + BC_LEX_LBRACE, BC_LEX_OP_MODEXP, BC_LEX_INVALID, BC_LEX_OP_DIVMOD, +}; static const //BcInst - should be this type. Using signed narrow type since BC_INST_INVALID is -1 int8_t dc_LEX_to_INST[] = { // (so many INVALIDs b/c dc parser does not generate these LEXs) // corresponding BC_LEX_xyz: @@ -3381,49 +3424,6 @@ static BC_STATUS zdc_lex_token(BcLex *l) BC_LEX_ELSE, BC_LEX_LOAD, BC_LEX_LOAD_POP, BC_LEX_OP_ASSIGN, BC_LEX_STORE_PUSH, }; - static const //BcLexType - should be this type - uint8_t - dc_lex_tokens[] = { - /* %&'( */ - BC_LEX_OP_MODULUS, BC_LEX_INVALID, BC_LEX_INVALID, BC_LEX_LPAREN, - /* )*+, */ - BC_LEX_INVALID, BC_LEX_OP_MULTIPLY, BC_LEX_OP_PLUS, BC_LEX_INVALID, - /* -./ */ - BC_LEX_OP_MINUS, BC_LEX_INVALID, BC_LEX_OP_DIVIDE, - /* 0123456789 */ - BC_LEX_INVALID, BC_LEX_INVALID, BC_LEX_INVALID, BC_LEX_INVALID, - BC_LEX_INVALID, BC_LEX_INVALID, BC_LEX_INVALID, BC_LEX_INVALID, - BC_LEX_INVALID, BC_LEX_INVALID, - /* :;<=>?@ */ - BC_LEX_COLON, BC_LEX_SCOLON, BC_LEX_OP_REL_GT, BC_LEX_OP_REL_EQ, - BC_LEX_OP_REL_LT, BC_LEX_KEY_READ, BC_LEX_INVALID, - /* ABCDEFGH */ - BC_LEX_INVALID, BC_LEX_INVALID, BC_LEX_INVALID, BC_LEX_INVALID, - BC_LEX_INVALID, BC_LEX_INVALID, BC_LEX_EQ_NO_REG, BC_LEX_INVALID, - /* IJKLMNOP */ - BC_LEX_KEY_IBASE, BC_LEX_INVALID, BC_LEX_KEY_SCALE, BC_LEX_LOAD_POP, - BC_LEX_INVALID, BC_LEX_OP_BOOL_NOT, BC_LEX_KEY_OBASE, BC_LEX_PRINT_STREAM, - /* QRSTUVWXY */ - BC_LEX_NQUIT, BC_LEX_POP, BC_LEX_STORE_PUSH, BC_LEX_INVALID, BC_LEX_INVALID, - BC_LEX_INVALID, BC_LEX_INVALID, BC_LEX_SCALE_FACTOR, BC_LEX_INVALID, - /* Z[\] */ - BC_LEX_KEY_LENGTH, BC_LEX_INVALID, BC_LEX_INVALID, BC_LEX_INVALID, - /* ^_` */ - BC_LEX_OP_POWER, BC_LEX_NEG, BC_LEX_INVALID, - /* abcdefgh */ - BC_LEX_ASCIIFY, BC_LEX_INVALID, BC_LEX_CLEAR_STACK, BC_LEX_DUPLICATE, - BC_LEX_ELSE, BC_LEX_PRINT_STACK, BC_LEX_INVALID, BC_LEX_INVALID, - /* ijklmnop */ - BC_LEX_STORE_IBASE, BC_LEX_INVALID, BC_LEX_STORE_SCALE, BC_LEX_LOAD, - BC_LEX_INVALID, BC_LEX_PRINT_POP, BC_LEX_STORE_OBASE, BC_LEX_KEY_PRINT, - /* qrstuvwx */ - BC_LEX_KEY_QUIT, BC_LEX_SWAP, BC_LEX_OP_ASSIGN, BC_LEX_INVALID, - BC_LEX_INVALID, BC_LEX_KEY_SQRT, BC_LEX_INVALID, BC_LEX_EXECUTE, - /* yz */ - BC_LEX_INVALID, BC_LEX_STACK_LEVEL, - /* {|}~ */ - BC_LEX_LBRACE, BC_LEX_OP_MODEXP, BC_LEX_INVALID, BC_LEX_OP_DIVMOD, - }; BcStatus s = BC_STATUS_SUCCESS; char c = l->buf[l->i++], c2; @@ -3435,7 +3435,7 @@ static BC_STATUS zdc_lex_token(BcLex *l) } if (c >= '%' && c <= '~' - && (l->t.t = dc_lex_tokens[c - '%']) != BC_LEX_INVALID + && (l->t.t = dc_char_to_LEX[c - '%']) != BC_LEX_INVALID ) { RETURN_STATUS(s); } |