blob: dabedeb7cd0b1c17dcfe41fe6070bee256080a54 [file] [log] [blame]
Gavin Howard5715b042018-02-12 16:11:42 -07001/*
Gavin Howardb5904bf2018-02-20 13:28:18 -07002 * *****************************************************************************
Gavin Howard5715b042018-02-12 16:11:42 -07003 *
Gavin Howardb5904bf2018-02-20 13:28:18 -07004 * Copyright 2018 Gavin D. Howard
Gavin Howard5715b042018-02-12 16:11:42 -07005 *
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 Howardb5904bf2018-02-20 13:28:18 -070017 * *****************************************************************************
Gavin Howard5715b042018-02-12 16:11:42 -070018 *
Gavin Howard4ffe5a92018-09-26 20:58:31 -060019 * Definitions for bc.
Gavin Howard5715b042018-02-12 16:11:42 -070020 *
21 */
22
Gavin Howard4ffe5a92018-09-26 20:58:31 -060023#ifndef BC_BC_H
24#define BC_BC_H
Gavin Howard8a596d42018-01-15 15:46:01 -070025
Gavin Howard707a4e32018-10-03 16:36:41 -060026#include <stdbool.h>
27
Gavin Howard29493062018-03-20 19:57:37 -060028#include <status.h>
Gavin Howard707a4e32018-10-03 16:36:41 -060029#include <lex.h>
30#include <parse.h>
Gavin Howard6839e4d2018-03-20 21:24:52 -060031
Gavin Howarddf4fe792018-10-03 16:48:30 -060032#ifdef BC_ENABLED
33
Gavin Howardeb9a8222018-03-13 09:25:56 -060034// ** Exclude start. **
Gavin Howardd5551672018-09-22 19:52:42 -060035BcStatus bc_main(int argc, char *argv[]);
Gavin Howardc5e491b2018-02-20 13:51:20 -070036
Gavin Howardd5551672018-09-22 19:52:42 -060037extern const char bc_help[];
Gavin Howard707a4e32018-10-03 16:36:41 -060038// ** Exclude end. **
39
40typedef 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
50extern const BcLexKeyword bc_lex_kws[20];
51
52BcStatus bc_lex_token(BcLex *l);
53
Gavin Howard707a4e32018-10-03 16:36:41 -060054#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 Howarde3240122018-10-06 20:31:50 -060061#define BC_PARSE_TOKEN_INST(t) ((char) ((t) - BC_LEX_NEG + BC_INST_NEG))
Gavin Howard707a4e32018-10-03 16:36:41 -060062
63// ** Exclude start. **
Gavin Howarde3240122018-10-06 20:31:50 -060064BcStatus bc_parse_init(BcParse *p, struct BcProgram *prog, size_t func);
65BcStatus bc_parse_expression(BcParse *p, uint8_t flags);
Gavin Howard707a4e32018-10-03 16:36:41 -060066// ** Exclude end. **
67
Gavin Howarde3240122018-10-06 20:31:50 -060068BcStatus bc_parse_expr(BcParse *p, uint8_t flags, BcParseNext next);
Gavin Howardff66e292018-03-28 12:47:58 -060069
Gavin Howarddf4fe792018-10-03 16:48:30 -060070#endif // BC_ENABLED
71
Gavin Howard4ffe5a92018-09-26 20:58:31 -060072#endif // BC_BC_H