diff options
Diffstat (limited to 'src/main.zig')
-rw-r--r-- | src/main.zig | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/src/main.zig b/src/main.zig index a9c77ac..9678d0b 100644 --- a/src/main.zig +++ b/src/main.zig @@ -37,9 +37,15 @@ pub fn main() !void { // } const source = - \\let x = read_int(0); - \\print(18446744073709551615); - \\print(x + x); + \\{ + \\ let x = 69; + \\ { + \\ let x = read_int(0); + \\ print(18446744073709551615); + \\ print(x + x); + \\ } + \\ print(x); + \\} ; var lexer: Lexer = .{ .source = source }; std.debug.print("Tokens:\n", .{}); @@ -49,15 +55,12 @@ pub fn main() !void { if (token.type == .eof) break; } lexer = .{ .source = source }; - const stmts = try parse.statements(allocator, &lexer); - std.debug.print("Statements:\n", .{}); - for (stmts) |stmt| { - std.debug.print(" {}\n", .{stmt.fmt(source)}); - } + const ast = try parse.block(allocator, &lexer); + std.debug.print("Parse tree:\n{}\n", .{parse.fmt(ast, source, 0)}); if (lexer.peek().type != .eof) { std.debug.print("Unexpected token {}, expected end of file\n", .{lexer.next()}); } - const block = try compile.compile(allocator, source, stmts); + const block = try compile.compile(allocator, source, ast); std.debug.print("Bytecode instructions:\n", .{}); for (block.instrs) |instr| { std.debug.print(" {}\n", .{instr}); |