diff --git a/CFGBoltzmann.py b/CFGBoltzmann.py index c39feb374eab374f93fc4d74370b4e6b51e66b5b..d64095001674f904ec251bafdbc6b175fd245491 100644 --- a/CFGBoltzmann.py +++ b/CFGBoltzmann.py @@ -360,10 +360,9 @@ class CFGBoltzmann: def Gzero_shimmed(self, nonterminal, requested_length): nonterminal_index = self.nonterminals_ordered.index(nonterminal) - root_of_tree = TreeNode(nonterminal,[]) - nonterminal_root = root_of_tree + root_of_tree = TreeNode(None,[]) - return (self.Gzero(nonterminal_index, requested_length, 0, root_of_tree, nonterminal_root), root_of_tree) + return (self.Gzero(nonterminal_index, requested_length, 0, root_of_tree, None), root_of_tree) @@ -382,10 +381,17 @@ class CFGBoltzmann: # We already know we will have this nonterminal show up in our derivation tree; so we add it now # First, dereference the location to get the operation site: - newnode = TreeNode(self.nonterminals_ordered[nonterminal_index], []) + if (nonterminal_root == None): + root_of_tree.language_element = self.nonterminals_ordered[nonterminal_index] + nonterminal_root = root_of_tree + else: + newnode = TreeNode(self.nonterminals_ordered[nonterminal_index], []) + nonterminal_root.subnodes.append(newnode) + nonterminal_root = newnode + + + - nonterminal_root.subnodes.append(newnode) - nonterminal_root = newnode generated_string = self.Gprim(nonterminal_index, chosen_production, 0, requested_length, depth, root_of_tree, nonterminal_root) diff --git a/python_arborist.py b/python_arborist.py index 92554be2131430fc72f8c1462ed87846a0d4bada..db3f3690d7d18299e6d92139e0e559447f2aad03 100644 --- a/python_arborist.py +++ b/python_arborist.py @@ -316,7 +316,7 @@ list_of_terminals = [INTEGER, ADDOP, MULTOP, OPENPAREN, CLOSEPAREN] z = CFGBoltzmann.CFGBoltzmann(rules, list_of_nonterminals, list_of_terminals) cooked_rules = z.preprocessor() -bgen = z.Gzero_shimmed(EXPRESSION, 1) +bgen = z.Gzero_shimmed(EXPRESSION, 5) parse_me = bgen[0] @@ -431,7 +431,7 @@ def deserializer(serialized_array, last_idx_written): -the_tree = deserializer(serialized_tree_final, 8) +the_tree = deserializer(serialized_tree_final, 30) walk_the_tree(the_tree,0)