Commit ea4270eb authored by Taddeus Kroes's avatar Taddeus Kroes

Reduced negation precedence to MINUS.

parent 70714ec0
......@@ -142,7 +142,11 @@ def generate_line(root):
if child.negated:
# (-a) ^ b
if op == '^' and not i:
# -a ^ -b
# (-a) * b
# a * -b
# (-a) / b
if (node_pred > NEG_PRED and not i):
exp = '(' + exp + ')'
elif child_pred < node_pred:
exp = '(' + exp + ')'
......
......@@ -138,8 +138,10 @@ class TestLine(unittest.TestCase):
mul = N('*', N('*', a, l2), b)
self.assertEquals(generate_line(mul), 'a * 2b')
plus = N('*', N('*', -a, b), c)
self.assertEquals(generate_line(plus), '-abc')
mul = -N('*', N('*', a, b), c)
self.assertEquals(generate_line(mul), '-abc')
mul = N('*', N('*', -a, b), c)
self.assertEquals(generate_line(mul), '(-a)bc')
mul = N('*', a, N('-', b, c))
self.assertEquals(generate_line(mul), 'a(b - c)')
......@@ -173,7 +175,7 @@ class TestLine(unittest.TestCase):
self.assertEquals(generate_line(plus), '1 - 2')
l1, a, b, c = L(1), L('a'), L('b'), L('c')
plus = N('+', l1, N('*', N('*', -a, b), c))
plus = N('+', l1, -N('*', N('*', a, b), c))
self.assertEquals(generate_line(plus), '1 - abc')
def test_helper_functions(self):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment