ast: add IfStmt and IfBranch

This commit is contained in:
Luna 2019-08-25 12:31:57 -03:00
parent f9f6362c91
commit 83910811fa

View file

@ -20,8 +20,6 @@ pub const NodeType = enum {
pub const ParamDecl = struct { pub const ParamDecl = struct {
name: Token, name: Token,
// TODO types
typ: Token, typ: Token,
}; };
@ -81,26 +79,28 @@ pub const VarDecl = struct {
pub const Expr = union(ExprType) { pub const Expr = union(ExprType) {
Assign: AssignExpr, Assign: AssignExpr,
VarDecl: VarDecl, VarDecl: VarDecl,
Binary: BinaryExpr, Binary: BinaryExpr,
Unary: UnaryExpr, Unary: UnaryExpr,
Literal: LiteralExpr, Literal: LiteralExpr,
Variable: Token, Variable: Token,
Grouping: *Expr, Grouping: *Expr,
}; };
// TODO pub const IfBranch = std.ArrayList(Stmt);
//pub const IfStmt = struct {
// condition: *Expr, pub const IfStmt = struct {
// then_branch: *StmtList, condition: *Expr,
// else_branch: *StmtList, then_branch: IfBranch,
//}; else_branch: IfBranch,
};
pub const Stmt = union(enum) { pub const Stmt = union(enum) {
Expr: *Expr, Expr: *Expr,
Println: *Expr, Println: *Expr,
// TODO If: IfStmt,
//If: IfStmt,
pub fn mkPrintln(allocator: *std.mem.Allocator, expr: *Expr) !*Stmt { pub fn mkPrintln(allocator: *std.mem.Allocator, expr: *Expr) !*Stmt {
var println = try allocator.create(Stmt); var println = try allocator.create(Stmt);