- 添加 .gitignore 文件,忽略编译器生成的二进制文件 - 重构 lexer.c 文件,改进了关键字处理和字符串处理 - 更新前端的前端、解析器和 AST 相关文件,以适应新的词法分析器 - 优化了 token 相关的定义和函数,引入了新的 token 类型
52 lines
1.2 KiB
C
52 lines
1.2 KiB
C
|
|
#include "../ast.h"
|
|
#include "../parser.h"
|
|
#include "../symtab/symtab.h"
|
|
|
|
|
|
#ifndef BLOCK_MAX_NODE
|
|
#define BLOCK_MAX_NODE (1024)
|
|
#endif
|
|
|
|
ast_node_t* new_ast_node_block() {
|
|
ast_node_t* node = new_ast_node();
|
|
node->type = NT_BLOCK;
|
|
vector_init(node->block.children);
|
|
return node;
|
|
}
|
|
|
|
ast_node_t* parse_block(parser_t* parser) {
|
|
symtab_enter_scope(parser->symtab);
|
|
tok_stream_t *tokbuf = &parser->tokbuf;
|
|
flush_peek_tok(tokbuf);
|
|
cc_tktype_t ttype;
|
|
ast_node_t* node = new_ast_node_block();
|
|
|
|
expect_pop_tok(tokbuf, TOKEN_L_BRACE);
|
|
ast_node_t* child = NULL;
|
|
while (1) {
|
|
if (peek_decl(tokbuf)) {
|
|
child = parse_decl(parser);
|
|
vector_push(node->block.children, child);
|
|
continue;
|
|
}
|
|
|
|
flush_peek_tok(tokbuf);
|
|
ttype = peek_tok_type(tokbuf);
|
|
switch (ttype) {
|
|
case TOKEN_R_BRACE: {
|
|
pop_tok(tokbuf);
|
|
goto END;
|
|
}
|
|
default: {
|
|
child = parse_stmt(parser);
|
|
vector_push(node->block.children, child);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
END:
|
|
symtab_leave_scope(parser->symtab);
|
|
return node;
|
|
}
|