forked from benclmnt/zig-interpreter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.zig
More file actions
27 lines (23 loc) · 719 Bytes
/
main.zig
File metadata and controls
27 lines (23 loc) · 719 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
const std = @import("std");
const stdin = std.io.getStdIn().reader();
const stdout = std.io.getStdOut().writer();
const Lexer = @import("lexer.zig").Lexer;
const Token = @import("lexer.zig").Token;
const PROMPT = ">> ";
pub fn main() !void {
try stdout.print("Welcome to Monkey REPL!\n", .{});
try run();
}
fn run() !void {
var buf: [128]u8 = undefined;
try stdout.print(PROMPT, .{});
while (try stdin.readUntilDelimiterOrEof(buf[0..], '\n')) |line| {
var l = Lexer.init(line);
while (true) {
var tok = l.next();
if (tok.tag == Token.Tag.eof) break;
std.debug.print("{any}\n", .{tok});
}
try stdout.print(PROMPT, .{});
}
}