This commit is contained in:
Krzosa Karol
2022-04-30 12:28:34 +02:00
parent a5a3acf3ef
commit 3a9b748fed
15 changed files with 296 additions and 746 deletions

34
ast.c Normal file
View File

@@ -0,0 +1,34 @@
typedef AST_Node AST_Node_List;
function B32
ast_is_named(AST_Node *n){
B32 result = n && n->name.s.str;
return result;
}
function AST_Node *
ast_node_new(Parser *p, AST_Kind kind, Token *token, Intern_String name){
AST_Node *node = arena_push_struct(&p->main_arena, AST_Node);
node->pos = token;
node->name = name;
node->kind = kind;
return node;
}
function AST_Node *
ast_enum(Parser *p, Token *token, Intern_String name){
AST_Node *node = ast_node_new(p, AK_Enum, token, name);
return node;
}
function AST_Node *
ast_enum_child(Parser *p, Token *token, Intern_String name, Expr *expr){
AST_Node *node = ast_node_new(p, AK_EnumChild, token, name);
node->expr = expr;
return node;
}
function void
ast_node_push_child(AST_Node *node, AST_Node *child){
SLLQueuePush(node->first_child, node->last_child, child);
}