ast: add IfStmt and IfBranch
This commit is contained in:
parent
f9f6362c91
commit
83910811fa
1 changed files with 10 additions and 10 deletions
20
src/ast.zig
20
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);
|
||||
|
|
Loading…
Reference in a new issue