- 在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调用
70 lines
1.9 KiB
C
70 lines
1.9 KiB
C
#ifndef __SCC_PARSER_UTILS_H__
|
|
#define __SCC_PARSER_UTILS_H__
|
|
|
|
#include "scc_parser.h"
|
|
|
|
static inline const scc_lexer_tok_t *scc_parser_peek(scc_parser_t *parser) {
|
|
cbool ok = false;
|
|
const scc_lexer_tok_t *tok = null;
|
|
scc_ring_unsafe_peek_ref(*parser->ring, tok, ok);
|
|
if (ok == false) {
|
|
return null;
|
|
}
|
|
return tok;
|
|
}
|
|
|
|
static inline const scc_lexer_tok_t *scc_parser_next(scc_parser_t *parser) {
|
|
cbool ok = false;
|
|
const scc_lexer_tok_t *tok = null;
|
|
scc_ring_unsafe_next_ref(*parser->ring, tok, ok);
|
|
if (ok == false) {
|
|
return null;
|
|
}
|
|
return tok;
|
|
}
|
|
|
|
static inline cbool scc_parser_consume_if(scc_parser_t *parser,
|
|
scc_tok_type_t type) {
|
|
cbool ok = false;
|
|
scc_lexer_tok_t *tok = null;
|
|
scc_ring_unsafe_peek_ref(*parser->ring, tok, ok);
|
|
if (ok == false) {
|
|
return null;
|
|
}
|
|
if (tok->type == type) {
|
|
scc_lexer_tok_drop(tok);
|
|
scc_ring_unsafe_pure_next_consume(*parser->ring);
|
|
return true;
|
|
} else {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
static inline void scc_parser_store(scc_parser_t *parser) {
|
|
parser->checkpoint = _scc_ring_probe(*parser->ring);
|
|
}
|
|
|
|
static inline void scc_parser_restore(scc_parser_t *parser) {
|
|
_scc_ring_probe(*parser->ring) = parser->checkpoint;
|
|
}
|
|
|
|
static inline cbool scc_parser_next_consume(scc_parser_t *parser,
|
|
scc_lexer_tok_t *tok) {
|
|
cbool ok = false;
|
|
scc_lexer_tok_t *raw_tok_ref = null;
|
|
scc_ring_unsafe_next_ref_consume(*parser->ring, raw_tok_ref, ok);
|
|
scc_lexer_tok_move(tok, raw_tok_ref);
|
|
return ok;
|
|
}
|
|
|
|
static inline void scc_parser_commit(scc_parser_t *parser) {
|
|
// Memory leak
|
|
scc_ring_consume(*parser->ring);
|
|
}
|
|
|
|
static inline void scc_parser_reset(scc_parser_t *parser) {
|
|
scc_ring_reset(*parser->ring);
|
|
}
|
|
|
|
#endif /* __SCC_PARSER_UTILS_H__ */
|