const std = @import("std"); const ast = @import("ast.zig"); fn parenthesize(name: []const u8, exprs: []*ast.Expr) void { std.debug.warn("({}", name); for (exprs) |expr| { std.debug.warn(" "); printAst(expr); } std.debug.warn(")"); } pub fn printAst(ast_expr: *ast.Expr) void { switch (ast_expr.*) { .Binary => |expr| parenthesize(expr.operator.lexeme, &[]*ast.Expr{ expr.left, expr.right }), .Grouping => |expr| parenthesize("group", &[]*ast.Expr{expr.expression}), .Unary => |expr| parenthesize(expr.operator.lexeme, &[]*ast.Expr{expr.right}), .Number => |ast_num| { switch (ast_num) { .Integer32 => |num| std.debug.warn("{}", num), .Integer64 => |num| std.debug.warn("{}", num), .Unsigned32 => |num| std.debug.warn("{}", num), .Unsigned64 => |num| std.debug.warn("{}", num), .Float32 => |num| std.debug.warn("{}", num), .Float64 => |num| std.debug.warn("{}", num), } }, else => unreachable, } }