aboutsummaryrefslogtreecommitdiff
path: root/src/main.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.zig')
-rw-r--r--src/main.zig18
1 files changed, 12 insertions, 6 deletions
diff --git a/src/main.zig b/src/main.zig
index 87dc493..d4951e6 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -1,8 +1,7 @@
const std = @import("std");
-const parse = @import("./parse.zig");
const codegen = @import("./codegen.zig");
-pub const Expr = parse.Expr;
+pub const parse = @import("./parse.zig");
pub const Lexer = @import("./Lexer.zig");
pub const compile = @import("./compile.zig");
@@ -30,7 +29,11 @@ pub fn main() !void {
// }
// const source = "17216961135462248174 + 4095 - 4294967295 + 2147483647";
- const source = "print 18446744073709551615";
+ const source =
+ \\print 18446744073709551615;
+ \\print (0 - 1);
+ \\print 69;
+ ;
var lexer: Lexer = .{ .source = source };
std.debug.print("Tokens:\n", .{});
while (true) {
@@ -39,12 +42,15 @@ pub fn main() !void {
if (token.type == .eof) break;
}
lexer = .{ .source = source };
- const expr = try parse.expression(allocator, &lexer);
- std.debug.print("{}\n", .{expr});
- const block = try compile.compile(allocator, source, expr);
+ const stmts = try parse.statements(allocator, &lexer);
+ std.debug.print("Statements:\n", .{});
+ for (stmts) |stmt| {
+ std.debug.print(" {}\n", .{stmt});
+ }
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);
std.debug.print("Bytecode instructions:\n", .{});
for (block.instrs) |instr| {
std.debug.print(" {}\n", .{instr});