bc: rename BC_LEX_NLINE/WHITESPACE/STR/NAME/NUMBER to XC_LEX_

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Denys Vlasenko 2018-12-24 15:05:49 +01:00
parent 9d9c97efbd
commit 23ea0734e1

View File

@ -392,11 +392,11 @@ typedef enum BcLexType {
XC_LEX_EOF, XC_LEX_EOF,
XC_LEX_INVALID, XC_LEX_INVALID,
BC_LEX_NLINE, XC_LEX_NLINE,
BC_LEX_WHITESPACE, XC_LEX_WHITESPACE,
BC_LEX_STR, XC_LEX_STR,
BC_LEX_NAME, XC_LEX_NAME,
BC_LEX_NUMBER, XC_LEX_NUMBER,
XC_LEX_1st_op, XC_LEX_1st_op,
XC_LEX_NEG = XC_LEX_1st_op, // order XC_LEX_NEG = XC_LEX_1st_op, // order
@ -2745,7 +2745,7 @@ static void bc_lex_lineComment(BcLex *l)
{ {
// Try: echo -n '#foo' | bc // Try: echo -n '#foo' | bc
size_t i; size_t i;
l->t.t = BC_LEX_WHITESPACE; l->t.t = XC_LEX_WHITESPACE;
i = l->i; i = l->i;
while (i < l->len && l->buf[i] != '\n') while (i < l->len && l->buf[i] != '\n')
i++; i++;
@ -2754,10 +2754,10 @@ static void bc_lex_lineComment(BcLex *l)
static void bc_lex_whitespace(BcLex *l) static void bc_lex_whitespace(BcLex *l)
{ {
l->t.t = BC_LEX_WHITESPACE; l->t.t = XC_LEX_WHITESPACE;
for (;;) { for (;;) {
char c = l->buf[l->i]; 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; break;
if (!isspace(c)) if (!isspace(c))
break; break;
@ -2772,7 +2772,7 @@ static BC_STATUS zbc_lex_number(BcLex *l, char start)
bool pt; bool pt;
pt = (start == '.'); pt = (start == '.');
l->t.t = BC_LEX_NUMBER; l->t.t = XC_LEX_NUMBER;
ccnt = i = 0; ccnt = i = 0;
for (;;) { for (;;) {
char c = buf[i]; char c = buf[i];
@ -2840,7 +2840,7 @@ static void bc_lex_name(BcLex *l)
size_t i; size_t i;
const char *buf; const char *buf;
l->t.t = BC_LEX_NAME; l->t.t = XC_LEX_NAME;
i = 0; i = 0;
buf = l->buf + l->i - 1; buf = l->buf + l->i - 1;
@ -2971,7 +2971,7 @@ static BC_STATUS zbc_lex_next(BcLex *l)
// Loop until failure or we don't have whitespace. This // Loop until failure or we don't have whitespace. This
// is so the parser doesn't get inundated with whitespace. // 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; s = BC_STATUS_SUCCESS;
do { do {
if (l->i == l->len) { if (l->i == l->len) {
@ -2992,7 +2992,7 @@ static BC_STATUS zbc_lex_next(BcLex *l)
} else { } else {
IF_DC(s = zdc_lex_token(l)); 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); dbg_lex("l->t.t from string:%d", l->t.t);
RETURN_STATUS(s); RETURN_STATUS(s);
@ -3002,7 +3002,7 @@ static BC_STATUS zbc_lex_next(BcLex *l)
#if ENABLE_BC #if ENABLE_BC
static BC_STATUS zbc_lex_skip_if_at_NLINE(BcLex *l) 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(zbc_lex_next(l));
RETURN_STATUS(BC_STATUS_SUCCESS); RETURN_STATUS(BC_STATUS_SUCCESS);
} }
@ -3081,7 +3081,7 @@ static BC_STATUS zbc_lex_string(BcLex *l)
{ {
size_t len, nls, i; size_t len, nls, i;
l->t.t = BC_LEX_STR; l->t.t = XC_LEX_STR;
nls = 0; nls = 0;
i = l->i; i = l->i;
@ -3129,7 +3129,7 @@ static BC_STATUS zbc_lex_comment(BcLex *l)
size_t i, nls = 0; size_t i, nls = 0;
const char *buf = l->buf; 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 */ i = l->i; /* here buf[l->i] is the '*' of opening comment delimiter */
for (;;) { for (;;) {
char c = buf[++i]; char c = buf[++i];
@ -3169,7 +3169,7 @@ static BC_STATUS zbc_lex_token(BcLex *l)
// l->newline = true; // l->newline = true;
// break; // break;
case '\n': case '\n':
l->t.t = BC_LEX_NLINE; l->t.t = XC_LEX_NLINE;
l->newline = true; l->newline = true;
break; break;
case '\t': case '\t':
@ -3286,7 +3286,7 @@ static BC_STATUS zbc_lex_token(BcLex *l)
break; break;
case '\\': case '\\':
if (l->buf[l->i] == '\n') { if (l->buf[l->i] == '\n') {
l->t.t = BC_LEX_WHITESPACE; l->t.t = XC_LEX_WHITESPACE;
++l->i; ++l->i;
} else } else
s = bc_error_bad_character(c); s = bc_error_bad_character(c);
@ -3360,7 +3360,7 @@ static BC_STATUS zdc_lex_register(BcLex *l)
bc_vec_pop_all(&l->t.v); bc_vec_pop_all(&l->t.v);
bc_vec_push(&l->t.v, &l->buf[l->i++]); bc_vec_push(&l->t.v, &l->buf[l->i++]);
bc_vec_pushZeroByte(&l->t.v); bc_vec_pushZeroByte(&l->t.v);
l->t.t = BC_LEX_NAME; l->t.t = XC_LEX_NAME;
} }
RETURN_STATUS(BC_STATUS_SUCCESS); RETURN_STATUS(BC_STATUS_SUCCESS);
@ -3371,7 +3371,7 @@ static BC_STATUS zdc_lex_string(BcLex *l)
{ {
size_t depth, nls, i; size_t depth, nls, i;
l->t.t = BC_LEX_STR; l->t.t = XC_LEX_STR;
bc_vec_pop_all(&l->t.v); bc_vec_pop_all(&l->t.v);
nls = 0; nls = 0;
@ -3445,7 +3445,7 @@ static BC_STATUS zdc_lex_token(BcLex *l)
// l->t.t = XC_LEX_EOF; // l->t.t = XC_LEX_EOF;
// break; // break;
case '\n': 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) // (and "case '\n':" is not just empty here)
// only to allow interactive dc have a way to exit // only to allow interactive dc have a way to exit
// "parse" stage of "parse,execute" loop // "parse" stage of "parse,execute" loop
@ -3453,7 +3453,7 @@ static BC_STATUS zdc_lex_token(BcLex *l)
// commands are not executed on pressing <enter>). // commands are not executed on pressing <enter>).
// IOW: typing "1p<enter>" should print "1" _at once_, // IOW: typing "1p<enter>" should print "1" _at once_,
// not after some more input. // not after some more input.
l->t.t = BC_LEX_NLINE; l->t.t = XC_LEX_NLINE;
l->newline = true; l->newline = true;
break; break;
case '\t': case '\t':
@ -3737,7 +3737,7 @@ static BC_STATUS zbc_parse_stmt_allow_NLINE_before(BcParse *p, const char *after
// Same for "else", "while()", "for()". // Same for "else", "while()", "for()".
BcStatus s = zbc_lex_next_and_skip_NLINE(&p->l); BcStatus s = zbc_lex_next_and_skip_NLINE(&p->l);
if (s) RETURN_STATUS(s); 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(bc_error_fmt("no statement after '%s'", after_X));
RETURN_STATUS(zbc_parse_stmt(p)); RETURN_STATUS(zbc_parse_stmt(p));
@ -4012,7 +4012,7 @@ static BC_STATUS zbc_parse_incdec(BcParse *p, BcInst *prev, bool *paren_expr,
*nexprs = *nexprs + 1; *nexprs = *nexprs + 1;
switch (type) { switch (type) {
case BC_LEX_NAME: case XC_LEX_NAME:
s = zbc_parse_name(p, prev, flags | BC_PARSE_NOCALL); s = zbc_parse_name(p, prev, flags | BC_PARSE_NOCALL);
break; break;
case BC_LEX_KEY_IBASE: case BC_LEX_KEY_IBASE:
@ -4077,7 +4077,7 @@ static BC_STATUS zbc_parse_print(BcParse *p)
s = zbc_lex_next(&p->l); s = zbc_lex_next(&p->l);
if (s) RETURN_STATUS(s); if (s) RETURN_STATUS(s);
type = p->l.t.t; type = p->l.t.t;
if (type == BC_LEX_STR) { if (type == XC_LEX_STR) {
s = zbc_parse_pushSTR(p); s = zbc_parse_pushSTR(p);
} else { } else {
s = zbc_parse_expr(p, 0); s = zbc_parse_expr(p, 0);
@ -4102,7 +4102,7 @@ static BC_STATUS zbc_parse_return(BcParse *p)
if (s) RETURN_STATUS(s); if (s) RETURN_STATUS(s);
t = p->l.t.t; 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); bc_parse_push(p, BC_INST_RET0);
else { else {
bool paren = (t == BC_LEX_LPAREN); bool paren = (t == BC_LEX_LPAREN);
@ -4327,7 +4327,7 @@ static BC_STATUS zbc_parse_break_or_continue(BcParse *p, BcLexType type)
s = zbc_lex_next(&p->l); s = zbc_lex_next(&p->l);
if (s) RETURN_STATUS(s); 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(bc_error_bad_token());
RETURN_STATUS(zbc_lex_next(&p->l)); RETURN_STATUS(zbc_lex_next(&p->l));
@ -4364,7 +4364,7 @@ static BC_STATUS zbc_parse_funcdef(BcParse *p)
dbg_lex_enter("%s:%d entered", __func__, __LINE__); dbg_lex_enter("%s:%d entered", __func__, __LINE__);
s = zbc_lex_next(&p->l); s = zbc_lex_next(&p->l);
if (s) RETURN_STATUS(s); 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")); RETURN_STATUS(bc_error("bad function definition"));
name = xstrdup(p->l.t.v.v); name = xstrdup(p->l.t.v.v);
@ -4379,7 +4379,7 @@ static BC_STATUS zbc_parse_funcdef(BcParse *p)
if (s) RETURN_STATUS(s); if (s) RETURN_STATUS(s);
while (p->l.t.t != BC_LEX_RPAREN) { 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")); RETURN_STATUS(bc_error("bad function definition"));
++p->func->nparams; ++p->func->nparams;
@ -4459,9 +4459,9 @@ static BC_STATUS zbc_parse_auto(BcParse *p)
if (s) RETURN_STATUS(s); if (s) RETURN_STATUS(s);
comma = false; 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); name = xstrdup(p->l.t.v.v);
s = zbc_lex_next(&p->l); s = zbc_lex_next(&p->l);
if (s) goto err; if (s) goto err;
@ -4493,7 +4493,7 @@ static BC_STATUS zbc_parse_auto(BcParse *p)
if (comma) RETURN_STATUS(bc_error("bad function definition")); if (comma) RETURN_STATUS(bc_error("bad function definition"));
if (!one) RETURN_STATUS(bc_error("no auto variable found")); 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()); RETURN_STATUS(bc_error_bad_token());
dbg_lex_done("%s:%d done", __func__, __LINE__); dbg_lex_done("%s:%d done", __func__, __LINE__);
@ -4512,8 +4512,8 @@ static BC_STATUS zbc_parse_stmt_possibly_auto(BcParse *p, bool auto_allowed)
dbg_lex_enter("%s:%d entered, p->l.t.t:%d", __func__, __LINE__, p->l.t.t); 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) { if (p->l.t.t == XC_LEX_NLINE) {
dbg_lex_done("%s:%d done (seen BC_LEX_NLINE)", __func__, __LINE__); dbg_lex_done("%s:%d done (seen XC_LEX_NLINE)", __func__, __LINE__);
RETURN_STATUS(zbc_lex_next(&p->l)); RETURN_STATUS(zbc_lex_next(&p->l));
} }
if (p->l.t.t == BC_LEX_SCOLON) { if (p->l.t.t == BC_LEX_SCOLON) {
@ -4526,7 +4526,7 @@ static BC_STATUS zbc_parse_stmt_possibly_auto(BcParse *p, bool auto_allowed)
do { do {
s = zbc_lex_next(&p->l); s = zbc_lex_next(&p->l);
if (s) RETURN_STATUS(s); 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) { if (auto_allowed && p->l.t.t == BC_LEX_KEY_AUTO) {
dbg_lex("%s:%d calling zbc_parse_auto()", __func__, __LINE__); dbg_lex("%s:%d calling zbc_parse_auto()", __func__, __LINE__);
s = zbc_parse_auto(p); s = zbc_parse_auto(p);
@ -4549,8 +4549,8 @@ static BC_STATUS zbc_parse_stmt_possibly_auto(BcParse *p, bool auto_allowed)
case BC_LEX_OP_DEC: case BC_LEX_OP_DEC:
case BC_LEX_OP_BOOL_NOT: case BC_LEX_OP_BOOL_NOT:
case BC_LEX_LPAREN: case BC_LEX_LPAREN:
case BC_LEX_NAME: case XC_LEX_NAME:
case BC_LEX_NUMBER: case XC_LEX_NUMBER:
case BC_LEX_KEY_IBASE: case BC_LEX_KEY_IBASE:
case BC_LEX_KEY_LAST: case BC_LEX_KEY_LAST:
case BC_LEX_KEY_LENGTH: case BC_LEX_KEY_LENGTH:
@ -4560,7 +4560,7 @@ static BC_STATUS zbc_parse_stmt_possibly_auto(BcParse *p, bool auto_allowed)
case BC_LEX_KEY_SQRT: case BC_LEX_KEY_SQRT:
s = zbc_parse_expr(p, BC_PARSE_PRINT); s = zbc_parse_expr(p, BC_PARSE_PRINT);
break; break;
case BC_LEX_STR: case XC_LEX_STR:
s = zbc_parse_pushSTR(p); s = zbc_parse_pushSTR(p);
bc_parse_push(p, XC_INST_PRINT_STR); bc_parse_push(p, XC_INST_PRINT_STR);
break; break;
@ -4738,7 +4738,7 @@ static BcStatus bc_parse_expr_empty_ok(BcParse *p, uint8_t flags)
get_token = bin_last = false; get_token = bin_last = false;
s = zbc_parse_rightParen(p, ops_bgn, &nexprs); s = zbc_parse_rightParen(p, ops_bgn, &nexprs);
break; break;
case BC_LEX_NAME: case XC_LEX_NAME:
if (BC_PARSE_LEAF(prev, rprn)) if (BC_PARSE_LEAF(prev, rprn))
return bc_error_bad_expression(); return bc_error_bad_expression();
paren_expr = true; paren_expr = true;
@ -4746,7 +4746,7 @@ static BcStatus bc_parse_expr_empty_ok(BcParse *p, uint8_t flags)
s = zbc_parse_name(p, &prev, flags & ~BC_PARSE_NOCALL); s = zbc_parse_name(p, &prev, flags & ~BC_PARSE_NOCALL);
++nexprs; ++nexprs;
break; break;
case BC_LEX_NUMBER: case XC_LEX_NUMBER:
if (BC_PARSE_LEAF(prev, rprn)) if (BC_PARSE_LEAF(prev, rprn))
return bc_error_bad_expression(); return bc_error_bad_expression();
bc_parse_pushNUM(p); bc_parse_pushNUM(p);
@ -4848,7 +4848,7 @@ static BC_STATUS zdc_parse_register(BcParse *p)
s = zbc_lex_next(&p->l); s = zbc_lex_next(&p->l);
if (s) RETURN_STATUS(s); 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); bc_parse_pushName(p, p->l.t.v.v);
@ -4948,7 +4948,7 @@ static BC_STATUS zdc_parse_token(BcParse *p, BcLexType t)
dbg_lex("%s:%d LEX_[S]COLON", __func__, __LINE__); dbg_lex("%s:%d LEX_[S]COLON", __func__, __LINE__);
s = zdc_parse_mem(p, XC_INST_ARRAY_ELEM, true, t == DC_LEX_COLON); s = zdc_parse_mem(p, XC_INST_ARRAY_ELEM, true, t == DC_LEX_COLON);
break; break;
case BC_LEX_STR: case XC_LEX_STR:
dbg_lex("%s:%d LEX_STR", __func__, __LINE__); dbg_lex("%s:%d LEX_STR", __func__, __LINE__);
dc_parse_string(p); dc_parse_string(p);
break; break;
@ -4956,12 +4956,12 @@ static BC_STATUS zdc_parse_token(BcParse *p, BcLexType t)
dbg_lex("%s:%d LEX_NEG", __func__, __LINE__); dbg_lex("%s:%d LEX_NEG", __func__, __LINE__);
s = zbc_lex_next(&p->l); s = zbc_lex_next(&p->l);
if (s) RETURN_STATUS(s); 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()); RETURN_STATUS(bc_error_bad_token());
bc_parse_pushNUM(p); bc_parse_pushNUM(p);
bc_parse_push(p, XC_INST_NEG); bc_parse_push(p, XC_INST_NEG);
break; break;
case BC_LEX_NUMBER: case XC_LEX_NUMBER:
dbg_lex("%s:%d LEX_NUMBER", __func__, __LINE__); dbg_lex("%s:%d LEX_NUMBER", __func__, __LINE__);
bc_parse_pushNUM(p); bc_parse_pushNUM(p);
break; break;
@ -5252,7 +5252,7 @@ static BC_STATUS zbc_program_read(void)
} }
if (s) goto exec_err; 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"); s = bc_error("bad read() expression");
goto exec_err; goto exec_err;
} }
@ -6733,7 +6733,7 @@ static BC_STATUS zbc_vm_process(const char *text)
} else { } else {
// Most of dc parsing assumes all whitespace, // Most of dc parsing assumes all whitespace,
// including '\n', is eaten. // 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); s = zbc_lex_next(&G.prs.l);
if (s) goto err; if (s) goto err;
if (G.prs.l.t.t == XC_LEX_EOF) if (G.prs.l.t.t == XC_LEX_EOF)