diff --git a/CFGBoltzmann.py b/CFGBoltzmann.py index 028f3e88895cde3c2673701edbe7d71e234f6b81..c39feb374eab374f93fc4d74370b4e6b51e66b5b 100644 --- a/CFGBoltzmann.py +++ b/CFGBoltzmann.py @@ -365,6 +365,16 @@ class CFGBoltzmann: return (self.Gzero(nonterminal_index, requested_length, 0, root_of_tree, nonterminal_root), root_of_tree) + + + def reversiflip(self, root_of_completed_tree): + root_of_completed_tree.subnodes.reverse() + for x in root_of_completed_tree.subnodes: + self.reversiflip(x) + + + + def Gzero(self, nonterminal_index, requested_length, depth, root_of_tree, nonterminal_root): possibilities = self.Fzero(nonterminal_index, requested_length) chosen_production = self.normalized_choice(possibilities) @@ -512,6 +522,7 @@ class CFGBoltzmann: + #z = CFGBoltzmann(rules, list_of_nonterminals, list_of_terminals) #rulepack_cooked = z.preprocessor() diff --git a/python_arborist.py b/python_arborist.py index 424843c3b1e44813516fdeca5572674a696ffaec..fa3e9a4b00c730fba6a8d11e3b369f3fc3f56579 100644 --- a/python_arborist.py +++ b/python_arborist.py @@ -319,8 +319,7 @@ cooked_rules = z.preprocessor() bgen = z.Gzero_shimmed(EXPRESSION, 7) parse_me = bgen[0] -print("derivation tree was") -walk_the_tree(bgen[1]) + parse_me.append(ENDOFPARSE) @@ -439,4 +438,11 @@ print(the_tree) walk_the_tree(the_tree,0) +#print("derivation tree was") +#walk_the_tree(bgen[1]) + +print("reversed derivation tree is") +z.reversiflip(bgen[1]) +walk_the_tree(bgen[1]) + print("THE ORIGINAL WAS", [hex_to_name(x) for x in parse_me])