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 {
|
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);
|
||||||
|
|
Loading…
Reference in a new issue