"-": ast.Sub(),
"*": ast.Mult(),
"/": ast.Div(),
+ "%": ast.Mod(),
"<=": make_le_compare,
">=": make_ge_compare,
"<": make_lt_compare,
# also part of Ply
#import yacc
+# https://www.mathcs.emory.edu/~valerie/courses/fall10/155/resources/op_precedence.html
+# python operator precedence
+# Highest precedence at top, lowest at bottom.
+# Operators in the same box evaluate left to right.
+#
+# Operator Description
+# () Parentheses (grouping)
+# f(args...) Function call
+# x[index:index] Slicing
+# x[index] Subscription
+# x.attribute Attribute reference
+# ** Exponentiation
+# ~x Bitwise not
+# +x, -x Positive, negative
+# *, /, % mul, div, remainder
+# +, - Addition, subtraction
+# <<, >> Bitwise shifts
+# & Bitwise AND
+# ^ Bitwise XOR
+# | Bitwise OR
+# in, not in, is, is not, <, <=, >, >=, <>, !=, == comp, membership, ident
+# not x Boolean NOT
+# and Boolean AND
+# or Boolean OR
+# lambda Lambda expression
+
class PowerParser:
precedence = (
("left", "BITOR"),
("left", "BITAND"),
("left", "PLUS", "MINUS"),
- ("left", "MULT", "DIV"),
+ ("left", "MULT", "DIV", "MOD"),
("left", "INVERT"),
)
| comparison MINUS comparison
| comparison MULT comparison
| comparison DIV comparison
+ | comparison MOD comparison
| comparison EQ comparison
| comparison LE comparison
| comparison GE comparison
assert b.bits == self.bits
return SelectableInt(self.value * b.value, self.bits)
+ def __div__(self, b):
+ assert b.bits == self.bits
+ return SelectableInt(self.value / b.value, self.bits)
+
+ def __mod__(self, b):
+ assert b.bits == self.bits
+ return SelectableInt(self.value % b.value, self.bits)
+
def __or__(self, b):
assert b.bits == self.bits
return SelectableInt(self.value | b.value, self.bits)