XC_LEX_EOF,
XC_LEX_INVALID,
- BC_LEX_NLINE,
- BC_LEX_WHITESPACE,
- BC_LEX_STR,
- BC_LEX_NAME,
- BC_LEX_NUMBER,
+ XC_LEX_NLINE,
+ XC_LEX_WHITESPACE,
+ XC_LEX_STR,
+ XC_LEX_NAME,
+ XC_LEX_NUMBER,
XC_LEX_1st_op,
XC_LEX_NEG = XC_LEX_1st_op, // order
{
// Try: echo -n '#foo' | bc
size_t i;
- l->t.t = BC_LEX_WHITESPACE;
+ l->t.t = XC_LEX_WHITESPACE;
i = l->i;
while (i < l->len && l->buf[i] != '\n')
i++;
static void bc_lex_whitespace(BcLex *l)
{
- l->t.t = BC_LEX_WHITESPACE;
+ l->t.t = XC_LEX_WHITESPACE;
for (;;) {
char c = l->buf[l->i];
- if (c == '\n') // this is BC_LEX_NLINE, not BC_LEX_WHITESPACE
+ if (c == '\n') // this is XC_LEX_NLINE, not XC_LEX_WHITESPACE
break;
if (!isspace(c))
break;
bool pt;
pt = (start == '.');
- l->t.t = BC_LEX_NUMBER;
+ l->t.t = XC_LEX_NUMBER;
ccnt = i = 0;
for (;;) {
char c = buf[i];
size_t i;
const char *buf;
- l->t.t = BC_LEX_NAME;
+ l->t.t = XC_LEX_NAME;
i = 0;
buf = l->buf + l->i - 1;
// 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.
+ // Comments are also XC_LEX_WHITESPACE tokens and eaten here.
s = BC_STATUS_SUCCESS;
do {
if (l->i == l->len) {
} else {
IF_DC(s = zdc_lex_token(l));
}
- } while (!s && l->t.t == BC_LEX_WHITESPACE);
+ } while (!s && l->t.t == XC_LEX_WHITESPACE);
dbg_lex("l->t.t from string:%d", l->t.t);
RETURN_STATUS(s);
#if ENABLE_BC
static BC_STATUS zbc_lex_skip_if_at_NLINE(BcLex *l)
{
- if (l->t.t == BC_LEX_NLINE)
+ if (l->t.t == XC_LEX_NLINE)
RETURN_STATUS(zbc_lex_next(l));
RETURN_STATUS(BC_STATUS_SUCCESS);
}
{
size_t len, nls, i;
- l->t.t = BC_LEX_STR;
+ l->t.t = XC_LEX_STR;
nls = 0;
i = l->i;
size_t i, nls = 0;
const char *buf = l->buf;
- l->t.t = BC_LEX_WHITESPACE;
+ l->t.t = XC_LEX_WHITESPACE;
i = l->i; /* here buf[l->i] is the '*' of opening comment delimiter */
for (;;) {
char c = buf[++i];
// l->newline = true;
// break;
case '\n':
- l->t.t = BC_LEX_NLINE;
+ l->t.t = XC_LEX_NLINE;
l->newline = true;
break;
case '\t':
break;
case '\\':
if (l->buf[l->i] == '\n') {
- l->t.t = BC_LEX_WHITESPACE;
+ l->t.t = XC_LEX_WHITESPACE;
++l->i;
} else
s = bc_error_bad_character(c);
bc_vec_pop_all(&l->t.v);
bc_vec_push(&l->t.v, &l->buf[l->i++]);
bc_vec_pushZeroByte(&l->t.v);
- l->t.t = BC_LEX_NAME;
+ l->t.t = XC_LEX_NAME;
}
RETURN_STATUS(BC_STATUS_SUCCESS);
{
size_t depth, nls, i;
- l->t.t = BC_LEX_STR;
+ l->t.t = XC_LEX_STR;
bc_vec_pop_all(&l->t.v);
nls = 0;
// l->t.t = XC_LEX_EOF;
// break;
case '\n':
- // '\n' is BC_LEX_NLINE, not BC_LEX_WHITESPACE
+ // '\n' is XC_LEX_NLINE, not XC_LEX_WHITESPACE
// (and "case '\n':" is not just empty here)
// only to allow interactive dc have a way to exit
// "parse" stage of "parse,execute" loop
// commands are not executed on pressing <enter>).
// IOW: typing "1p<enter>" should print "1" _at once_,
// not after some more input.
- l->t.t = BC_LEX_NLINE;
+ l->t.t = XC_LEX_NLINE;
l->newline = true;
break;
case '\t':
// Same for "else", "while()", "for()".
BcStatus s = zbc_lex_next_and_skip_NLINE(&p->l);
if (s) RETURN_STATUS(s);
- if (p->l.t.t == BC_LEX_NLINE)
+ if (p->l.t.t == XC_LEX_NLINE)
RETURN_STATUS(bc_error_fmt("no statement after '%s'", after_X));
RETURN_STATUS(zbc_parse_stmt(p));
*nexprs = *nexprs + 1;
switch (type) {
- case BC_LEX_NAME:
+ case XC_LEX_NAME:
s = zbc_parse_name(p, prev, flags | BC_PARSE_NOCALL);
break;
case BC_LEX_KEY_IBASE:
s = zbc_lex_next(&p->l);
if (s) RETURN_STATUS(s);
type = p->l.t.t;
- if (type == BC_LEX_STR) {
+ if (type == XC_LEX_STR) {
s = zbc_parse_pushSTR(p);
} else {
s = zbc_parse_expr(p, 0);
if (s) RETURN_STATUS(s);
t = p->l.t.t;
- if (t == BC_LEX_NLINE || t == BC_LEX_SCOLON)
+ if (t == XC_LEX_NLINE || t == BC_LEX_SCOLON)
bc_parse_push(p, BC_INST_RET0);
else {
bool paren = (t == BC_LEX_LPAREN);
s = zbc_lex_next(&p->l);
if (s) RETURN_STATUS(s);
- if (p->l.t.t != BC_LEX_SCOLON && p->l.t.t != BC_LEX_NLINE)
+ if (p->l.t.t != BC_LEX_SCOLON && p->l.t.t != XC_LEX_NLINE)
RETURN_STATUS(bc_error_bad_token());
RETURN_STATUS(zbc_lex_next(&p->l));
dbg_lex_enter("%s:%d entered", __func__, __LINE__);
s = zbc_lex_next(&p->l);
if (s) RETURN_STATUS(s);
- if (p->l.t.t != BC_LEX_NAME)
+ if (p->l.t.t != XC_LEX_NAME)
RETURN_STATUS(bc_error("bad function definition"));
name = xstrdup(p->l.t.v.v);
if (s) RETURN_STATUS(s);
while (p->l.t.t != BC_LEX_RPAREN) {
- if (p->l.t.t != BC_LEX_NAME)
+ if (p->l.t.t != XC_LEX_NAME)
RETURN_STATUS(bc_error("bad function definition"));
++p->func->nparams;
if (s) RETURN_STATUS(s);
comma = false;
- one = p->l.t.t == BC_LEX_NAME;
+ one = p->l.t.t == XC_LEX_NAME;
- while (p->l.t.t == BC_LEX_NAME) {
+ while (p->l.t.t == XC_LEX_NAME) {
name = xstrdup(p->l.t.v.v);
s = zbc_lex_next(&p->l);
if (s) goto err;
if (comma) RETURN_STATUS(bc_error("bad function definition"));
if (!one) RETURN_STATUS(bc_error("no auto variable found"));
- if (p->l.t.t != BC_LEX_NLINE && p->l.t.t != BC_LEX_SCOLON)
+ if (p->l.t.t != XC_LEX_NLINE && p->l.t.t != BC_LEX_SCOLON)
RETURN_STATUS(bc_error_bad_token());
dbg_lex_done("%s:%d done", __func__, __LINE__);
dbg_lex_enter("%s:%d entered, p->l.t.t:%d", __func__, __LINE__, p->l.t.t);
- if (p->l.t.t == BC_LEX_NLINE) {
- dbg_lex_done("%s:%d done (seen BC_LEX_NLINE)", __func__, __LINE__);
+ if (p->l.t.t == XC_LEX_NLINE) {
+ dbg_lex_done("%s:%d done (seen XC_LEX_NLINE)", __func__, __LINE__);
RETURN_STATUS(zbc_lex_next(&p->l));
}
if (p->l.t.t == BC_LEX_SCOLON) {
do {
s = zbc_lex_next(&p->l);
if (s) RETURN_STATUS(s);
- } while (p->l.t.t == BC_LEX_NLINE);
+ } while (p->l.t.t == XC_LEX_NLINE);
if (auto_allowed && p->l.t.t == BC_LEX_KEY_AUTO) {
dbg_lex("%s:%d calling zbc_parse_auto()", __func__, __LINE__);
s = zbc_parse_auto(p);
case BC_LEX_OP_DEC:
case BC_LEX_OP_BOOL_NOT:
case BC_LEX_LPAREN:
- case BC_LEX_NAME:
- case BC_LEX_NUMBER:
+ case XC_LEX_NAME:
+ case XC_LEX_NUMBER:
case BC_LEX_KEY_IBASE:
case BC_LEX_KEY_LAST:
case BC_LEX_KEY_LENGTH:
case BC_LEX_KEY_SQRT:
s = zbc_parse_expr(p, BC_PARSE_PRINT);
break;
- case BC_LEX_STR:
+ case XC_LEX_STR:
s = zbc_parse_pushSTR(p);
bc_parse_push(p, XC_INST_PRINT_STR);
break;
get_token = bin_last = false;
s = zbc_parse_rightParen(p, ops_bgn, &nexprs);
break;
- case BC_LEX_NAME:
+ case XC_LEX_NAME:
if (BC_PARSE_LEAF(prev, rprn))
return bc_error_bad_expression();
paren_expr = true;
s = zbc_parse_name(p, &prev, flags & ~BC_PARSE_NOCALL);
++nexprs;
break;
- case BC_LEX_NUMBER:
+ case XC_LEX_NUMBER:
if (BC_PARSE_LEAF(prev, rprn))
return bc_error_bad_expression();
bc_parse_pushNUM(p);
s = zbc_lex_next(&p->l);
if (s) RETURN_STATUS(s);
- if (p->l.t.t != BC_LEX_NAME) RETURN_STATUS(bc_error_bad_token());
+ if (p->l.t.t != XC_LEX_NAME) RETURN_STATUS(bc_error_bad_token());
bc_parse_pushName(p, p->l.t.v.v);
dbg_lex("%s:%d LEX_[S]COLON", __func__, __LINE__);
s = zdc_parse_mem(p, XC_INST_ARRAY_ELEM, true, t == DC_LEX_COLON);
break;
- case BC_LEX_STR:
+ case XC_LEX_STR:
dbg_lex("%s:%d LEX_STR", __func__, __LINE__);
dc_parse_string(p);
break;
dbg_lex("%s:%d LEX_NEG", __func__, __LINE__);
s = zbc_lex_next(&p->l);
if (s) RETURN_STATUS(s);
- if (p->l.t.t != BC_LEX_NUMBER)
+ if (p->l.t.t != XC_LEX_NUMBER)
RETURN_STATUS(bc_error_bad_token());
bc_parse_pushNUM(p);
bc_parse_push(p, XC_INST_NEG);
break;
- case BC_LEX_NUMBER:
+ case XC_LEX_NUMBER:
dbg_lex("%s:%d LEX_NUMBER", __func__, __LINE__);
bc_parse_pushNUM(p);
break;
}
if (s) goto exec_err;
- if (parse.l.t.t != BC_LEX_NLINE && parse.l.t.t != XC_LEX_EOF) {
+ if (parse.l.t.t != XC_LEX_NLINE && parse.l.t.t != XC_LEX_EOF) {
s = bc_error("bad read() expression");
goto exec_err;
}
} else {
// Most of dc parsing assumes all whitespace,
// including '\n', is eaten.
- while (G.prs.l.t.t == BC_LEX_NLINE) {
+ while (G.prs.l.t.t == XC_LEX_NLINE) {
s = zbc_lex_next(&G.prs.l);
if (s) goto err;
if (G.prs.l.t.t == XC_LEX_EOF)