From de6c1f32ced255e05f339e5102de74aa2e015e69 Mon Sep 17 00:00:00 2001 From: Kia <kia@special-circumstanc.es> Date: Mon, 24 Aug 2020 15:08:49 -0600 Subject: [PATCH] tree reversing is done; now to handle the spurious double-start-symbol --- CFGBoltzmann.py | 11 +++++++++++ python_arborist.py | 10 ++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/CFGBoltzmann.py b/CFGBoltzmann.py index 028f3e8..c39feb3 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 424843c..fa3e9a4 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]) -- GitLab