From 1af7a564f1a1e90b2d0420a989afe62198f04b9b Mon Sep 17 00:00:00 2001
From: Kia <kia@special-circumstanc.es>
Date: Sat, 22 Aug 2020 19:53:36 -0600
Subject: [PATCH] Gprim has effects and we must respect this by scheduling the
 addition of X_ijk to the derivation tree *before* invoking Gprim! This fixes
 the order bug!

---
 CFGBoltzmann.py    | 7 ++++---
 python_arborist.py | 2 +-
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/CFGBoltzmann.py b/CFGBoltzmann.py
index a9ffd34..028f3e8 100644
--- a/CFGBoltzmann.py
+++ b/CFGBoltzmann.py
@@ -451,13 +451,14 @@ class CFGBoltzmann:
             else:
                 # CASE B
                 print("    "* depth +"GPRIM CASE B FIRST PRODUCES", [xijk], "with depth", depth)
-                reduct = self.Gprim(nonterminal_index, chosen_production, how_far_into_the_RHS + 1, exact_length_total - 1, depth+1,  root_of_tree, nonterminal_root)
-                retstring = [xijk] + reduct
-                print("    "* depth +"GPRIM CASE B THEN ADDS ON", reduct, "with depth", depth)
                 newnode = TreeNode(xijk, [])
 
                 nonterminal_root.subnodes.append(newnode)
 
+                reduct = self.Gprim(nonterminal_index, chosen_production, how_far_into_the_RHS + 1, exact_length_total - 1, depth+1,  root_of_tree, nonterminal_root)
+                retstring = [xijk] + reduct
+                print("    "* depth +"GPRIM CASE B THEN ADDS ON", reduct, "with depth", depth)
+
                 print("    "* depth +"Gprim inside the production of a nonterminal, adding terminal", xijk)
 
          #       print("    "* depth +"GPRIM CASE B RETURNING", retstring)
diff --git a/python_arborist.py b/python_arborist.py
index b1e755a..424843c 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, 3)
+bgen = z.Gzero_shimmed(EXPRESSION, 7)
 parse_me =  bgen[0]
 
 print("derivation tree was")
-- 
GitLab