first commit
This commit is contained in:
commit
46e1a1e2ce
8 changed files with 590 additions and 0 deletions
42
src/main.zig
Normal file
42
src/main.zig
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
const std = @import("std");
|
||||
const al = @import("al");
|
||||
|
||||
pub fn nodeName(node: *al.Parser.Node) void {
|
||||
switch (node.@"type") {
|
||||
.start => std.debug.print("{d} [label=\"start\",fillcolor=yellow, color=black, shape=box]", .{node.id}),
|
||||
.add => std.debug.print("{d} [label=\"+\"]", .{node.id}),
|
||||
.sub => std.debug.print("{d} [label=\"-\"]", .{node.id}),
|
||||
.mul => std.debug.print("{d} [label=\"*\"]", .{node.id}),
|
||||
.div => std.debug.print("{d} [label=\"/\"]", .{node.id}),
|
||||
.integer => std.debug.print("{d} [label=\"{d}\"]", .{node.id, node.data.integer}),
|
||||
.float => std.debug.print("{d} [label=\"{d}\"]", .{node.id, node.data.float}),
|
||||
else => {},
|
||||
}
|
||||
std.debug.print("\n", .{});
|
||||
}
|
||||
|
||||
pub fn printGraph(node: *al.Parser.Node) void {
|
||||
for (node.inputs.items) |n| {
|
||||
nodeName(n);
|
||||
std.debug.print("{d}->{d}\n", .{node.id, n.id});
|
||||
printGraph(n);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn main() !void {
|
||||
var gpa = std.heap.DebugAllocator(.{}).init;
|
||||
defer {
|
||||
//_ = gpa.detectLeaks();
|
||||
}
|
||||
const allocator = gpa.allocator();
|
||||
|
||||
var lexer = al.Lexer.init(@constCast("3*2+2.2"));
|
||||
var parser = al.Parser.init(allocator, &lexer);
|
||||
defer parser.deinit();
|
||||
const graph = try parser.buildGraph();
|
||||
defer graph.?.deinit(&parser);
|
||||
std.debug.print("digraph G {{\n", .{});
|
||||
nodeName(graph.?);
|
||||
printGraph(graph.?);
|
||||
std.debug.print("}}\n", .{});
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue