From 83910811fa1f396e46b6577acae166f0f4026164 Mon Sep 17 00:00:00 2001 From: Luna Date: Sun, 25 Aug 2019 12:31:57 -0300 Subject: [PATCH] ast: add IfStmt and IfBranch --- src/ast.zig | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/ast.zig b/src/ast.zig index 4386b98..23b829d 100644 --- a/src/ast.zig +++ b/src/ast.zig @@ -20,8 +20,6 @@ pub const NodeType = enum { pub const ParamDecl = struct { name: Token, - - // TODO types typ: Token, }; @@ -81,26 +79,28 @@ pub const VarDecl = struct { pub const Expr = union(ExprType) { Assign: AssignExpr, VarDecl: VarDecl, + Binary: BinaryExpr, Unary: UnaryExpr, Literal: LiteralExpr, + Variable: Token, Grouping: *Expr, }; -// TODO -//pub const IfStmt = struct { -// condition: *Expr, -// then_branch: *StmtList, -// else_branch: *StmtList, -//}; +pub const IfBranch = std.ArrayList(Stmt); + +pub const IfStmt = struct { + condition: *Expr, + then_branch: IfBranch, + else_branch: IfBranch, +}; pub const Stmt = union(enum) { Expr: *Expr, Println: *Expr, - // TODO - //If: IfStmt, + If: IfStmt, pub fn mkPrintln(allocator: *std.mem.Allocator, expr: *Expr) !*Stmt { var println = try allocator.create(Stmt);