Lines Matching defs:p
59 bc_parse_else(BcParse* p);
62 bc_parse_stmt(BcParse* p);
65 bc_parse_expr_err(BcParse* p, uint8_t flags, BcParseNext next);
68 bc_parse_expr_status(BcParse* p, uint8_t flags, BcParseNext next);
90 * @param p The parser.
94 bc_parse_isDelimiter(const BcParse* p)
96 BcLexType t = p->l.t;
113 for (i = 0; i < p->flags.len && BC_PARSE_BLOCK_STMT(flags); ++i)
115 fptr = bc_vec_item_rev(&p->flags, i);
120 if ((flags & BC_PARSE_FLAG_BRACE) && p->l.last != BC_LEX_RBRACE)
134 for (i = 0; !good && i < p->flags.len; ++i)
136 uint16_t* fptr = bc_vec_item_rev(&p->flags, i);
148 * @param p The parser.
152 bc_parse_TopFunc(const BcParse* p)
154 bool good = p->flags.len == 2;
159 return good && BC_PARSE_TOP_FLAG(p) == val;
165 * @param p The parser.
168 bc_parse_setLabel(BcParse* p)
170 BcFunc* func = p->func;
171 BcInstPtr* ip = bc_vec_top(&p->exits);
174 assert(func == bc_vec_item(&p->prog->fns, p->fidx));
181 bc_vec_pop(&p->exits);
188 * @param p The parser.
192 bc_parse_createLabel(BcParse* p, size_t idx)
194 bc_vec_push(&p->func->labels, &idx);
200 * @param p The parser.
204 bc_parse_createCondLabel(BcParse* p, size_t idx)
206 bc_parse_createLabel(p, p->func->code.len);
207 bc_vec_push(&p->conds, &idx);
220 * @param p The parser.
225 bc_parse_createExitLabel(BcParse* p, size_t idx, bool loop)
229 assert(p->func == bc_vec_item(&p->prog->fns, p->fidx));
235 bc_vec_push(&p->exits, &ip);
236 bc_parse_createLabel(p, SIZE_MAX);
243 * @param p The parser.
252 bc_parse_operator(BcParse* p, BcLexType type, size_t start, size_t* nexprs)
259 while (p->ops.len > start)
262 t = BC_PARSE_TOP_OP(p);
282 bc_parse_push(p, BC_PARSE_TOKEN_INST(t));
283 bc_vec_pop(&p->ops);
287 bc_vec_push(&p->ops, &type);
294 * @param p The parser.
299 bc_parse_rightParen(BcParse* p, size_t* nexprs)
304 while ((top = BC_PARSE_TOP_OP(p)) != BC_LEX_LPAREN)
306 bc_parse_push(p, BC_PARSE_TOKEN_INST(top));
307 bc_vec_pop(&p->ops);
312 bc_vec_pop(&p->ops);
315 bc_lex_next(&p->l);
320 * @param p The parser.
325 bc_parse_args(BcParse* p, uint8_t flags)
330 bc_lex_next(&p->l);
338 for (nargs = 0; p->l.t != BC_LEX_RPAREN; ++nargs)
340 bc_parse_expr_status(p, flags, bc_parse_next_arg);
342 comma = (p->l.t == BC_LEX_COMMA);
343 if (comma) bc_lex_next(&p->l);
347 if (BC_ERR(comma)) bc_parse_err(p, BC_ERR_PARSE_TOKEN);
350 bc_parse_push(p, BC_INST_CALL);
351 bc_parse_pushIndex(p, nargs);
356 * @param p The parser.
361 bc_parse_call(BcParse* p, const char* name, uint8_t flags)
365 bc_parse_args(p, flags);
369 assert(p->l.t == BC_LEX_RPAREN);
373 idx = bc_map_index(&p->prog->fn_map, name);
379 idx = bc_program_insertFunc(p->prog, name);
384 p->func = bc_vec_item(&p->prog->fns, p->fidx);
387 else idx = ((BcId*) bc_vec_item(&p->prog->fn_map, idx))->idx;
389 bc_parse_pushIndex(p, idx);
392 bc_lex_next(&p->l);
398 * @param p The parser.
405 bc_parse_name(BcParse* p, BcInst* type, bool* can_assign, uint8_t flags)
412 name = bc_vm_strdup(p->l.str.v);
417 bc_lex_next(&p->l);
420 if (p->l.t == BC_LEX_LBRACKET)
422 bc_lex_next(&p->l);
425 if (p->l.t == BC_LEX_RBRACKET)
430 bc_parse_err(p, BC_ERR_PARSE_EXPR);
443 bc_parse_expr_status(p, flags2, bc_parse_next_elem);
446 if (BC_ERR(p->l.t != BC_LEX_RBRACKET))
448 bc_parse_err(p, BC_ERR_PARSE_TOKEN);
456 bc_lex_next(&p->l);
459 bc_parse_push(p, *type);
460 bc_parse_pushName(p, name, false);
462 else if (p->l.t == BC_LEX_LPAREN)
467 bc_parse_err(p, BC_ERR_PARSE_TOKEN);
473 bc_parse_call(p, name, flags);
480 bc_parse_push(p, BC_INST_VAR);
481 bc_parse_pushName(p, name, true);
494 * @param p The parser.
498 bc_parse_noArgBuiltin(BcParse* p, BcInst inst)
501 bc_lex_next(&p->l);
502 if (BC_ERR(p->l.t != BC_LEX_LPAREN)) bc_parse_err(p, BC_ERR_PARSE_TOKEN);
505 bc_lex_next(&p->l);
506 if ((p->l.t != BC_LEX_RPAREN)) bc_parse_err(p, BC_ERR_PARSE_TOKEN);
508 bc_parse_push(p, inst);
510 bc_lex_next(&p->l);
516 * @param p The parser.
522 bc_parse_builtin(BcParse* p, BcLexType type, uint8_t flags, BcInst* prev)
525 bc_lex_next(&p->l);
526 if (BC_ERR(p->l.t != BC_LEX_LPAREN)) bc_parse_err(p, BC_ERR_PARSE_TOKEN);
528 bc_lex_next(&p->l);
543 bc_parse_expr_status(p, flags, bc_parse_next_rel);
546 if (BC_ERR(p->l.t != BC_LEX_RPAREN)) bc_parse_err(p, BC_ERR_PARSE_TOKEN);
550 bc_parse_push(p, *prev);
552 bc_lex_next(&p->l);
558 * @param p The parser.
564 bc_parse_builtin3(BcParse* p, BcLexType type, uint8_t flags, BcInst* prev)
569 bc_lex_next(&p->l);
570 if (BC_ERR(p->l.t != BC_LEX_LPAREN)) bc_parse_err(p, BC_ERR_PARSE_TOKEN);
572 bc_lex_next(&p->l);
578 bc_parse_expr_status(p, flags, bc_parse_next_builtin);
581 if (BC_ERR(p->l.t != BC_LEX_COMMA)) bc_parse_err(p, BC_ERR_PARSE_TOKEN);
583 bc_lex_next(&p->l);
585 bc_parse_expr_status(p, flags, bc_parse_next_builtin);
588 if (BC_ERR(p->l.t != BC_LEX_COMMA)) bc_parse_err(p, BC_ERR_PARSE_TOKEN);
590 bc_lex_next(&p->l);
597 if (BC_ERR(p->l.t != BC_LEX_NAME)) bc_parse_err(p, BC_ERR_PARSE_TOKEN);
600 bc_lex_next(&p->l);
603 if (BC_ERR(p->l.t != BC_LEX_LBRACKET))
605 bc_parse_err(p, BC_ERR_PARSE_TOKEN);
609 bc_lex_next(&p->l);
612 if (BC_ERR(p->l.t != BC_LEX_RBRACKET))
614 bc_parse_err(p, BC_ERR_PARSE_TOKEN);
618 bc_lex_next(&p->l);
620 else bc_parse_expr_status(p, flags, bc_parse_next_rel);
623 if (BC_ERR(p->l.t != BC_LEX_RPAREN)) bc_parse_err(p, BC_ERR_PARSE_TOKEN);
627 bc_parse_push(p, *prev);
634 bc_parse_push(p, BC_INST_ZERO);
635 bc_parse_push(p, BC_INST_ARRAY_ELEM);
638 bc_parse_pushName(p, p->l.str.v, false);
642 bc_parse_push(p, BC_INST_SWAP);
643 bc_parse_push(p, BC_INST_ASSIGN_NO_VAL);
646 bc_lex_next(&p->l);
652 * @param p The parser.
659 bc_parse_scale(BcParse* p, BcInst* type, bool* can_assign, uint8_t flags)
661 bc_lex_next(&p->l);
664 if (p->l.t != BC_LEX_LPAREN)
669 bc_parse_push(p, BC_INST_SCALE);
681 bc_lex_next(&p->l);
683 bc_parse_expr_status(p, flags, bc_parse_next_rel);
686 if (BC_ERR(p->l.t != BC_LEX_RPAREN)) bc_parse_err(p, BC_ERR_PARSE_TOKEN);
688 bc_parse_push(p, BC_INST_SCALE_FUNC);
690 bc_lex_next(&p->l);
695 * @param p The parser.
704 bc_parse_incdec(BcParse* p, BcInst* prev, bool* can_assign, size_t* nexs,
710 BcLexType last = p->l.last;
718 bc_parse_err(p, BC_ERR_PARSE_ASSIGN);
725 if (!*can_assign) bc_parse_err(p, BC_ERR_PARSE_ASSIGN);
728 *prev = inst = BC_INST_INC + (p->l.t != BC_LEX_OP_INC);
729 bc_parse_push(p, inst);
730 bc_lex_next(&p->l);
737 *prev = inst = BC_INST_ASSIGN_PLUS + (p->l.t != BC_LEX_OP_INC);
739 bc_lex_next(&p->l);
740 type = p->l.t;
751 bc_parse_name(p, prev, can_assign, flags2 | BC_PARSE_NOCALL);
756 bc_parse_push(p, type - BC_LEX_KW_LAST + BC_INST_LAST);
757 bc_lex_next(&p->l);
762 bc_lex_next(&p->l);
765 if (BC_ERR(p->l.t == BC_LEX_LPAREN))
767 bc_parse_err(p, BC_ERR_PARSE_TOKEN);
769 else bc_parse_push(p, BC_INST_SCALE);
772 else bc_parse_err(p, BC_ERR_PARSE_TOKEN);
776 bc_parse_push(p, BC_INST_ONE);
777 bc_parse_push(p, inst);
784 * @param p The parser.
792 bc_parse_minus(BcParse* p, BcInst* prev, size_t ops_bgn, bool rparen,
797 bc_lex_next(&p->l);
805 if (type != BC_LEX_OP_MINUS) bc_vec_push(&p->ops, &type);
806 else bc_parse_operator(p, type, ops_bgn, nexprs);
811 * @param p The parser.
816 bc_parse_str(BcParse* p, BcInst inst)
818 bc_parse_addString(p);
819 bc_parse_push(p, inst);
820 bc_lex_next(&p->l);
825 * @param p The parser.
828 bc_parse_print(BcParse* p, BcLexType type)
835 bc_lex_next(&p->l);
837 t = p->l.t;
840 if (bc_parse_isDelimiter(p)) bc_parse_err(p, BC_ERR_PARSE_PRINT);
846 if (t == BC_LEX_STR) bc_parse_str(p, inst);
850 bc_parse_expr_status(p, BC_PARSE_NEEDVAL, bc_parse_next_print);
851 bc_parse_push(p, inst);
855 comma = (p->l.t == BC_LEX_COMMA);
858 if (comma) bc_lex_next(&p->l);
862 if (!bc_parse_isDelimiter(p)) bc_parse_err(p, BC_ERR_PARSE_TOKEN);
866 t = p->l.t;
871 if (BC_ERR(comma)) bc_parse_err(p, BC_ERR_PARSE_TOKEN);
876 * @param p The parser.
879 bc_parse_return(BcParse* p)
886 if (BC_ERR(!BC_PARSE_FUNC(p))) bc_parse_err(p, BC_ERR_PARSE_TOKEN);
889 if (p->func->voidfn) inst = BC_INST_RET_VOID;
891 bc_lex_next(&p->l);
893 t = p->l.t;
897 if (bc_parse_isDelimiter(p)) bc_parse_push(p, inst);
903 s = bc_parse_expr_err(p, BC_PARSE_NEEDVAL, bc_parse_next_expr);
908 bc_parse_push(p, inst);
909 bc_lex_next(&p->l);
913 if (!paren || p->l.last != BC_LEX_RPAREN)
915 bc_parse_err(p, BC_ERR_POSIX_RET);
919 if (BC_ERR(p->func->voidfn))
923 bc_parse_verr(p, BC_ERR_PARSE_RET_VOID, p->func->name);
928 else bc_parse_push(p, BC_INST_RET);
935 * @param p The parser.
938 bc_parse_noElse(BcParse* p)
940 uint16_t* flag_ptr = BC_PARSE_TOP_FLAG_PTR(p);
942 bc_parse_setLabel(p);
947 * @param p The parser.
951 bc_parse_endBody(BcParse* p, bool brace)
956 if (BC_ERR(p->flags.len <= 1)) bc_parse_err(p, BC_ERR_PARSE_TOKEN);
962 assert(p->l.t == BC_LEX_RBRACE);
964 bc_lex_next(&p->l);
967 if (BC_ERR(!bc_parse_isDelimiter(p) && !bc_parse_TopFunc(p)))
969 bc_parse_err(p, BC_ERR_PARSE_TOKEN);
974 has_brace = (BC_PARSE_BRACE(p) != 0);
978 size_t len = p->flags.len;
982 if (has_brace && !brace) bc_parse_err(p, BC_ERR_PARSE_TOKEN);
985 loop = (BC_PARSE_LOOP_INNER(p) != 0);
988 if (loop || BC_PARSE_ELSE(p))
993 size_t* label = bc_vec_top(&p->conds);
995 bc_parse_push(p, BC_INST_JUMP);
996 bc_parse_pushIndex(p, *label);
998 bc_vec_pop(&p->conds);
1001 bc_parse_setLabel(p);
1002 bc_vec_pop(&p->flags);
1005 else if (BC_PARSE_FUNC_INNER(p))
1007 BcInst inst = (p->func->voidfn ? BC_INST_RET_VOID : BC_INST_RET0);
1008 bc_parse_push(p, inst);
1009 bc_parse_updateFunc(p, BC_PROG_MAIN);
1010 bc_vec_pop(&p->flags);
1014 else if (has_brace && !BC_PARSE_IF(p)) bc_vec_pop(&p->flags);
1017 if (BC_PARSE_IF(p) && (len == p->flags.len || !BC_PARSE_BRACE(p)))
1020 while (p->l.t == BC_LEX_NLINE)
1022 bc_lex_next(&p->l);
1026 bc_vec_pop(&p->flags);
1032 *(BC_PARSE_TOP_FLAG_PTR(p)) |= BC_PARSE_FLAG_IF_END;
1033 new_else = (p->l.t == BC_LEX_KW_ELSE);
1036 if (new_else) bc_parse_else(p);
1037 else if (!has_brace && (!BC_PARSE_IF_END(p) || brace))
1039 bc_parse_noElse(p);
1043 else bc_parse_noElse(p);
1054 while (p->flags.len > 1 && !new_else && (!BC_PARSE_IF_END(p) || brace) &&
1055 !(has_brace = (BC_PARSE_BRACE(p) != 0)));
1058 if (BC_ERR(p->flags.len == 1 && brace)) bc_parse_err(p, BC_ERR_PARSE_TOKEN);
1059 else if (brace && BC_PARSE_BRACE(p))
1062 uint16_t flags = BC_PARSE_TOP_FLAG(p);
1070 bc_vec_pop(&p->flags);
1077 * @param p The parser.
1081 bc_parse_startBody(BcParse* p, uint16_t flags)
1084 flags |= (BC_PARSE_TOP_FLAG(p) & (BC_PARSE_FLAG_FUNC | BC_PARSE_FLAG_LOOP));
1086 bc_vec_push(&p->flags, &flags);
1090 bc_parse_endif(BcParse* p)
1096 if (BC_NO_ERR(!BC_PARSE_NO_EXEC(p))) return;
1102 for (i = 0; good && i < p->flags.len; ++i)
1104 uint16_t flag = *((uint16_t*) bc_vec_item(&p->flags, i));
1118 while (p->flags.len > 1 || BC_PARSE_IF_END(p))
1120 if (BC_PARSE_IF_END(p)) bc_parse_noElse(p);
1121 if (p->flags.len > 1) bc_parse_endBody(p, false);
1132 * @param p The parser.
1135 bc_parse_if(BcParse* p)
1142 bc_lex_next(&p->l);
1143 if (BC_ERR(p->l.t != BC_LEX_LPAREN)) bc_parse_err(p, BC_ERR_PARSE_TOKEN);
1146 bc_lex_next(&p->l);
1147 bc_parse_expr_status(p, flags, bc_parse_next_rel);
1150 if (BC_ERR(p->l.t != BC_LEX_RPAREN)) bc_parse_err(p, BC_ERR_PARSE_TOKEN);
1152 bc_lex_next(&p->l);
1155 bc_parse_push(p, BC_INST_JUMP_ZERO);
1157 idx = p->func->labels.len;
1161 bc_parse_pushIndex(p, idx);
1162 bc_parse_createExitLabel(p, idx, false);
1164 bc_parse_startBody(p, BC_PARSE_FLAG_IF);
1169 * @param p The parser.
1172 bc_parse_else(BcParse* p)
1174 size_t idx = p->func->labels.len;
1177 if (BC_ERR(!BC_PARSE_IF_END(p))) bc_parse_err(p, BC_ERR_PARSE_TOKEN);
1181 bc_parse_push(p, BC_INST_JUMP);
1182 bc_parse_pushIndex(p, idx);
1186 bc_parse_noElse(p);
1189 bc_parse_createExitLabel(p, idx, false);
1190 bc_parse_startBody(p, BC_PARSE_FLAG_ELSE);
1192 bc_lex_next(&p->l);
1197 * @param p The parser.
1200 bc_parse_while(BcParse* p)
1207 bc_lex_next(&p->l);
1208 if (BC_ERR(p->l.t != BC_LEX_LPAREN)) bc_parse_err(p, BC_ERR_PARSE_TOKEN);
1209 bc_lex_next(&p->l);
1212 bc_parse_createCondLabel(p, p->func->labels.len);
1213 idx = p->func->labels.len;
1214 bc_parse_createExitLabel(p, idx, true);
1217 bc_parse_expr_status(p, flags, bc_parse_next_rel);
1218 if (BC_ERR(p->l.t != BC_LEX_RPAREN)) bc_parse_err(p, BC_ERR_PARSE_TOKEN);
1219 bc_lex_next(&p->l);
1222 bc_parse_push(p, BC_INST_JUMP_ZERO);
1223 bc_parse_pushIndex(p, idx);
1224 bc_parse_startBody(p, BC_PARSE_FLAG_LOOP | BC_PARSE_FLAG_LOOP_INNER);
1229 * @param p The parser.
1232 bc_parse_for(BcParse* p)
1237 bc_lex_next(&p->l);
1238 if (BC_ERR(p->l.t != BC_LEX_LPAREN)) bc_parse_err(p, BC_ERR_PARSE_TOKEN);
1239 bc_lex_next(&p->l);
1243 if (p->l.t != BC_LEX_SCOLON) bc_parse_expr_status(p, 0, bc_parse_next_for);
1244 else bc_parse_err(p, BC_ERR_POSIX_FOR);
1247 if (BC_ERR(p->l.t != BC_LEX_SCOLON)) bc_parse_err(p, BC_ERR_PARSE_TOKEN);
1248 bc_lex_next(&p->l);
1254 cond_idx = p->func->labels.len;
1260 bc_parse_createLabel(p, p->func->code.len);
1263 if (p->l.t != BC_LEX_SCOLON)
1266 bc_parse_expr_status(p, flags, bc_parse_next_for);
1274 bc_vec_string(&p->l.str, sizeof(bc_parse_one) - 1, bc_parse_one);
1275 bc_parse_number(p);
1278 bc_parse_err(p, BC_ERR_POSIX_FOR);
1282 if (BC_ERR(p->l.t != BC_LEX_SCOLON)) bc_parse_err(p, BC_ERR_PARSE_TOKEN);
1283 bc_lex_next(&p->l);
1289 bc_parse_push(p, BC_INST_JUMP_ZERO);
1290 bc_parse_pushIndex(p, exit_idx);
1291 bc_parse_push(p, BC_INST_JUMP);
1292 bc_parse_pushIndex(p, body_idx);
1295 bc_parse_createCondLabel(p, update_idx);
1298 if (p->l.t != BC_LEX_RPAREN) bc_parse_expr_status(p, 0, bc_parse_next_rel);
1299 else bc_parse_err(p, BC_ERR_POSIX_FOR);
1302 if (BC_ERR(p->l.t != BC_LEX_RPAREN)) bc_parse_err(p, BC_ERR_PARSE_TOKEN);
1305 bc_parse_push(p, BC_INST_JUMP);
1306 bc_parse_pushIndex(p, cond_idx);
1307 bc_parse_createLabel(p, p->func->code.len);
1310 bc_parse_createExitLabel(p, exit_idx, true);
1311 bc_lex_next(&p->l);
1312 bc_parse_startBody(p, BC_PARSE_FLAG_LOOP | BC_PARSE_FLAG_LOOP_INNER);
1318 * @param p The parser.
1322 bc_parse_loopExit(BcParse* p, BcLexType type)
1328 if (BC_ERR(!BC_PARSE_LOOP(p))) bc_parse_err(p, BC_ERR_PARSE_TOKEN);
1334 if (BC_ERR(!p->exits.len)) bc_parse_err(p, BC_ERR_PARSE_TOKEN);
1337 i = p->exits.len - 1;
1338 ip = bc_vec_item(&p->exits, i);
1342 while (!ip->func && i < p->exits.len)
1344 ip = bc_vec_item(&p->exits, i);
1349 assert(ip != NULL && (i < p->exits.len || ip->func));
1356 else i = *((size_t*) bc_vec_top(&p->conds));
1359 bc_parse_push(p, BC_INST_JUMP);
1360 bc_parse_pushIndex(p, i);
1362 bc_lex_next(&p->l);
1367 * @param p The parser.
1370 bc_parse_func(BcParse* p)
1376 bc_lex_next(&p->l);
1379 if (BC_ERR(p->l.t != BC_LEX_NAME)) bc_parse_err(p, BC_ERR_PARSE_FUNC);
1382 voidfn = (!BC_IS_POSIX && p->l.t == BC_LEX_NAME &&
1383 !strcmp(p->l.str.v, "void"));
1387 bc_lex_next(&p->l);
1390 voidfn = (voidfn && p->l.t == BC_LEX_NAME);
1395 bc_parse_err(p, BC_ERR_POSIX_VOID);
1399 bc_lex_next(&p->l);
1403 if (BC_ERR(p->l.t != BC_LEX_LPAREN)) bc_parse_err(p, BC_ERR_PARSE_FUNC);
1406 assert(p->prog->fns.len == p->prog->fn_map.len);
1409 idx = bc_program_insertFunc(p->prog, p->l.str.v);
1415 bc_parse_updateFunc(p, idx);
1416 p->func->voidfn = voidfn;
1418 bc_lex_next(&p->l);
1421 while (p->l.t != BC_LEX_RPAREN)
1426 if (p->l.t == BC_LEX_OP_MULTIPLY)
1429 bc_lex_next(&p->l);
1432 bc_parse_err(p, BC_ERR_POSIX_REF);
1436 if (BC_ERR(p->l.t != BC_LEX_NAME)) bc_parse_err(p, BC_ERR_PARSE_FUNC);
1439 p->func->nparams += 1;
1442 bc_vec_string(&p->buf, p->l.str.len, p->l.str.v);
1444 bc_lex_next(&p->l);
1447 if (p->l.t == BC_LEX_LBRACKET)
1452 bc_lex_next(&p->l);
1455 if (BC_ERR(p->l.t != BC_LEX_RBRACKET))
1457 bc_parse_err(p, BC_ERR_PARSE_FUNC);
1460 bc_lex_next(&p->l);
1466 bc_parse_verr(p, BC_ERR_PARSE_REF_VAR, p->buf.v);
1470 comma = (p->l.t == BC_LEX_COMMA);
1471 if (comma) bc_lex_next(&p->l);
1474 bc_func_insert(p->func, p->prog, p->buf.v, t, p->l.line);
1478 if (BC_ERR(comma)) bc_parse_err(p, BC_ERR_PARSE_FUNC);
1482 bc_parse_startBody(p, flags);
1484 bc_lex_next(&p->l);
1488 if (p->l.t != BC_LEX_LBRACE) bc_parse_err(p, BC_ERR_POSIX_BRACE);
1493 * @param p The parser.
1496 bc_parse_auto(BcParse* p)
1501 if (BC_ERR(!p->auto_part)) bc_parse_err(p, BC_ERR_PARSE_TOKEN);
1502 bc_lex_next(&p->l);
1504 p->auto_part = comma = false;
1507 one = (p->l.t == BC_LEX_NAME);
1510 while (p->l.t == BC_LEX_NAME)
1515 bc_vec_string(&p->buf, p->l.str.len - 1, p->l.str.v);
1517 bc_lex_next(&p->l);
1520 if (p->l.t == BC_LEX_LBRACKET)
1524 bc_lex_next(&p->l);
1527 if (BC_ERR(p->l.t != BC_LEX_RBRACKET))
1529 bc_parse_err(p, BC_ERR_PARSE_FUNC);
1532 bc_lex_next(&p->l);
1537 comma = (p->l.t == BC_LEX_COMMA);
1538 if (comma) bc_lex_next(&p->l);
1541 bc_func_insert(p->func, p->prog, p->buf.v, t, p->l.line);
1545 if (BC_ERR(comma)) bc_parse_err(p, BC_ERR_PARSE_FUNC);
1548 if (BC_ERR(!one)) bc_parse_err(p, BC_ERR_PARSE_NO_AUTO);
1551 if (BC_ERR(!bc_parse_isDelimiter(p))) bc_parse_err(p, BC_ERR_PARSE_TOKEN);
1556 * @param p The parser.
1560 bc_parse_body(BcParse* p, bool brace)
1562 uint16_t* flag_ptr = BC_PARSE_TOP_FLAG_PTR(p);
1565 assert(p->flags.len >= 2);
1576 if (BC_ERR(!brace)) bc_parse_err(p, BC_ERR_PARSE_TOKEN);
1578 p->auto_part = (p->l.t != BC_LEX_KW_AUTO);
1580 if (!p->auto_part)
1583 p->auto_part = true;
1586 bc_parse_auto(p);
1590 if (p->l.t == BC_LEX_NLINE) bc_lex_next(&p->l);
1595 size_t len = p->flags.len;
1600 bc_parse_stmt(p);
1606 if (!brace && !BC_PARSE_BODY(p) && len <= p->flags.len)
1608 bc_parse_endBody(p, false);
1616 * @param p The parser.
1619 bc_parse_stmt(BcParse* p)
1623 BcLexType type = p->l.t;
1628 bc_lex_next(&p->l);
1635 bc_parse_auto(p);
1640 p->auto_part = false;
1647 if (BC_PARSE_IF_END(p))
1651 bc_parse_noElse(p);
1652 if (p->flags.len > 1 && !BC_PARSE_BRACE(p))
1654 bc_parse_endBody(p, false);
1663 if (!BC_PARSE_BODY(p))
1665 bc_parse_startBody(p, BC_PARSE_FLAG_BRACE);
1666 bc_lex_next(&p->l);
1673 *(BC_PARSE_TOP_FLAG_PTR(p)) |= BC_PARSE_FLAG_BRACE;
1674 bc_lex_next(&p->l);
1675 bc_parse_body(p, true);
1685 else if (BC_PARSE_BODY(p) && !BC_PARSE_BRACE(p))
1687 bc_parse_body(p, false);
1692 len = p->flags.len;
1693 flags = BC_PARSE_TOP_FLAG(p);
1737 bc_parse_expr_status(p, BC_PARSE_PRINT, bc_parse_next_expr);
1743 bc_parse_else(p);
1756 bc_parse_endBody(p, true);
1762 bc_parse_str(p, BC_INST_PRINT_STR);
1769 bc_parse_loopExit(p, p->l.t);
1775 bc_parse_for(p);
1781 bc_parse_push(p, BC_INST_HALT);
1782 bc_lex_next(&p->l);
1788 bc_parse_if(p);
1812 bc_lex_next(&p->l);
1820 bc_parse_print(p, type);
1835 bc_parse_return(p);
1841 bc_parse_while(p);
1918 bc_parse_err(p, BC_ERR_PARSE_TOKEN);
1923 if (len == p->flags.len && flags == BC_PARSE_TOP_FLAG(p))
1925 if (BC_ERR(!bc_parse_isDelimiter(p)))
1927 bc_parse_err(p, BC_ERR_PARSE_TOKEN);
1932 while (p->l.t == BC_LEX_SCOLON || p->l.t == BC_LEX_NLINE)
1934 bc_lex_next(&p->l);
1940 if (p->l.last == BC_LEX_SCOLON && p->l.t == BC_LEX_KW_DEFINE && BC_IS_POSIX)
1942 bc_parse_err(p, BC_ERR_POSIX_FUNC_AFTER_SEMICOLON);
1947 bc_parse_parse(BcParse* p)
1949 assert(p);
1955 if (BC_ERR(p->l.t == BC_LEX_EOF)) bc_parse_err(p, BC_ERR_PARSE_EOF);
1958 else if (p->l.t == BC_LEX_KW_DEFINE)
1960 if (BC_ERR(BC_PARSE_NO_EXEC(p)))
1962 bc_parse_endif(p);
1963 if (BC_ERR(BC_PARSE_NO_EXEC(p)))
1965 bc_parse_err(p, BC_ERR_PARSE_TOKEN);
1968 bc_parse_func(p);
1972 else bc_parse_stmt(p);
1979 bc_parse_reset(p);
1989 * @param p The parser.
1998 bc_parse_expr_err(BcParse* p, uint8_t flags, BcParseNext next)
2030 t = p->l.t;
2031 pfirst = (p->l.t == BC_LEX_LPAREN);
2034 ops_bgn = p->ops.len;
2042 while ((t = p->l.t) == BC_LEX_NLINE)
2044 bc_lex_next(&p->l);
2049 for (; !done && BC_PARSE_EXPR(t); t = p->l.t)
2056 bc_parse_err(p, BC_ERR_PARSE_EXPR);
2066 if (BC_ERR(incdec)) bc_parse_err(p, BC_ERR_PARSE_ASSIGN);
2068 bc_parse_incdec(p, &prev, &can_assign, &nexprs, flags);
2084 bc_parse_err(p, BC_ERR_PARSE_TOKEN);
2089 bc_parse_push(p, BC_INST_TRUNC);
2101 bc_parse_minus(p, &prev, ops_bgn, rprn, bin_last, &nexprs);
2132 bc_parse_err(p, BC_ERR_PARSE_ASSIGN);
2165 if (BC_ERR(!bin_last && !BC_PARSE_OP_PREFIX(p->l.last)))
2167 bc_parse_err(p, BC_ERR_PARSE_EXPR);
2175 bc_parse_err(p, BC_ERR_PARSE_EXPR);
2181 bc_parse_operator(p, t, ops_bgn, &nexprs);
2196 bc_parse_err(p, BC_ERR_PARSE_EXPR);
2204 bc_vec_push(&p->ops, &t);
2213 if (BC_ERR(p->l.last == BC_LEX_LPAREN))
2222 bc_parse_err(p, BC_ERR_PARSE_EXPR);
2239 bc_parse_err(p, BC_ERR_PARSE_EXPR);
2246 bc_parse_rightParen(p, &nexprs);
2254 if (BC_IS_POSIX) bc_parse_err(p, BC_ERR_POSIX_EXPR_STRING);
2259 bc_parse_err(p, BC_ERR_PARSE_EXPR);
2262 bc_parse_addString(p);
2276 bc_parse_err(p, BC_ERR_PARSE_EXPR);
2281 bc_parse_name(p, &prev, &can_assign, flags & ~BC_PARSE_NOCALL);
2296 bc_parse_err(p, BC_ERR_PARSE_EXPR);
2300 bc_parse_number(p);
2321 bc_parse_err(p, BC_ERR_PARSE_EXPR);
2325 bc_parse_push(p, prev);
2348 bc_parse_err(p, BC_ERR_PARSE_EXPR);
2351 bc_parse_builtin(p, t, flags, &prev);
2377 bc_parse_err(p, BC_ERR_PARSE_EXPR);
2383 bc_parse_err(p, BC_ERR_EXEC_REC_READ);
2387 bc_parse_noArgBuiltin(p, prev);
2401 bc_parse_err(p, BC_ERR_PARSE_EXPR);
2406 bc_parse_scale(p, &prev, &can_assign, flags);
2421 bc_parse_err(p, BC_ERR_PARSE_EXPR);
2424 bc_parse_builtin3(p, t, flags, &prev);
2488 bc_parse_err(p, BC_ERR_PARSE_TOKEN);
2494 if (get_token) bc_lex_next(&p->l);
2499 while (p->ops.len > ops_bgn)
2501 top = BC_PARSE_TOP_OP(p);
2507 bc_parse_err(p, BC_ERR_PARSE_EXPR);
2510 bc_parse_push(p, BC_PARSE_TOKEN_INST(top));
2514 bc_vec_pop(&p->ops);
2520 if (BC_ERR(nexprs != 1)) bc_parse_err(p, BC_ERR_PARSE_EXPR);
2527 if (BC_ERR(i == next.len && !bc_parse_isDelimiter(p)))
2529 bc_parse_err(p, BC_ERR_PARSE_EXPR);
2535 bc_parse_err(p, BC_ERR_POSIX_REL_POS);
2539 bc_parse_err(p, BC_ERR_POSIX_MULTIREL);
2551 inst = *((uchar*) bc_vec_top(&p->func->code));
2559 inst = *((uchar*) bc_vec_top(&p->func->code));
2575 bc_vec_pop(&p->func->code);
2576 if (incdec) bc_parse_push(p, BC_INST_ONE);
2577 bc_parse_push(p, inst);
2586 if (pfirst || !assign) bc_parse_push(p, BC_INST_PRINT);
2594 bc_parse_push(p, BC_INST_POP);
2608 while (p->l.t == BC_LEX_NLINE)
2610 bc_lex_next(&p->l);
2620 * @param p The parser.
2625 bc_parse_expr_status(BcParse* p, uint8_t flags, BcParseNext next)
2627 BcParseStatus s = bc_parse_expr_err(p, flags, next);
2631 bc_parse_err(p, BC_ERR_PARSE_EMPTY_EXPR);
2636 bc_parse_expr(BcParse* p, uint8_t flags)
2638 assert(p);
2639 bc_parse_expr_status(p, flags, bc_parse_next_read);