You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Leading minus sign in context where subtraction makes no sense (would be a grammar error) should have the highest priority. Otherwise, there will be a (R-associative) negation operator left at the end of the dance with no dance partner.
change py_expression_eval/init.py line 455 from: self.tokenprio = 5
to: self.tokenprio = 10
currently:: while self.pos < len(self.expression): if self.isOperator(): if self.isSign() and expected & self.SIGN: if self.isNegativeSign(): self.tokenprio = 5 self.tokenindex = '-' noperators += 1 self.addfunc(tokenstack, operstack, TOP1)
change to: while self.pos < len(self.expression): if self.isOperator(): if self.isSign() and expected & self.SIGN: if self.isNegativeSign(): self.tokenprio = 10 self.tokenindex = '-' noperators += 1 self.addfunc(tokenstack, operstack, TOP1)
This expression perse without problem
parser.parse('-2*3').evaluate({})
This expression crash
parser.parse('2*-3').evaluate({})
_IndexError Traceback (most recent call last)
in
----> 1 parser.parse('2*-3').evaluate({})
~/Library/Python/3.7/lib/python/site-packages/py_expression_eval/init.py in evaluate(self, values)
118 elif type_ == TOP2:
119 n2 = nstack.pop()
--> 120 n1 = nstack.pop()
121 f = self.ops2[item.index_]
122 nstack.append(f(n1, n2))
IndexError: pop from empty list_
eval('2*-3') works on python3.7
The text was updated successfully, but these errors were encountered: