mathparse 0.2.8__py3-none-any.whl → 0.2.9__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- mathparse/__init__.py +1 -1
- mathparse/mathparse.py +18 -8
- {mathparse-0.2.8.dist-info → mathparse-0.2.9.dist-info}/METADATA +1 -1
- mathparse-0.2.9.dist-info/RECORD +8 -0
- {mathparse-0.2.8.dist-info → mathparse-0.2.9.dist-info}/WHEEL +1 -1
- mathparse-0.2.8.dist-info/RECORD +0 -8
- {mathparse-0.2.8.dist-info → mathparse-0.2.9.dist-info}/licenses/LICENSE +0 -0
- {mathparse-0.2.8.dist-info → mathparse-0.2.9.dist-info}/top_level.txt +0 -0
mathparse/__init__.py
CHANGED
mathparse/mathparse.py
CHANGED
|
@@ -466,17 +466,21 @@ def to_postfix(tokens: list) -> list:
|
|
|
466
466
|
"""
|
|
467
467
|
precedence = {
|
|
468
468
|
'.': 5,
|
|
469
|
-
'
|
|
470
|
-
'
|
|
471
|
-
'
|
|
472
|
-
'
|
|
473
|
-
'
|
|
469
|
+
'^': 4,
|
|
470
|
+
'/': 3,
|
|
471
|
+
'*': 3,
|
|
472
|
+
'+': 2,
|
|
473
|
+
'-': 2,
|
|
474
474
|
'(': 1
|
|
475
475
|
}
|
|
476
476
|
|
|
477
477
|
# Unary functions have a higher precedence than binary operators
|
|
478
478
|
unary_precedence = max(precedence.values()) + 1
|
|
479
479
|
|
|
480
|
+
# Right-associative operators use strict inequality when popping,
|
|
481
|
+
# so that e.g. 2^3^2 evaluates as 2^(3^2) = 512, not (2^3)^2 = 64
|
|
482
|
+
right_associative = {'^'}
|
|
483
|
+
|
|
480
484
|
postfix = []
|
|
481
485
|
opstack = []
|
|
482
486
|
|
|
@@ -497,12 +501,18 @@ def to_postfix(tokens: list) -> list:
|
|
|
497
501
|
postfix.append(top_token)
|
|
498
502
|
top_token = opstack.pop()
|
|
499
503
|
elif is_binary(token):
|
|
500
|
-
#
|
|
501
|
-
#
|
|
504
|
+
# Pop operators with higher precedence, or equal precedence when
|
|
505
|
+
# the current token is left-associative (right-associative
|
|
506
|
+
# operators like ^ only yield to strictly higher precedence so
|
|
507
|
+
# that 2^3^2 = 2^(3^2) = 512 rather than (2^3)^2 = 64).
|
|
508
|
+
is_left_assoc = token not in right_associative
|
|
502
509
|
while (opstack != []) and (
|
|
503
510
|
(
|
|
504
511
|
opstack[-1] in precedence and token in precedence and (
|
|
505
|
-
precedence[opstack[-1]]
|
|
512
|
+
precedence[opstack[-1]] > precedence[token] or (
|
|
513
|
+
is_left_assoc and
|
|
514
|
+
precedence[opstack[-1]] == precedence[token]
|
|
515
|
+
)
|
|
506
516
|
)
|
|
507
517
|
) or
|
|
508
518
|
(
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
mathparse/__init__.py,sha256=IGoPZ97zQMilOfFKGq4bDLt3uZ7S6gUdta59IU79Tgo,110
|
|
2
|
+
mathparse/mathparse.py,sha256=RylRYi4KGmeUoZncHYYS7crml30PMPBvfHRU7-KpGjo,31710
|
|
3
|
+
mathparse/mathwords.py,sha256=Ui4K5Y1aDkSKtlUWDn5hO7C8FzNO4kYrZBXFaGjWWLI,48306
|
|
4
|
+
mathparse-0.2.9.dist-info/licenses/LICENSE,sha256=_buf4D_BxjT3x8SBhP0Rh966qP3zpbButcLI4bPq_TY,1068
|
|
5
|
+
mathparse-0.2.9.dist-info/METADATA,sha256=QiACgK0mCUYY-Y3R-yJMAthEqCzW_80B_NGOHqqkUQs,5157
|
|
6
|
+
mathparse-0.2.9.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
|
|
7
|
+
mathparse-0.2.9.dist-info/top_level.txt,sha256=rAQj3bfKyZhbFL6WxVLRCqnvwQPI2ZCc_FNrwx6Hlmc,10
|
|
8
|
+
mathparse-0.2.9.dist-info/RECORD,,
|
mathparse-0.2.8.dist-info/RECORD
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
mathparse/__init__.py,sha256=JjEq33WHjALR_G8DWNwmgY0EIsYEqhGNNfA4umxOyYs,110
|
|
2
|
-
mathparse/mathparse.py,sha256=KYuV1DIYxL4p7yscUZyQhOt_ucgH37icVvzmSfD73CM,31136
|
|
3
|
-
mathparse/mathwords.py,sha256=Ui4K5Y1aDkSKtlUWDn5hO7C8FzNO4kYrZBXFaGjWWLI,48306
|
|
4
|
-
mathparse-0.2.8.dist-info/licenses/LICENSE,sha256=_buf4D_BxjT3x8SBhP0Rh966qP3zpbButcLI4bPq_TY,1068
|
|
5
|
-
mathparse-0.2.8.dist-info/METADATA,sha256=VNrAyhkQmsnGqS20PvrmH1IMnByRcJY-PwWYtYU76hs,5157
|
|
6
|
-
mathparse-0.2.8.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
|
|
7
|
-
mathparse-0.2.8.dist-info/top_level.txt,sha256=rAQj3bfKyZhbFL6WxVLRCqnvwQPI2ZCc_FNrwx6Hlmc,10
|
|
8
|
-
mathparse-0.2.8.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|