Commit 363eb37c authored by Robert Bradshaw's avatar Robert Bradshaw

FloorDiv operation

parent dbb891df
......@@ -2421,6 +2421,7 @@ class NumBinopNode(BinopNode):
"-": "PyNumber_Subtract",
"*": "PyNumber_Multiply",
"/": "PyNumber_Divide",
"//": "PyNumber_FloorDivide",
"%": "PyNumber_Remainder",
"**": "PyNumber_Power"
}
......@@ -2479,6 +2480,16 @@ class MulNode(NumBinopNode):
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.
......@@ -2841,6 +2852,7 @@ binop_node_classes = {
"-": SubNode,
"*": MulNode,
"/": NumBinopNode,
"//": FloorDivNode,
"%": ModNode,
"**": PowNode
}
......
......@@ -66,7 +66,7 @@ def make_lexicon():
bra = Any("([{")
ket = Any(")]}")
punct = Any(":,;+-*/|&<>=.%`~^?")
diphthong = Str("==", "<>", "!=", "<=", ">=", "<<", ">>", "**", "+=", "-=", "*=", "/=", "%=", "|=", "^=", "&=")
diphthong = Str("==", "<>", "!=", "<=", ">=", "<<", ">>", "**", "+=", "-=", "*=", "/=", "%=", "|=", "^=", "&=", "//")
spaces = Rep1(Any(" \t\f"))
comment = Str("#") + Rep(AnyBut("\n"))
escaped_newline = Str("\\\n")
......
......@@ -155,7 +155,7 @@ def p_arith_expr(s):
#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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment