- 重命名lexer_token.h为scc_lexer_token.h以保持命名一致性 - 在词法分析器中实现##操作符的识别和处理 - 修改头文件包含路径和类型定义的位置 - 修复token结构体定义的顺序问题 fix(lexer): 初始化lexer中的cur变量避免未初始化问题 - 在scc_lexer_get_token函数中初始化scc_sstream_char_t cur变量 refactor(core): 增强ring缓冲区功能并添加cstring比较函数 - 在scc_core_ring.h中添加空值检查防止fill函数为空时崩溃 - 添加scc_ring_by_buffer宏用于通过缓冲区创建ring实例 - 在scc_core_str.h中添加scc_cstring_cmp函数用于字符串比较
53 lines
1.4 KiB
C
53 lines
1.4 KiB
C
/**
|
||
* @file lexer.h
|
||
* @brief C语言词法分析器核心数据结构与接口
|
||
*/
|
||
|
||
#ifndef __SCC_LEXER_H__
|
||
#define __SCC_LEXER_H__
|
||
|
||
#include "scc_lexer_token.h"
|
||
#include <scc_core.h>
|
||
#include <scc_core_ring.h>
|
||
#include <scc_sstream.h>
|
||
|
||
/**
|
||
* @brief 词法分析器核心结构体
|
||
*
|
||
* 封装词法分析所需的状态信息和缓冲区管理
|
||
*/
|
||
typedef struct scc_lexer {
|
||
scc_sstream_ring_t *stream_ref;
|
||
scc_lexer_tok_ring_t ring;
|
||
int ring_ref_count;
|
||
int jump_macro;
|
||
} scc_lexer_t;
|
||
|
||
void scc_lexer_init(scc_lexer_t *lexer, scc_sstream_ring_t *stream_ref);
|
||
|
||
/**
|
||
* @brief 获取原始token
|
||
* @param[in] lexer 词法分析器实例
|
||
* @param[out] token 输出token存储位置
|
||
*
|
||
* 此函数会返回所有类型的token,包括空白符等无效token
|
||
*/
|
||
void scc_lexer_get_token(scc_lexer_t *lexer, scc_lexer_tok_t *token);
|
||
|
||
/**
|
||
* @brief 获取有效token
|
||
* @param[in] lexer 词法分析器实例
|
||
* @param[out] token 输出token存储位置
|
||
*
|
||
* 此函数会自动跳过空白符等无效token,返回对语法分析有意义的token
|
||
*/
|
||
void scc_lexer_get_valid_token(scc_lexer_t *lexer, scc_lexer_tok_t *token);
|
||
|
||
scc_lexer_tok_ring_t *scc_lexer_to_ring(scc_lexer_t *lexer, int ring_size,
|
||
cbool need_comment);
|
||
|
||
void scc_lexer_drop_ring(scc_lexer_tok_ring_t *ring_ref);
|
||
void scc_lexer_drop(scc_lexer_t *lexer);
|
||
|
||
#endif /* __SCC_LEXER_H__ */
|