"-": "PyNumber_Subtract",
"*": "PyNumber_Multiply",
"/": "PyNumber_Divide",
+ "//": "PyNumber_FloorDivide",
"%": "PyNumber_Remainder",
"**": "PyNumber_Power"
}
return NumBinopNode.is_py_operation(self)
+class FloorDivNode(NumBinopNode):
+ # '//' operator.
+
+ def calculate_result_code(self):
+ return "(%s %s %s)" % (
+ self.operand1.result_code,
+ "/", # c division is by default floor-div
+ self.operand2.result_code)
+
+
class ModNode(IntBinopNode):
# '%' operator.
"-": SubNode,
"*": MulNode,
"/": NumBinopNode,
+ "//": FloorDivNode,
"%": ModNode,
"**": PowNode
}
bra = Any("([{")
ket = Any(")]}")
punct = Any(":,;+-*/|&<>=.%`~^?")
- diphthong = Str("==", "<>", "!=", "<=", ">=", "<<", ">>", "**", "+=", "-=", "*=", "/=", "%=", "|=", "^=", "&=")
+ diphthong = Str("==", "<>", "!=", "<=", ">=", "<<", ">>", "**", "+=", "-=", "*=", "/=", "%=", "|=", "^=", "&=", "//")
spaces = Rep1(Any(" \t\f"))
comment = Str("#") + Rep(AnyBut("\n"))
escaped_newline = Str("\\\n")
#term: factor (('*'|'/'|'%') factor)*
def p_term(s):
- return p_binop_expr(s, ('*', '/', '%'), p_factor)
+ return p_binop_expr(s, ('*', '/', '%', '//'), p_factor)
#factor: ('+'|'-'|'~'|'&'|typecast|sizeof) factor | power