diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/grammar.zig | 27 | ||||
| -rw-r--r-- | src/gss.zig | 3 |
2 files changed, 15 insertions, 15 deletions
diff --git a/src/grammar.zig b/src/grammar.zig index 9b794a0..eaea3d4 100644 --- a/src/grammar.zig +++ b/src/grammar.zig @@ -30,6 +30,17 @@ pub fn parse(entry: []const u8, buffer: []const u8, allocator: std.mem.Allocator errdefer self.deinit(); { + var iterator = names.iterator(); + while (iterator.next()) |name_entry| { + self.non_terminals[name_entry.value_ptr.*] = try NonTerminal.init( + name_entry.key_ptr.*, + name_entry.value_ptr.*, + allocator + ); + } + } + + { self.non_terminals[0] = try NonTerminal.init("_start", 0, allocator); const init_rule = try allocator.alloc(Character, 1); init_rule[0] = Character { @@ -41,17 +52,6 @@ pub fn parse(entry: []const u8, buffer: []const u8, allocator: std.mem.Allocator }); } - { - var iterator = names.iterator(); - while (iterator.next()) |name_entry| { - self.non_terminals[name_entry.value_ptr.*] = try NonTerminal.init( - name_entry.key_ptr.*, - name_entry.value_ptr.*, - allocator - ); - } - } - while (lines.next()) |line| { const name = try NonTerminal.parse_name(line); try self.non_terminal_by_id( @@ -230,7 +230,10 @@ pub fn is_next_char(self: *const Self, rule_slice: []Character, current: usize, } } - const result = is_char_in_first or (is_epsilon_in_first and self.non_terminals[current].follows.is_set(char)); + const result = is_char_in_first or ( + is_epsilon_in_first and + self.non_terminals[current].follows.is_set(char) + ); return result; } diff --git a/src/gss.zig b/src/gss.zig index 9201ca6..12b3b46 100644 --- a/src/gss.zig +++ b/src/gss.zig @@ -6,7 +6,6 @@ pub fn Node(T: type) type { parents: *std.ArrayList(*Self), state: T, - is_toplevel: bool = false, pub fn init(state: T, allocator: std.mem.Allocator) !Self { const parents = try allocator.create(std.ArrayList(*Self)); @@ -22,7 +21,6 @@ pub fn Node(T: type) type { return Self { .parents = self.parents, .state = state, - .is_toplevel = self.is_toplevel, }; } @@ -76,7 +74,6 @@ pub fn Graph(T: type) type { self.number_of_nodes += 1; const node = try self.allocator.create(Node(T)); node.* = try Node(T).init(state, self.allocator); - node.is_toplevel = true; return node; } |