stage1 修复错误 提供类型检查
This commit is contained in:
@@ -203,6 +203,7 @@ spl_expr_result_t spl_parse_block_expr(spl_comp_t *ctx) {
|
||||
result = (spl_expr_result_t){0};
|
||||
} else {
|
||||
/* Expression — look ahead for assignment */
|
||||
usize before = ctx->tok_idx;
|
||||
int is_assign = lookahead_is_assign(ctx);
|
||||
int saved_addr = ctx->addr_of_mode;
|
||||
if (is_assign)
|
||||
@@ -210,6 +211,14 @@ spl_expr_result_t spl_parse_block_expr(spl_comp_t *ctx) {
|
||||
spl_expr_result_t expr = spl_parse_expr(ctx, PREC_MIN);
|
||||
ctx->addr_of_mode = saved_addr;
|
||||
|
||||
/* Safety: if no token was consumed, advance to prevent infinite loop */
|
||||
if (ctx->tok_idx == before) {
|
||||
advance(ctx);
|
||||
result = (spl_expr_result_t){0};
|
||||
skip_nl(ctx);
|
||||
continue;
|
||||
}
|
||||
|
||||
skip_nl(ctx);
|
||||
if (peek(ctx)->type == TOK_SEMICOLON || peek(ctx)->type == TOK_ENDLINE) {
|
||||
/* Expression statement: drop value, consume ; */
|
||||
@@ -1140,6 +1149,7 @@ void spl_parse_stmt(spl_comp_t *ctx) {
|
||||
parse_extern_decl(ctx);
|
||||
break;
|
||||
default:
|
||||
snprintf(ctx->parse_context, sizeof(ctx->parse_context), "expression statement");
|
||||
parse_expr_stmt(ctx);
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user