BC_LEX_COMMA,
BC_LEX_RBRACKET,
- BC_LEX_LBRACE,
+ BC_LEX_LBRACE, // '{' is 0x7B, '}' is 0x7D,
BC_LEX_SCOLON,
- BC_LEX_RBRACE,
+ BC_LEX_RBRACE, // should be LBRACE+2: code uses (c - '{' + BC_LEX_LBRACE)
BC_LEX_STR,
BC_LEX_NAME,
BcFunc *func;
size_t fidx;
-//TODO: needed? Example?
- size_t nbraces;
-
size_t in_funcdef;
} BcParse;
l->t.t = BC_LEX_WHITESPACE;
for (;;) {
char c = l->buf[l->i];
- if (c == '\n' || !isspace(c))
+ if (c == '\n') // this is BC_LEX_NLINE, not BC_LEX_WHITESPACE
+ break;
+ if (!isspace(c))
break;
l->i++;
}
// Loop until failure or we don't have whitespace. This
// is so the parser doesn't get inundated with whitespace.
+ // Comments are also BC_LEX_WHITESPACE tokens and eaten here.
s = BC_STATUS_SUCCESS;
do {
dbg_lex("next string to parse:'%.*s'",
const char *buf = l->buf;
l->t.t = BC_LEX_WHITESPACE;
- i = ++l->i;
+ i = l->i; /* here buf[l->i] is the '*' of opening comment delimiter */
for (;;) {
- char c = buf[i];
+ char c = buf[++i];
check_star:
if (c == '*') {
c = buf[++i];
RETURN_STATUS(bc_error("comment end could not be found"));
}
nls += (c == '\n');
- i++;
}
l->i = i + 1;
// This is the workhorse of the lexer.
switch (c) {
- case '\0':
+ case '\0': // probably never reached
+ l->i--;
+ l->t.t = BC_LEX_EOF;
+ l->newline = true;
+ break;
case '\n':
+ l->t.t = BC_LEX_NLINE;
l->newline = true;
- l->t.t = !c ? BC_LEX_EOF : BC_LEX_NLINE;
break;
case '\t':
case '\v':
}
}
-static void bc_parse_number(BcParse *p, BcInst *prev, size_t *nexs)
+static void bc_parse_number(BcParse *p)
{
char *num = xstrdup(p->l.t.v.v);
size_t idx = G.prog.consts.len;
bc_parse_push(p, BC_INST_NUM);
bc_parse_pushIndex(p, idx);
-
- ++(*nexs);
- (*prev) = BC_INST_NUM;
}
IF_BC(static BC_STATUS zbc_parse_stmt_or_funcdef(BcParse *p);)
p->l.i = p->l.len;
p->l.t.t = BC_LEX_EOF;
- p->nbraces = 0;
bc_vec_pop_all(&p->exits);
bc_vec_pop_all(&p->conds);
bc_vec_init(&p->conds, sizeof(size_t), NULL);
bc_vec_init(&p->ops, sizeof(BcLexType), NULL);
- // p->nbraces = 0; - already is
bc_parse_updateFunc(p, func);
}
{
if (BC_PARSE_LEAF(prev, rprn))
return bc_error_bad_expression();
- bc_parse_number(p, &prev, &nexprs);
+ bc_parse_number(p);
+ nexprs++;
+ prev = BC_INST_NUM;
paren_expr = get_token = true;
rprn = bin_last = false;
if (p->l.t.t != BC_LEX_NUMBER)
RETURN_STATUS(bc_error_bad_token());
}
- bc_parse_number(p, &prev, &p->nbraces);
+ bc_parse_number(p);
+ prev = BC_INST_NUM;
if (t == BC_LEX_NEG) bc_parse_push(p, BC_INST_NEG);
get_token = true;
break;
BcInst inst;
BcLexType t;
- if (flags & BC_PARSE_NOCALL) p->nbraces = G.prog.results.len;
-
for (t = p->l.t.t; !s && t != BC_LEX_EOF; t = p->l.t.t) {
inst = dc_parse_insts[t];