feat(parser): 启用parser和ast模块并重构解析器结构
- 在cbuild.toml中启用parser和ast依赖项 - 将AST内置类型枚举重命名为SCC_AST_BUILTIN_TYPE_*前缀格式 - 修复ast_def.h中的类型字段命名,将builtin改为type - 添加逗号操作符支持到表达式操作符枚举中 - 更新字面量表达式的lexeme字段为const char*指针和owned标志 - 重构解析器头文件结构,分离为parser.h、parser_utils.h、scc_sema.h等 - 实现新的解析器工具函数,包括预览、消费、回溯等功能 - 更新声明解析逻辑,使用新的解析器接口进行token处理 - 添加符号表语义分析功能框架 - 修复词法分析器中token移动时的空指针检查 - 统一使用scc_tree_dump_printf替代直接的scc_printf调用
This commit is contained in:
43
src/main.c
43
src/main.c
@@ -2,8 +2,8 @@
|
||||
#include <scc_lexer.h>
|
||||
#include <scc_pproc.h>
|
||||
|
||||
// #include <scc_parser.h>
|
||||
// #include <ast_dump.h>
|
||||
#include <ast_dump.h>
|
||||
#include <scc_parser.h>
|
||||
// #include <ir_dump.h>
|
||||
// #include <scc_ast2ir.h>
|
||||
|
||||
@@ -195,12 +195,11 @@ int main(int argc, const char **argv, const char **envp) {
|
||||
SetConsoleCP(CP_UTF8);
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
#define OUTPUT_DEFAULT_FILE "a.exe"
|
||||
#else
|
||||
#define OUTPUT_DEFAULT_FILE "a.out"
|
||||
#ifndef SCC_DEFAULT_ARGPARSE_LANG
|
||||
#define SCC_DEFAULT_ARGPARSE_LANG SCC_ARGPARSE_LANG_ZH
|
||||
#endif
|
||||
scc_argparse_lang_t argparse_lang = SCC_ARGPARSE_LANG_EN;
|
||||
|
||||
scc_argparse_lang_t argparse_lang = SCC_DEFAULT_ARGPARSE_LANG;
|
||||
for (const char **env = envp; *env != null; env++) {
|
||||
const char *env_str = *env;
|
||||
if (scc_strcmp(env_str, "LANG=zh_CN.UTF-8") == 0) {
|
||||
@@ -256,7 +255,8 @@ int main(int argc, const char **argv, const char **envp) {
|
||||
scc_pproc_add_object_macro(&(pproc.macro_table), &pproc_macro_name,
|
||||
&pproc_tok_vec);
|
||||
if (config.emit_pp) {
|
||||
scc_lexer_tok_ring_t *tok_ring = scc_pproc_to_ring(&pproc, 8);
|
||||
scc_lexer_tok_ring_t *tok_ring =
|
||||
scc_pproc_to_ring(&pproc, 8, true, true);
|
||||
if (config.output_file == null) {
|
||||
print_ring(tok_ring, config.verbose);
|
||||
} else {
|
||||
@@ -265,22 +265,25 @@ int main(int argc, const char **argv, const char **envp) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
scc_lexer_tok_ring_t *tok_ring = scc_pproc_to_ring(&pproc, 8, false, false);
|
||||
scc_parser_t parser;
|
||||
scc_parser_init(&parser, tok_ring, null);
|
||||
scc_ast_translation_unit_t *translation_unit =
|
||||
scc_parse_translation_unit(&parser);
|
||||
|
||||
scc_parser_drop(&parser);
|
||||
scc_pproc_drop(&pproc);
|
||||
scc_lexer_drop(&lexer);
|
||||
scc_sstream_drop(&sstream);
|
||||
|
||||
// scc_parser_t parser;
|
||||
// scc_parser_init(&parser, &lexer_stream, null);
|
||||
// scc_ast_translation_unit_t *translation_unit =
|
||||
// scc_parse_translation_unit(&parser);
|
||||
|
||||
// if (config.emit_ast) {
|
||||
// scc_tree_dump_ctx_t tree_dump;
|
||||
// scc_tree_dump_ctx_init(&tree_dump, true);
|
||||
// scc_ast_dump_node(&tree_dump, (scc_ast_node_t *)translation_unit);
|
||||
// scc_tree_dump_ctx_drop(&tree_dump);
|
||||
// return 0;
|
||||
// }
|
||||
if (config.emit_ast) {
|
||||
scc_tree_dump_ctx_t tree_dump;
|
||||
scc_tree_dump_ctx_init(&tree_dump, true, (void *)scc_fprintf,
|
||||
(void *)scc_stdout);
|
||||
scc_ast_dump_node(&tree_dump, (scc_ast_node_t *)translation_unit);
|
||||
scc_tree_dump_ctx_drop(&tree_dump);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// scc_ir_builder_t ir_builder;
|
||||
// scc_ast2ir(translation_unit, &ir_builder);
|
||||
|
||||
Reference in New Issue
Block a user