diff options
author | Mathias Magnusson <mathias@magnusson.space> | 2025-05-29 00:42:36 +0200 |
---|---|---|
committer | Mathias Magnusson <mathias@magnusson.space> | 2025-05-29 01:53:54 +0200 |
commit | db112f0d384ca991e1477913b8af7a2c8dc80088 (patch) | |
tree | d76972bfbff517243027a4d65f796bc94374420c /src/main.zig | |
parent | 7b85276fc98643b1138df6f322b8bd657339ea96 (diff) | |
download | huginn-db112f0d384ca991e1477913b8af7a2c8dc80088.tar.gz |
compile some god damn additions
Diffstat (limited to 'src/main.zig')
-rw-r--r-- | src/main.zig | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/src/main.zig b/src/main.zig index e897d41..d938d9b 100644 --- a/src/main.zig +++ b/src/main.zig @@ -1,5 +1,12 @@ +const std = @import("std"); +const parse = @import("./parse.zig"); +const peek = @import("./peek.zig"); +const compile = @import("./compile.zig"); + pub const peekable = peek.peekable; pub const Peekable = peek.Peekable; +pub const Expr = parse.Expr; +pub const Lexer = @import("./lexer.zig"); pub fn main() !void { var arena: std.heap.ArenaAllocator = .init(std.heap.smp_allocator); @@ -22,7 +29,7 @@ pub fn main() !void { // try stdout.print("{s}\n", .{line.items}); // } - const source = "69 + (32 + 1) + 2"; + const source = "1 + 2 + 3"; // var lexer = Lexer{ .source = source }; // while (true) { // const token = lexer.next().?; @@ -30,17 +37,20 @@ pub fn main() !void { // if (token.type == .Eof) break; // } // try stdout.print("\n", .{}); - var lexer2 = peekable(Lexer{ .source = source }); - try stdout.print("{}\n", .{try parse.expression(allocator, &lexer2)}); + var lexer = peekable(Lexer{ .source = source }); + const expr = try parse.expression(allocator, &lexer); + try stdout.print("{}\n", .{expr}); + if (lexer.next()) |token| if (token.type != .eof) { + try stdout.print("Unexpected token {}, expected end of file\n", .{token}); + }; + const block = try compile.compile(allocator, expr); + for (block.instrs) |instr| { + try stdout.print("{}\n", .{instr}); + } try bw.flush(); // Don't forget to flush! } -const std = @import("std"); -const Lexer = @import("./lexer.zig"); -const parse = @import("./parse.zig"); -const peek = @import("./peek.zig"); - test { _ = peek; } |