Skip to content

Commit e613787

Browse files
committed
Binary operations are parsed
1 parent ab604d4 commit e613787

1 file changed

Lines changed: 11 additions & 5 deletions

File tree

dice_notation/parser/DiceNotationListener.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def binary_operation(self, operators):
2929
operands = []
3030

3131
# There are as many operands as operators plus one
32-
for i in range(0, len(operators)):
32+
for i in range(0, len(operators)+1):
3333
operands.append(self._nodes.pop())
3434

3535
for operator in operators:
@@ -72,7 +72,11 @@ def enterAddOp(self, ctx):
7272
# Exit a parse tree produced by DiceNotationParser#addOp.
7373
def exitAddOp(self, ctx):
7474
self._logger.debug("Exiting add %s", ctx.getText())
75-
pass
75+
operators = []
76+
for operator in ctx.ADDOPERATOR():
77+
operators.append(operator.getText())
78+
expression = self.binary_operation(operators)
79+
self._nodes.append(expression)
7680

7781

7882
# Enter a parse tree produced by DiceNotationParser#multOp.
@@ -83,7 +87,11 @@ def enterMultOp(self, ctx):
8387
# Exit a parse tree produced by DiceNotationParser#multOp.
8488
def exitMultOp(self, ctx):
8589
self._logger.debug("Exiting multiplication %s", ctx.getText())
86-
pass
90+
operators = []
91+
for operator in ctx.MULTOPERATOR():
92+
operators.append(operator.getText())
93+
expression = self.binary_operation(operators)
94+
self._nodes.append(expression)
8795

8896

8997
# Enter a parse tree produced by DiceNotationParser#operand.
@@ -119,8 +127,6 @@ def exitDice(self, ctx):
119127

120128
dice = Dice(quantity, sides)
121129
self._nodes.append(dice)
122-
self._logger.debug("Added dice %s to stack", dice)
123-
self._logger.debug("Currently the stack contains %s", self._nodes)
124130

125131

126132
# Enter a parse tree produced by DiceNotationParser#number.

0 commit comments

Comments
 (0)