Anonymous user
Compiler/AST interpreter: Difference between revisions
m
Update Zig to 0.9.0
(Add Zig language implementation) |
m (Update Zig to 0.9.0) |
||
Line 3,263:
const Self = @This();
pub fn init(allocator:
return ASTInterpreter{
.output = std.ArrayList(u8).init(allocator),
Line 3,391:
var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
defer arena.deinit();
var arg_it = std.process.args();
Line 3,489:
value: ?NodeValue = null,
fn makeNode(allocator:
const result = try allocator.create(Tree);
result.* = Tree{ .left = left, .right = right, .typ = typ };
Line 3,495:
}
fn makeLeaf(allocator:
const result = try allocator.create(Tree);
result.* = Tree{ .left = null, .right = null, .typ = typ, .value = value };
Line 3,505:
fn loadAST(
allocator:
str: []const u8,
string_pool: *std.ArrayList([]const u8),
) LoadASTError!?*Tree {
var line_it = std.mem.split(u8, str, "\n");
return try loadASTHelper(allocator, &line_it, string_pool);
}
fn loadASTHelper(
allocator:
line_it: *std.mem.SplitIterator(u8),
string_pool: *std.ArrayList([]const u8),
) LoadASTError!?*Tree {
if (line_it.next()) |line| {
var tok_it = std.mem.tokenize(u8, line, " ");
const tok_str = tok_it.next().?;
if (tok_str[0] == ';') return null;
|