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 {
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);