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 | 707a4e3 | 2018-10-03 16:36:41 -0600 | [diff] [blame] | 26 | #include <stdbool.h> |
| 27 | |
Gavin Howard | 2949306 | 2018-03-20 19:57:37 -0600 | [diff] [blame] | 28 | #include <status.h> |
Gavin Howard | 707a4e3 | 2018-10-03 16:36:41 -0600 | [diff] [blame] | 29 | #include <lex.h> |
| 30 | #include <parse.h> |
Gavin Howard | 6839e4d | 2018-03-20 21:24:52 -0600 | [diff] [blame] | 31 | |
Gavin Howard | 40a085f | 2018-12-03 12:08:59 -0700 | [diff] [blame] | 32 | #if BC_ENABLED |
Gavin Howard | df4fe79 | 2018-10-03 16:48:30 -0600 | [diff] [blame] | 33 | |
Gavin Howard | eb9a822 | 2018-03-13 09:25:56 -0600 | [diff] [blame] | 34 | // ** Exclude start. ** |
Gavin Howard | 773c86b | 2018-11-02 14:07:19 -0600 | [diff] [blame] | 35 | // ** Busybox exclude start. ** |
Gavin Howard | a84ad99 | 2018-12-03 19:11:06 -0700 | [diff] [blame] | 36 | int bc_main(int argc, char **argv); |
| 37 | |
Gavin Howard | d555167 | 2018-09-22 19:52:42 -0600 | [diff] [blame] | 38 | extern const char bc_help[]; |
Gavin Howard | 773c86b | 2018-11-02 14:07:19 -0600 | [diff] [blame] | 39 | // ** Busybox exclude end. ** |
Gavin Howard | 707a4e3 | 2018-10-03 16:36:41 -0600 | [diff] [blame] | 40 | // ** Exclude end. ** |
| 41 | |
| 42 | typedef struct BcLexKeyword { |
Gavin Howard | 707a4e3 | 2018-10-03 16:36:41 -0600 | [diff] [blame] | 43 | const char name[9]; |
Gavin Howard | 954f9b6 | 2018-12-19 15:22:20 -0700 | [diff] [blame^] | 44 | const uchar len; |
Gavin Howard | 707a4e3 | 2018-10-03 16:36:41 -0600 | [diff] [blame] | 45 | const bool posix; |
Gavin Howard | 707a4e3 | 2018-10-03 16:36:41 -0600 | [diff] [blame] | 46 | } BcLexKeyword; |
| 47 | |
| 48 | #define BC_LEX_KW_ENTRY(a, b, c) { .name = a, .len = (b), .posix = (c) } |
| 49 | |
| 50 | extern const BcLexKeyword bc_lex_kws[20]; |
| 51 | |
| 52 | BcStatus bc_lex_token(BcLex *l); |
| 53 | |
Gavin Howard | 890d0c0 | 2018-10-30 16:34:50 -0600 | [diff] [blame] | 54 | #define BC_PARSE_TOP_OP(p) (*((BcLexType*) bc_vec_top(&(p)->ops))) |
Gavin Howard | 707a4e3 | 2018-10-03 16:36:41 -0600 | [diff] [blame] | 55 | #define BC_PARSE_LEAF(p, rparen) \ |
| 56 | (((p) >= BC_INST_NUM && (p) <= BC_INST_SQRT) || (rparen) || \ |
| 57 | (p) == BC_INST_INC_POST || (p) == BC_INST_DEC_POST) |
| 58 | |
| 59 | // We can calculate the conversion between tokens and exprs by subtracting the |
Gavin Howard | 954f9b6 | 2018-12-19 15:22:20 -0700 | [diff] [blame^] | 60 | // position of the first operator in the lex enum and adding the position of |
| 61 | // the first in the expr enum. Note: This only works for binary operators. |
| 62 | #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] | 63 | |
| 64 | // ** Exclude start. ** |
Gavin Howard | 773c86b | 2018-11-02 14:07:19 -0600 | [diff] [blame] | 65 | // ** Busybox exclude start. ** |
Gavin Howard | ad0ecfe | 2018-10-30 01:16:01 -0600 | [diff] [blame] | 66 | void bc_parse_init(BcParse *p, struct BcProgram *prog, size_t func); |
Gavin Howard | 7536dcf | 2018-12-15 19:27:09 -0700 | [diff] [blame] | 67 | BcStatus bc_parse_expr(BcParse *p, uint8_t flags); |
Gavin Howard | 773c86b | 2018-11-02 14:07:19 -0600 | [diff] [blame] | 68 | // ** Busybox exclude end. ** |
Gavin Howard | 707a4e3 | 2018-10-03 16:36:41 -0600 | [diff] [blame] | 69 | // ** Exclude end. ** |
| 70 | |
Gavin Howard | 9d2497d | 2018-10-29 16:10:21 -0600 | [diff] [blame] | 71 | BcStatus bc_parse_parse(BcParse *p); |
Gavin Howard | 7536dcf | 2018-12-15 19:27:09 -0700 | [diff] [blame] | 72 | |
| 73 | BcStatus bc_parse_expr_error(BcParse *p, uint8_t flags, BcParseNext next); |
| 74 | BcStatus bc_parse_expr_status(BcParse *p, uint8_t flags, BcParseNext next); |
| 75 | BcStatus bc_parse_else(BcParse *p); |
| 76 | BcStatus bc_parse_stmt(BcParse *p); |
Gavin Howard | ff66e29 | 2018-03-28 12:47:58 -0600 | [diff] [blame] | 77 | |
Gavin Howard | a73c11b | 2018-12-17 11:30:39 -0700 | [diff] [blame] | 78 | extern const char* const bc_parse_const1; |
Gavin Howard | f89006a | 2018-10-29 13:01:51 -0600 | [diff] [blame] | 79 | extern const bool bc_parse_exprs[]; |
| 80 | extern const BcOp bc_parse_ops[]; |
| 81 | extern const BcParseNext bc_parse_next_expr; |
| 82 | extern const BcParseNext bc_parse_next_param; |
| 83 | extern const BcParseNext bc_parse_next_print; |
| 84 | extern const BcParseNext bc_parse_next_rel; |
| 85 | extern const BcParseNext bc_parse_next_elem; |
| 86 | extern const BcParseNext bc_parse_next_for; |
| 87 | extern const BcParseNext bc_parse_next_read; |
| 88 | |
Gavin Howard | df4fe79 | 2018-10-03 16:48:30 -0600 | [diff] [blame] | 89 | #endif // BC_ENABLED |
| 90 | |
Gavin Howard | 4ffe5a9 | 2018-09-26 20:58:31 -0600 | [diff] [blame] | 91 | #endif // BC_BC_H |