Skip to content
Snippets Groups Projects
Commit fe4e092c authored by Taddeüs Kroes's avatar Taddeüs Kroes
Browse files

Division by negated multiplication is now printed correctly by line printer.

parent e17779f2
No related branches found
No related tags found
No related merge requests found
......@@ -247,14 +247,14 @@ def generate_line(root):
lparens = is_right_assoc(left.title()) or is_right_assoc(op)
if rpred < op_pred:
rparens = not unary_right
rparens = not unary_right or len(right[0]) > 1
elif rpred == op_pred and len(right) > 1:
if right.title() == op:
rparens = not is_right_assoc(op)
elif is_left_assoc(right.title()):
rparens = True
# Check if multiplication sig is necessary
# Check if multiplication sign is necessary
if op == '*' and not unary_right:
sep = mult_sign(left, right, lparens, rparens)
......
......@@ -338,3 +338,13 @@ class TestLine(unittest.TestCase):
def addbrackets(self): self[0] = N('[]', self[0])
root.preprocess_str_exp = new.instancemethod(addbrackets, root)
self.assertEquals(generate_line(root), '-[1]')
def test_division_by_multiplication(self):
root = N('/', L(1), N('*', L('a'), L('b')))
self.assertEquals(generate_line(root), '1 / (ab)')
root = N('/', L(1), -N('*', L('a'), L('b')))
self.assertEquals(generate_line(root), '1 / (-ab)')
root = N('/', L(1), N('*', -L('a'), L('b')))
self.assertEquals(generate_line(root), '1 / ((-a)b)')
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment