Gavin Howard | 5715b04 | 2018-02-12 16:11:42 -0700 | [diff] [blame] | 1 | /* |
Gavin Howard | b5904bf | 2018-02-20 13:28:18 -0700 | [diff] [blame] | 2 | * ***************************************************************************** |
Gavin Howard | 5715b04 | 2018-02-12 16:11:42 -0700 | [diff] [blame] | 3 | * |
Gavin Howard | b5904bf | 2018-02-20 13:28:18 -0700 | [diff] [blame] | 4 | * Copyright 2018 Gavin D. Howard |
Gavin Howard | 5715b04 | 2018-02-12 16:11:42 -0700 | [diff] [blame] | 5 | * |
| 6 | * Permission to use, copy, modify, and/or distribute this software for any |
| 7 | * purpose with or without fee is hereby granted. |
| 8 | * |
| 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH |
| 10 | * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY |
| 11 | * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, |
| 12 | * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM |
| 13 | * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR |
| 14 | * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR |
| 15 | * PERFORMANCE OF THIS SOFTWARE. |
| 16 | * |
Gavin Howard | b5904bf | 2018-02-20 13:28:18 -0700 | [diff] [blame] | 17 | * ***************************************************************************** |
Gavin Howard | 5715b04 | 2018-02-12 16:11:42 -0700 | [diff] [blame] | 18 | * |
Gavin Howard | 4ffe5a9 | 2018-09-26 20:58:31 -0600 | [diff] [blame] | 19 | * Definitions for bc. |
Gavin Howard | 5715b04 | 2018-02-12 16:11:42 -0700 | [diff] [blame] | 20 | * |
| 21 | */ |
| 22 | |
Gavin Howard | 4ffe5a9 | 2018-09-26 20:58:31 -0600 | [diff] [blame] | 23 | #ifndef BC_BC_H |
| 24 | #define BC_BC_H |
Gavin Howard | 8a596d4 | 2018-01-15 15:46:01 -0700 | [diff] [blame] | 25 | |
Gavin Howard | c1902aa | 2018-12-20 15:54:28 -0700 | [diff] [blame^] | 26 | #include <limits.h> |
Gavin Howard | 707a4e3 | 2018-10-03 16:36:41 -0600 | [diff] [blame] | 27 | #include <stdbool.h> |
| 28 | |
Gavin Howard | 2949306 | 2018-03-20 19:57:37 -0600 | [diff] [blame] | 29 | #include <status.h> |
Gavin Howard | 707a4e3 | 2018-10-03 16:36:41 -0600 | [diff] [blame] | 30 | #include <lex.h> |
| 31 | #include <parse.h> |
Gavin Howard | 6839e4d | 2018-03-20 21:24:52 -0600 | [diff] [blame] | 32 | |
Gavin Howard | 40a085f | 2018-12-03 12:08:59 -0700 | [diff] [blame] | 33 | #if BC_ENABLED |
Gavin Howard | df4fe79 | 2018-10-03 16:48:30 -0600 | [diff] [blame] | 34 | |
Gavin Howard | eb9a822 | 2018-03-13 09:25:56 -0600 | [diff] [blame] | 35 | // ** Exclude start. ** |
Gavin Howard | 773c86b | 2018-11-02 14:07:19 -0600 | [diff] [blame] | 36 | // ** Busybox exclude start. ** |
Gavin Howard | a84ad99 | 2018-12-03 19:11:06 -0700 | [diff] [blame] | 37 | int bc_main(int argc, char **argv); |
| 38 | |
Gavin Howard | d555167 | 2018-09-22 19:52:42 -0600 | [diff] [blame] | 39 | extern const char bc_help[]; |
Gavin Howard | 773c86b | 2018-11-02 14:07:19 -0600 | [diff] [blame] | 40 | // ** Busybox exclude end. ** |
Gavin Howard | 707a4e3 | 2018-10-03 16:36:41 -0600 | [diff] [blame] | 41 | // ** Exclude end. ** |
| 42 | |
| 43 | typedef struct BcLexKeyword { |
Gavin Howard | c1902aa | 2018-12-20 15:54:28 -0700 | [diff] [blame^] | 44 | uchar data; |
Gavin Howard | 707a4e3 | 2018-10-03 16:36:41 -0600 | [diff] [blame] | 45 | const char name[9]; |
Gavin Howard | 707a4e3 | 2018-10-03 16:36:41 -0600 | [diff] [blame] | 46 | } BcLexKeyword; |
| 47 | |
Gavin Howard | c1902aa | 2018-12-20 15:54:28 -0700 | [diff] [blame^] | 48 | #define BC_LEX_KW_ENTRY(a, b, c) \ |
| 49 | { .data = (b) & ~(BC_LEX_CHAR_MSB(1)) | BC_LEX_CHAR_MSB(c),.name = a } |
Gavin Howard | 707a4e3 | 2018-10-03 16:36:41 -0600 | [diff] [blame] | 50 | |
| 51 | extern const BcLexKeyword bc_lex_kws[20]; |
| 52 | |
| 53 | BcStatus bc_lex_token(BcLex *l); |
| 54 | |
Gavin Howard | 890d0c0 | 2018-10-30 16:34:50 -0600 | [diff] [blame] | 55 | #define BC_PARSE_TOP_OP(p) (*((BcLexType*) bc_vec_top(&(p)->ops))) |
Gavin Howard | 707a4e3 | 2018-10-03 16:36:41 -0600 | [diff] [blame] | 56 | #define BC_PARSE_LEAF(p, rparen) \ |
| 57 | (((p) >= BC_INST_NUM && (p) <= BC_INST_SQRT) || (rparen) || \ |
| 58 | (p) == BC_INST_INC_POST || (p) == BC_INST_DEC_POST) |
| 59 | |
| 60 | // We can calculate the conversion between tokens and exprs by subtracting the |
Gavin Howard | 954f9b6 | 2018-12-19 15:22:20 -0700 | [diff] [blame] | 61 | // position of the first operator in the lex enum and adding the position of |
| 62 | // the first in the expr enum. Note: This only works for binary operators. |
| 63 | #define BC_PARSE_TOKEN_INST(t) ((uchar) ((t) - BC_LEX_NEG + BC_INST_NEG)) |
Gavin Howard | 707a4e3 | 2018-10-03 16:36:41 -0600 | [diff] [blame] | 64 | |
| 65 | // ** Exclude start. ** |
Gavin Howard | 773c86b | 2018-11-02 14:07:19 -0600 | [diff] [blame] | 66 | // ** Busybox exclude start. ** |
Gavin Howard | ad0ecfe | 2018-10-30 01:16:01 -0600 | [diff] [blame] | 67 | void bc_parse_init(BcParse *p, struct BcProgram *prog, size_t func); |
Gavin Howard | 7536dcf | 2018-12-15 19:27:09 -0700 | [diff] [blame] | 68 | BcStatus bc_parse_expr(BcParse *p, uint8_t flags); |
Gavin Howard | 773c86b | 2018-11-02 14:07:19 -0600 | [diff] [blame] | 69 | // ** Busybox exclude end. ** |
Gavin Howard | 707a4e3 | 2018-10-03 16:36:41 -0600 | [diff] [blame] | 70 | // ** Exclude end. ** |
| 71 | |
Gavin Howard | 9d2497d | 2018-10-29 16:10:21 -0600 | [diff] [blame] | 72 | BcStatus bc_parse_parse(BcParse *p); |
Gavin Howard | 7536dcf | 2018-12-15 19:27:09 -0700 | [diff] [blame] | 73 | |
| 74 | BcStatus bc_parse_expr_error(BcParse *p, uint8_t flags, BcParseNext next); |
| 75 | BcStatus bc_parse_expr_status(BcParse *p, uint8_t flags, BcParseNext next); |
| 76 | BcStatus bc_parse_else(BcParse *p); |
| 77 | BcStatus bc_parse_stmt(BcParse *p); |
Gavin Howard | ff66e29 | 2018-03-28 12:47:58 -0600 | [diff] [blame] | 78 | |
Gavin Howard | 1066709 | 2018-12-20 11:52:55 -0700 | [diff] [blame] | 79 | #if BC_ENABLE_SIGNALS |
| 80 | extern const char bc_sig_msg[]; |
Gavin Howard | 1066709 | 2018-12-20 11:52:55 -0700 | [diff] [blame] | 81 | #endif // BC_ENABLE_SIGNALS |
| 82 | |
Gavin Howard | a73c11b | 2018-12-17 11:30:39 -0700 | [diff] [blame] | 83 | extern const char* const bc_parse_const1; |
Gavin Howard | f89006a | 2018-10-29 13:01:51 -0600 | [diff] [blame] | 84 | extern const bool bc_parse_exprs[]; |
Gavin Howard | c1902aa | 2018-12-20 15:54:28 -0700 | [diff] [blame^] | 85 | extern const uchar bc_parse_ops[]; |
Gavin Howard | f89006a | 2018-10-29 13:01:51 -0600 | [diff] [blame] | 86 | extern const BcParseNext bc_parse_next_expr; |
| 87 | extern const BcParseNext bc_parse_next_param; |
| 88 | extern const BcParseNext bc_parse_next_print; |
| 89 | extern const BcParseNext bc_parse_next_rel; |
| 90 | extern const BcParseNext bc_parse_next_elem; |
| 91 | extern const BcParseNext bc_parse_next_for; |
| 92 | extern const BcParseNext bc_parse_next_read; |
| 93 | |
Gavin Howard | df4fe79 | 2018-10-03 16:48:30 -0600 | [diff] [blame] | 94 | #endif // BC_ENABLED |
| 95 | |
Gavin Howard | 4ffe5a9 | 2018-09-26 20:58:31 -0600 | [diff] [blame] | 96 | #endif // BC_BC_H |