diff --git a/cfg_utils.py b/cfg_utils.py index 7d18eb4f94d5722ae849567ca0b8a626da87e1b7..c460856de9e0393aa90b480915e116e433946da9 100644 --- a/cfg_utils.py +++ b/cfg_utils.py @@ -471,10 +471,18 @@ class CFGBoltzmann: # Here, L will be the number of characters produced by X_ijk # L will therefore go from 1 (we disallow epsilon-productions so - # X_ijk must produce at least one character) to: + # X_ijk must produce at least one character) (INCLUSIVE) to (INCLUSIVE): # Total Characters Requested - (minimum number of characters generated by k+1 to end of rule) # which will be: - # + # Total Characters Requested - (T_ij -(k+1)+1) = TCR - (T_ij-k) + # But T_ij is the INDEX of the last element of the rule, aka len(rule)-1 + # so the expression is + # Total Characters Requested - (len(rule)-k-1) + # exact_length_total - len(rule) - how_far_into_the_RHS - 1 + + # in the range() call we lop off the "-1" because we want to be inclusive and range gives us [) + # bounds. Phantasmagoria of off-by-ones here we go! + for l in range(1, exact_length_total - len(RHS_in_question) - how_far_into_the_RHS) return 0