diff --git a/CFGBoltzmann.py b/CFGBoltzmann.py index f4df62d386591422826b1926301f7cbede0f0661..27f87d79fda1f65b59bbcac8d07346b6874044e6 100644 --- a/CFGBoltzmann.py +++ b/CFGBoltzmann.py @@ -372,14 +372,15 @@ 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: - opsite = self.indexes_to_item(root_of_tree, operation_site_index) + #opsite = self.indexes_to_item(root_of_tree, operation_site_index) - generated_string = self.Gprim(nonterminal_index, chosen_production, depth, requested_length, depth) + + generated_string = self.Gprim(nonterminal_index, chosen_production, depth, requested_length, depth, root_of_tree, operation_site_index) return generated_string - def indexes_to_item(tree, location): + def indexes_to_item(self, tree, location): opsite = tree if (location != []): for depth_index in location: @@ -426,7 +427,7 @@ class CFGBoltzmann: # \----------------------------------------------------------/ - def Gprim(self, nonterminal_index, chosen_production, how_far_into_the_RHS, exact_length_total, depth): + def Gprim(self, nonterminal_index, chosen_production, how_far_into_the_RHS, exact_length_total, depth, root_of_tree, operation_site_index): #print(" "* depth + "GPRIM arguments are", nonterminal_index, chosen_production, how_far_into_the_RHS, exact_length_total) @@ -436,8 +437,8 @@ class CFGBoltzmann: # The case analysis hinges on what is at X_ijk. RHS_in_question = self.processed_rulepack[nonterminal_index][1][chosen_production] - #print(" "* depth +"Our RHS is", RHS_in_question) - #print(" "* depth +"WE ARE PROCESSING index", how_far_into_the_RHS, "and our remaining lengthis", exact_length_total) + print(" "* depth +"Our RHS is", RHS_in_question) + print(" "* depth +"WE ARE PROCESSING index", how_far_into_the_RHS, "and our remaining length is", exact_length_total) xijk = RHS_in_question[how_far_into_the_RHS] @@ -448,13 +449,13 @@ class CFGBoltzmann: # are we at the end of the rule if (how_far_into_the_RHS == (len(RHS_in_question) - 1)): # CASE A - # print(" "* depth +"GPRIM CASE A RETURNING", [xijk]) + print(" "* depth +"GPRIM CASE A RETURNING", [xijk]) print(" "* depth +"Gprim ending the production of a nonterminal, with terminal", xijk) return [xijk] else: # CASE B - # print(" "* depth +"GPRIM CASE B pointing @", [xijk]) - reduct = self.Gprim(nonterminal_index, chosen_production, how_far_into_the_RHS + 1, exact_length_total - 1, depth+1) + print(" "* depth +"GPRIM CASE B pointing @", [xijk]) + reduct = self.Gprim(nonterminal_index, chosen_production, how_far_into_the_RHS + 1, exact_length_total - 1, depth+1, root_of_tree, operation_site_index) retstring = [xijk] + reduct print(" "* depth +"Gprim inside the production of a nonterminal, adding terminal", xijk) @@ -474,7 +475,7 @@ class CFGBoltzmann: if (how_far_into_the_RHS == (len(RHS_in_question) - 1)): # CASE C # print(" "* depth +"CASE C STARTING") - retstring = self.Gzero(new_nonterminal_index, exact_length_total, depth+1) + retstring = self.Gzero(new_nonterminal_index, exact_length_total, depth+1, root_of_tree, operation_site_index) # print(" "* depth +"CASE C returning", retstring) return retstring @@ -492,12 +493,12 @@ class CFGBoltzmann: # hit the nonterminal X_ijk with Gzero - nonterminal_generates = self.Gzero(new_nonterminal_index, split_choice, depth+1) + nonterminal_generates = self.Gzero(new_nonterminal_index, split_choice, depth+1, root_of_tree, operation_site_index) # print (" "* depth +"CASE D NONTERMINAL @ XIJK generates", nonterminal_generates) # and then the remaining part of the rule - rest_of_rule_generates = self.Gprim(nonterminal_index, chosen_production, how_far_into_the_RHS + 1, exact_length_total - split_choice, depth+1) + rest_of_rule_generates = self.Gprim(nonterminal_index, chosen_production, how_far_into_the_RHS + 1, exact_length_total - split_choice, depth+1, root_of_tree, operation_site_index) # print ("CASE D REST OF RULE generates", rest_of_rule_generates) retstring = nonterminal_generates + rest_of_rule_generates @@ -623,3 +624,11 @@ class CFGBoltzmann: +z = CFGBoltzmann(rules, list_of_nonterminals, list_of_terminals) + +rulepack_cooked = z.preprocessor() + + +qq = z.Gzero_shimmed(nonterminals.EXPRESSION, 3) +print ("AND THE FINAL ANSWER IS","\n\n\n",qq, "\n\n\n") +