/** * @file lexer.h * @brief C语言词法分析器核心数据结构与接口 */ #ifndef __SCC_LEXER_H__ #define __SCC_LEXER_H__ #include "lexer_token.h" #include #include #include typedef SCC_RING(scc_lexer_tok_t) scc_lexer_tok_ring_t; typedef SCC_VEC(scc_lexer_tok_t) scc_lexer_tok_vec_t; /** * @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__ */