# define BC_STATUS void
#endif
-struct BcLex;
-typedef BC_STATUS (*BcLexNext)(struct BcLex *) FAST_FUNC;
-
typedef struct BcLex {
const char *buf;
BcVec v;
} t;
- BcLexNext next;
-
} BcLex;
#define BC_PARSE_STREND ((char) UCHAR_MAX)
//return BC_STATUS_SUCCESS;
}
-static void bc_lex_init(BcLex *l, BcLexNext next)
+static void bc_lex_init(BcLex *l)
{
- l->next = next;
bc_char_vec_init(&l->t.v);
}
l->newline = false;
}
+static BC_STATUS zbc_lex_token(BcLex *l);
+static BC_STATUS zdc_lex_token(BcLex *l);
+
+static BC_STATUS zcommon_lex_token(BcLex *l)
+{
+ if (IS_BC) {
+ IF_BC(RETURN_STATUS(zbc_lex_token(l));)
+ }
+ IF_DC(RETURN_STATUS(zdc_lex_token(l));)
+}
+
static BC_STATUS zbc_lex_next(BcLex *l)
{
BcStatus s;
s = BC_STATUS_SUCCESS;
do {
//TODO: replace pointer with if(IS_BC)
- ERROR_RETURN(s =) l->next(l);
+ ERROR_RETURN(s =) zcommon_lex_token(l);
} while (!s && l->t.t == BC_LEX_WHITESPACE);
RETURN_STATUS(s);
# define zbc_lex_comment(...) (zbc_lex_comment(__VA_ARGS__), BC_STATUS_SUCCESS)
#endif
-static FAST_FUNC BC_STATUS zbc_lex_token(BcLex *l)
+static BC_STATUS zbc_lex_token(BcLex *l)
{
BcStatus s = BC_STATUS_SUCCESS;
char c = l->buf[l->i++], c2;
# define zdc_lex_string(...) (zdc_lex_string(__VA_ARGS__), BC_STATUS_SUCCESS)
#endif
-static FAST_FUNC BC_STATUS zdc_lex_token(BcLex *l)
+static BC_STATUS zdc_lex_token(BcLex *l)
{
BcStatus s = BC_STATUS_SUCCESS;
char c = l->buf[l->i++], c2;
bc_lex_free(&p->l);
}
-static void bc_parse_create(BcParse *p, size_t func, BcLexNext next)
+static void bc_parse_create(BcParse *p, size_t func)
{
memset(p, 0, sizeof(BcParse));
- bc_lex_init(&p->l, next);
+ bc_lex_init(&p->l);
bc_vec_init(&p->flags, sizeof(uint8_t), NULL);
bc_vec_init(&p->exits, sizeof(BcInstPtr), NULL);
bc_vec_init(&p->conds, sizeof(size_t), NULL);
# define zbc_parse_expr(...) (zbc_parse_expr(__VA_ARGS__), BC_STATUS_SUCCESS)
#endif
-static void bc_parse_init(BcParse *p, size_t func)
-{
- bc_parse_create(p, func, zbc_lex_token);
-}
-
static BC_STATUS zbc_parse_expression(BcParse *p, uint8_t flags)
{
RETURN_STATUS(zbc_parse_expr(p, flags, bc_parse_next_read));
# define zdc_parse_parse(...) (zdc_parse_parse(__VA_ARGS__), BC_STATUS_SUCCESS)
#endif
-static void dc_parse_init(BcParse *p, size_t func)
-{
- bc_parse_create(p, func, zdc_lex_token);
-}
-
#endif // ENABLE_DC
-static void common_parse_init(BcParse *p, size_t func)
-{
- if (IS_BC) {
- IF_BC(bc_parse_init(p, func);)
- } else {
- IF_DC(dc_parse_init(p, func);)
- }
-}
-
static BC_STATUS zcommon_parse_expr(BcParse *p, uint8_t flags)
{
if (IS_BC) {
bc_read_line(&buf);
- common_parse_init(&parse, BC_PROG_READ);
+ bc_parse_create(&parse, BC_PROG_READ);
bc_lex_file(&parse.l);
s = zbc_parse_text(&parse, buf.v);
f = bc_program_func(fidx);
if (f->code.len == 0) {
- common_parse_init(&prs, fidx);
+ bc_parse_create(&prs, fidx);
s = zbc_parse_text(&prs, *str);
if (s) goto err;
s = zcommon_parse_expr(&prs, BC_PARSE_NOCALL);
if (IS_BC)
IF_BC(bc_vm_envArgs();)
bc_program_init();
- common_parse_init(&G.prs, BC_PROG_MAIN);
+ bc_parse_create(&G.prs, BC_PROG_MAIN);
if (isatty(0)) {
#if ENABLE_FEATURE_BC_SIGNALS