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

@@ -226,12 +226,18 @@ int main(int argc, const char **argv, const char **envp) {
LOG_FATAL("Failed to open file %s", config.output_file);
return 1;
}
} else {
fp = scc_stdout;
}
}
int error_code = 0;
cbool need_end = false;
scc_sstream_t sstream;
if (scc_sstream_init(&sstream, config.input_file, 1024)) {
return 0;
error_code = scc_sstream_init(&sstream, config.input_file, 1024);
if (error_code) {
goto sstream_drop;
need_end = true;
}
scc_lexer_t lexer;
@@ -244,11 +250,14 @@ int main(int argc, const char **argv, const char **envp) {
} else {
print_file(tok_ring, fp);
}
return 0;
need_end = true;
goto lexer_drop;
}
scc_pproc_t pproc;
scc_pproc_init(&pproc, scc_lexer_to_ring(&lexer, 8, true));
// FIXME maybe using config to got download path and add include path
scc_pproc_add_include_path_cstr(&pproc, "./.scc_include");
scc_vec_foreach(config.include_paths, i) {
scc_pproc_add_include_path_cstr(&pproc,
scc_vec_at(config.include_paths, i));
@@ -266,10 +275,12 @@ int main(int argc, const char **argv, const char **envp) {
} else {
print_file(tok_ring, fp);
}
return 0;
need_end = true;
goto pproc_drop;
}
scc_lexer_tok_ring_t *tok_ring = scc_pproc_to_ring(&pproc, 8, false, false);
scc_lexer_tok_ring_t *tok_ring =
scc_pproc_to_ring(&pproc, 1024, false, false);
scc_parser_t parser;
scc_sema_callbacks_t sema_callbacks;
scc_sema_init(&sema_callbacks);
@@ -279,9 +290,15 @@ int main(int argc, const char **argv, const char **envp) {
scc_sema_drop(&sema_callbacks);
scc_parser_drop(&parser);
pproc_drop:
scc_pproc_drop(&pproc);
lexer_drop:
scc_lexer_drop(&lexer);
sstream_drop:
scc_sstream_drop(&sstream);
if (error_code || need_end) {
return error_code;
}
if (config.emit_ast) {
scc_tree_dump_ctx_t tree_dump;
@@ -312,6 +329,6 @@ int main(int argc, const char **argv, const char **envp) {
// return 0;
// }
scc_printf("output exe at %s", config.output_file);
scc_printf("output exe at %s\n", config.output_file);
return 0;
}