feat(lexer): 添加预处理器关键字支持并优化词法分析器

添加了完整的C预处理器关键字表,包括define、include、ifdef等关键字,
用于支持预处理器功能。

- 新增SCC_PPKEYWORD_TABLE宏定义所有预处理器关键字
- 在token类型枚举中包含预处理关键字
- 重构词法分析器以正确识别预处理关键字
- 添加scc_lexer_tok_drop函数用于清理token资源

refactor(lexer): 重构词法分析器内部结构

- 修复keywords数组字段名从tok到tok_type
- 优化scc_lexer_get_valid_token使用while循环替代do-while
- 修改fill_token和fill_valid_token返回类型为cbool
- 调整lexer_to_ring参数语义更清晰

fix(sstream): 修正环形缓冲区填充函数返回类型

- 将fill_func返回类型从int改为cbool以保持一致性
- 更新SCC_RING宏文档说明fill回调函数返回值含义

docs(argparse): 重命名examples目录修复路径错误

- 将libs/argparse/example重命名为libs/argparse/examples保持一致性

test(lexer): 更新测试用例适配新的流接口

- 修改测试代码中的scc_sstream_ref_ring为scc_sstream_to_ring
- 确保测试用例与新的API保持兼容

style(lexer): 更新示例程序日志级别和实现方式

- 将调试日志改为信息日志
- 使用环形缓冲区实现示例程序的token获取
This commit is contained in:
zzy
2026-02-16 22:27:09 +08:00
parent b4929be6b8
commit 681a15cb44
7 changed files with 73 additions and 26 deletions

View File

@@ -40,19 +40,27 @@ int main(int argc, char *argv[]) {
scc_lexer_t lexer;
scc_sstream_t stream;
scc_sstream_init(&stream, file_name, 16);
scc_sstream_ring_t *ref = scc_sstream_ref_ring(&stream);
scc_sstream_ring_t *ref = scc_sstream_to_ring(&stream);
scc_lexer_init(&lexer, ref);
scc_lexer_tok_t token;
scc_lexer_tok_ring_t *tok_ring = scc_lexer_to_ring(&lexer, 16, false);
int ok;
while (1) {
scc_lexer_get_valid_token(&lexer, &token);
if (token.type == SCC_TOK_EOF) {
// scc_lexer_get_valid_token(&lexer, &token);
// if (token.type == SCC_TOK_EOF) {
// break;
// }
scc_ring_next_consume(*tok_ring, token, ok);
if (!ok) {
break;
}
LOG_DEBUG("get token [%-8s] `%s` at %s:%d:%d",
scc_get_tok_name(token.type),
scc_cstring_as_cstr(&token.lexeme), token.loc.name,
token.loc.line, token.loc.col);
LOG_INFO("get token [%-8s] `%s` at %s:%d:%d",
scc_get_tok_name(token.type),
scc_cstring_as_cstr(&token.lexeme), token.loc.name,
token.loc.line, token.loc.col);
scc_cstring_free(&token.lexeme);
}
scc_sstream_drop_ring(ref);