diff --git a/CFGBoltzmann.py b/CFGBoltzmann.py index 04602ef5036cb795bae9b1cff8f752a2ad9584d8..06d158eefa76e6710bf0b415c4f2fc1d5d0393cf 100644 --- a/CFGBoltzmann.py +++ b/CFGBoltzmann.py @@ -342,7 +342,7 @@ class CFGBoltzmann: nonterminal_index = self.nonterminals_ordered.index(nonterminal) return self.Gzero(nonterminal_index, requested_length, 0) def Gzero(self, nonterminal_index, requested_length, depth): - print(" "* depth +"ENTERING Gzero") + print(" "* depth +"ENTERINGGzero") possibilities = self.Fzero(nonterminal_index, requested_length) chosen_production = self.normalized_choice(possibilities) generated_string = self.Gprim(nonterminal_index, chosen_production, 0, requested_length, depth) @@ -385,7 +385,8 @@ class CFGBoltzmann: def Gprim(self, nonterminal_index, chosen_production, how_far_into_the_RHS, exact_length_total, depth): - print(" "* depth + "GPRIM arguments are", nonterminal_index, chosen_production, how_far_into_the_RHS, exact_length_total) + #print(" "* depth + "GPRIM arguments are", nonterminal_index, chosen_production, how_far_into_the_RHS, exact_length_total) + # first, handle the ultimate degenerate case: assert(exact_length_total != 0) @@ -393,8 +394,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 lengthis", exact_length_total) xijk = RHS_in_question[how_far_into_the_RHS] @@ -405,14 +406,14 @@ 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]) return [xijk] else: # CASE B - print(" "* depth +"GPRIM CASE B pointing @", [xijk]) + # 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) retstring = [xijk] + reduct - print(" "* depth +"GPRIM CASE B RETURNING", retstring) + # print(" "* depth +"GPRIM CASE B RETURNING", retstring) return retstring @@ -427,35 +428,35 @@ class CFGBoltzmann: if (how_far_into_the_RHS == (len(RHS_in_question) - 1)): # CASE C - print(" "* depth +"CASE C STARTING") + # print(" "* depth +"CASE C STARTING") retstring = self.Gzero(new_nonterminal_index, exact_length_total, depth+1) - print(" "* depth +"CASE C returning", retstring) + # print(" "* depth +"CASE C returning", retstring) return retstring else: # CASE D - print(" "* depth +"CASE D STARTING") + # print(" "* depth +"CASE D STARTING") splitting_possibilities = self.Fprim(nonterminal_index, chosen_production, how_far_into_the_RHS, exact_length_total) - print (" "* depth +"CASE D; SPLIT POSSIBILITIES ARE", splitting_possibilities) + # print (" "* depth +"CASE D; SPLIT POSSIBILITIES ARE", splitting_possibilities) split_choice = 1+ self.normalized_choice(splitting_possibilities) - print (" "* depth +"CASE D; SPLITTING WITH LENGTH", split_choice) + # print (" "* depth +"CASE D; SPLITTING WITH LENGTH", split_choice) # hit the nonterminal X_ijk with Gzero nonterminal_generates = self.Gzero(new_nonterminal_index, split_choice, depth+1) - print (" "* depth +"CASE D NONTERMINAL @ XIJK generates", nonterminal_generates) + # 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) - print ("CASE D REST OF RULE generates", rest_of_rule_generates) + # print ("CASE D REST OF RULE generates", rest_of_rule_generates) retstring = nonterminal_generates + rest_of_rule_generates - print (" "* depth +"CASE D RETURNING", retstring) + # print (" "* depth +"CASE D RETURNING", retstring) return retstring @@ -463,13 +464,13 @@ class CFGBoltzmann: -z = CFGBoltzmann(rules, list_of_nonterminals, list_of_terminals) +#z = CFGBoltzmann(rules, list_of_nonterminals, list_of_terminals) -rulepack_cooked = z.preprocessor() +#rulepack_cooked = z.preprocessor() -qq = z.Gzero_shimmed(nonterminals.EXPRESSION, 11) -print ("AND THE FINAL ANSWER IS","\n\n\n",qq, "\n\n\n") +#qq = z.Gzero_shimmed(nonterminals.EXPRESSION, 11) +#print ("AND THE FINAL ANSWER IS","\n\n\n",qq, "\n\n\n") # We now can calculate the number of strings generated c(n) for each length n. We also can generate