feat(parser): 改进解析器错误处理和表达式解析逻辑

- 在初始化解析中添加缺失的赋值操作符检查
- 改进后缀表达式解析逻辑,处理嵌套情况
- 添加数组下标初始化的赋值操作符验证
- 修复主表达式解析中的返回语句处理

refactor(pproc): 优化预处理器宏展开和位置追踪

- 添加token复制函数来保持原始位置信息
- 重构宏展开函数参数传递方式
- 修复字符串化参数的位置信息处理
- 改进可变参数宏的处理逻辑

test(parser): 增加标签语句和字符串字面量测试用例

- 添加返回语句with复合字面量的测试
- 增加标签继续语句的测试用例
- 添加字符串连接的解析测试

test(pproc): 添加预处理器位置追踪测试

- 增加双重宏定义位置追踪测试
- 添加带参数宏定义位置追踪测试
- 增加字符串化操作位置追踪测试

docs: 更新代码中的宏定义和注释

- 修正未定义标识符的拼写错误
- 添加必要的头文件包含
- 改进错误消息提示文本
This commit is contained in:
zzy
2026-03-13 13:48:55 +08:00
parent 2d1032c363
commit c99f64708e
14 changed files with 260 additions and 60 deletions

View File

@@ -198,13 +198,21 @@ scc_ast_expr_t *scc_parse_initializer(scc_parser_t *parser,
scc_parser_next_consume(parser, null);
tok_ptr = scc_parser_peek(parser);
if (tok_ptr && tok_ptr->type == SCC_TOK_IDENT) {
scc_parser_next(parser);
lhs = scc_malloc(sizeof(scc_ast_expr_t));
Assert(lhs != null);
scc_ast_expr_member_init(lhs, base,
scc_cstring_as_cstr(&tok_ptr->lexeme));
if (!scc_parser_consume_if(parser, SCC_TOK_ASSIGN)) {
SCC_ERROR(scc_parser_got_current_pos(parser),
"Expected '='");
}
rhs = scc_parse_initializer(parser, lhs);
Assert(rhs != null);
if (rhs == null) {
SCC_ERROR(scc_parser_got_current_pos(parser),
"Expected initializer");
Panic();
}
scc_vec_push(lhs_exprs, lhs);
scc_vec_push(rhs_exprs, rhs);
} else {
@@ -221,7 +229,9 @@ scc_ast_expr_t *scc_parse_initializer(scc_parser_t *parser,
lhs = scc_malloc(sizeof(scc_ast_expr_t));
Assert(lhs != null);
scc_ast_expr_array_subscript_init(lhs, base, idx);
if (!scc_parser_consume_if(parser, SCC_TOK_ASSIGN)) {
SCC_ERROR(scc_parser_got_current_pos(parser), "Expected '='");
}
rhs = scc_parse_initializer(parser, lhs);
Assert(rhs != null);
scc_vec_push(lhs_exprs, lhs);
@@ -230,6 +240,7 @@ scc_ast_expr_t *scc_parse_initializer(scc_parser_t *parser,
scc_parser_next_consume(parser, null);
break;
} else if (tok_ptr->type == SCC_TOK_COMMA) {
scc_parser_next_consume(parser, null);
continue;
} else {
// FIXME