init basic
This commit is contained in:
29
ccompiler/frontend/parser/ast/program.c
Normal file
29
ccompiler/frontend/parser/ast/program.c
Normal file
@@ -0,0 +1,29 @@
|
||||
#include "../parser.h"
|
||||
#include "ast.h"
|
||||
|
||||
#ifndef PROG_MAX_NODE_SIZE
|
||||
#define PROG_MAX_NODE_SIZE (1024 * 4)
|
||||
#endif
|
||||
|
||||
void parse_prog(struct Parser* parser) {
|
||||
/**
|
||||
* Program := (Declaration | Definition)*
|
||||
* same as
|
||||
* Program := Declaration* Definition*
|
||||
*/
|
||||
int child_size = 0;
|
||||
parser->root = new_ast_node();
|
||||
struct ASTNode* node;
|
||||
parser->root->root.children = xmalloc(sizeof(struct ASTNode*) * PROG_MAX_NODE_SIZE);
|
||||
while (1) {
|
||||
flushpeektok(parser);
|
||||
if (peektoktype(parser) == TOKEN_EOF) {
|
||||
break;
|
||||
}
|
||||
node = parse_decl(parser);
|
||||
parser->root->root.children[child_size++] = node;
|
||||
}
|
||||
parser->root->type = NT_ROOT;
|
||||
parser->root->root.child_size = child_size;
|
||||
return;
|
||||
}
|
||||
Reference in New Issue
Block a user