aboutsummaryrefslogtreecommitdiff
path: root/src/main.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.zig')
-rw-r--r--src/main.zig26
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;
}