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 | df4fe79 | 2018-10-03 16:48:30 -0600 | [diff] [blame] | 32 | #ifdef BC_ENABLED |
| 33 | |
Gavin Howard | eb9a822 | 2018-03-13 09:25:56 -0600 | [diff] [blame] | 34 | // ** Exclude start. ** |
Gavin Howard | d555167 | 2018-09-22 19:52:42 -0600 | [diff] [blame] | 35 | BcStatus bc_main(int argc, char *argv[]); |
Gavin Howard | c5e491b | 2018-02-20 13:51:20 -0700 | [diff] [blame] | 36 | |
Gavin Howard | d555167 | 2018-09-22 19:52:42 -0600 | [diff] [blame] | 37 | extern const char bc_help[]; |
Gavin Howard | 707a4e3 | 2018-10-03 16:36:41 -0600 | [diff] [blame] | 38 | // ** Exclude end. ** |
| 39 | |
| 40 | typedef struct BcLexKeyword { |
| 41 | |
| 42 | const char name[9]; |
| 43 | const char len; |
| 44 | const bool posix; |
| 45 | |
| 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 | 707a4e3 | 2018-10-03 16:36:41 -0600 | [diff] [blame] | 54 | #define BC_PARSE_LEAF(p, rparen) \ |
| 55 | (((p) >= BC_INST_NUM && (p) <= BC_INST_SQRT) || (rparen) || \ |
| 56 | (p) == BC_INST_INC_POST || (p) == BC_INST_DEC_POST) |
| 57 | |
| 58 | // We can calculate the conversion between tokens and exprs by subtracting the |
| 59 | // position of the first operator in the lex enum and adding the position of the |
| 60 | // first in the expr enum. Note: This only works for binary operators. |
Gavin Howard | e324012 | 2018-10-06 20:31:50 -0600 | [diff] [blame] | 61 | #define BC_PARSE_TOKEN_INST(t) ((char) ((t) - BC_LEX_NEG + BC_INST_NEG)) |
Gavin Howard | 707a4e3 | 2018-10-03 16:36:41 -0600 | [diff] [blame] | 62 | |
| 63 | // ** Exclude start. ** |
Gavin Howard | e324012 | 2018-10-06 20:31:50 -0600 | [diff] [blame] | 64 | BcStatus bc_parse_init(BcParse *p, struct BcProgram *prog, size_t func); |
| 65 | BcStatus bc_parse_expression(BcParse *p, uint8_t flags); |
Gavin Howard | 707a4e3 | 2018-10-03 16:36:41 -0600 | [diff] [blame] | 66 | // ** Exclude end. ** |
| 67 | |
Gavin Howard | e324012 | 2018-10-06 20:31:50 -0600 | [diff] [blame] | 68 | BcStatus bc_parse_expr(BcParse *p, uint8_t flags, BcParseNext next); |
Gavin Howard | ff66e29 | 2018-03-28 12:47:58 -0600 | [diff] [blame] | 69 | |
Gavin Howard | df4fe79 | 2018-10-03 16:48:30 -0600 | [diff] [blame] | 70 | #endif // BC_ENABLED |
| 71 | |
Gavin Howard | 4ffe5a9 | 2018-09-26 20:58:31 -0600 | [diff] [blame] | 72 | #endif // BC_BC_H |