Fixed negation bug in parser.

parent 84c9dcb4
......@@ -239,8 +239,7 @@ class Parser(BisonParser):
+ combine('+', values[2])))
if option == 1: # rule: exp MINUS exp
return Node('-', *(combine('-', values[0])
+ combine('-', values[2])))
return Node('-', values[0], values[2])
if option == 2: # rule: exp TIMES exp
return Node('*', *(combine('*', values[0])
......
......@@ -79,3 +79,10 @@ class TestCalc(unittest.TestCase):
]
run_expressions(Parser, expressions)
def test_negation(self):
run_expressions(Parser, [
('-9', N('-', L(9))),
('--9', N('-', N('-', L(9)))),
('a--9', N('-', L('a'), N('-', L(9)))),
])
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