Add init statement to if

This commit is contained in:
Krzosa Karol
2022-05-26 18:57:15 +02:00
parent 8e4942f5ae
commit ec773c08be
5 changed files with 71 additions and 7 deletions

View File

@@ -89,6 +89,7 @@ enum Ast_Kind{
AST_COMPOUND_ITEM,
AST_COMPOUND,
AST_INIT,
AST_IF,
AST_IF_NODE,
AST_RETURN,
@@ -167,9 +168,16 @@ struct Ast_Return: Ast{
Ast_Expr *expr;
};
struct Ast_Init: Ast{
Token_Kind op;
Ast_Atom *ident;
Ast_Expr *expr;
};
struct Ast_If_Node: Ast{
Ast_Expr *expr ;
Ast_Block *block;
Ast_Init *init;
};
struct Ast_If: Ast{
@@ -338,9 +346,19 @@ ast_if(Token *pos, Array<Ast_If_Node *> ifs){
}
function Ast_If_Node *
ast_if_node(Token *pos, Ast_Expr *expr, Ast_Block *block){
ast_if_node(Token *pos, Ast_Init *init, Ast_Expr *expr, Ast_Block *block){
AST_NEW(If_Node, AST_IF_NODE, pos);
result->block = block;
result->block = block;
result->expr = expr;
result->init = init;
return result;
}
function Ast_Init *
ast_init(Token *pos, Token_Kind op, Ast_Atom *ident, Ast_Expr *expr){
AST_NEW(Init, AST_INIT, pos);
result->op = op;
result->ident = ident;
result->expr = expr;
return result;
}