Przeglądaj źródła

Fixed some precedence issues.

Taddeus Kroes 14 lat temu
rodzic
commit
6a78440dfb
2 zmienionych plików z 13 dodań i 2 usunięć
  1. 7 0
      src/parser.py
  2. 6 2
      src/rules/precedences.py

+ 7 - 0
src/parser.py

@@ -294,6 +294,13 @@ class Parser(BisonParser):
             while self.possibilities:
                 # Find the first implicit possibliity in the list
                 # FIXME: Is it smart to apply a rule that is not a hint?
+                # ANSWER: Yes, but there must be an extra list that prevents
+                # deliberately generated implicit rules from being applied
+                #sugg = self.possibilities[0]
+
+                #if sugg.handler not in IMPLICIT_RULES:
+                #    break
+
                 sugg = None
 
                 for pos in self.possibilities:

+ 6 - 2
src/rules/precedences.py

@@ -7,7 +7,8 @@ from .logarithmic import factor_in_exponent_multiplicant, \
 from .derivatives import chain_rule
 from .negation import double_negation, negated_factor, negated_nominator, \
         negated_denominator, negated_zero
-from .fractions import multiply_with_fraction, extract_fraction_terms
+from .fractions import multiply_with_fraction, extract_fraction_terms, \
+        add_nominators
 from .integrals import factor_out_constant, integrate_variable_root
 from .powers import remove_power_of_one
 from .sqrt import quadrant_sqrt, extract_sqrt_mult_priority
@@ -18,6 +19,9 @@ from .sqrt import quadrant_sqrt, extract_sqrt_mult_priority
 # means lower priority
 HIGH = [
         raised_base,
+
+        # 4 / 4 + 1 / 4 -> 5 / 4 instead of 1 + 1/4
+        add_nominators,
         ]
 
 
@@ -32,7 +36,7 @@ LOW = [
 
 
 # Fucntion precedences relative to eachother. Tuple (A, B) means that A has a
-# higer priority than B. This list ignores occurences in the HIGH or LOW lists
+# higher priority than B. This list ignores occurences in the HIGH or LOW lists
 # above
 RELATIVE = [
         # Precedences needed for 'power rule'