Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sign directly after * cause crash #76

Open
owarnier opened this issue Aug 29, 2023 · 2 comments
Open

sign directly after * cause crash #76

owarnier opened this issue Aug 29, 2023 · 2 comments

Comments

@owarnier
Copy link

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

@owarnier
Copy link
Author

version
py-expression-eval 0.3.14

@kcrossen
Copy link

kcrossen commented Aug 19, 2024

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants