feat add func call and rewrite codes
This commit is contained in:
@@ -5,25 +5,30 @@
|
||||
#define PROG_MAX_NODE_SIZE (1024 * 4)
|
||||
#endif
|
||||
|
||||
void parse_prog(struct Parser* parser) {
|
||||
void parse_func(parser_t* parser);
|
||||
|
||||
void parse_prog(parser_t* parser) {
|
||||
/**
|
||||
* Program := (Declaration | Definition)*
|
||||
* same as
|
||||
* Program := Declaration* Definition*
|
||||
*/
|
||||
int child_size = 0;
|
||||
tok_buf_t *tokbuf = &(parser->tokbuf);
|
||||
parser->root = new_ast_node();
|
||||
struct ASTNode* node;
|
||||
parser->root->root.children = xmalloc(sizeof(struct ASTNode*) * PROG_MAX_NODE_SIZE);
|
||||
ast_node_t* node;
|
||||
parser->root->type = NT_ROOT;
|
||||
vector_init(parser->root->root.children);
|
||||
while (1) {
|
||||
flushpeektok(parser);
|
||||
if (peektoktype(parser) == TOKEN_EOF) {
|
||||
flush_peek_tok(tokbuf);
|
||||
if (peek_tok_type(tokbuf) == TOKEN_EOF) {
|
||||
break;
|
||||
}
|
||||
node = parse_decl(parser);
|
||||
parser->root->root.children[child_size++] = node;
|
||||
if (node == NULL) {
|
||||
parse_func(parser);
|
||||
} else {
|
||||
vector_push(parser->root->root.children, node);
|
||||
}
|
||||
}
|
||||
parser->root->type = NT_ROOT;
|
||||
parser->root->root.child_size = child_size;
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user