def NullPrefixOp(p, w, bp): """Prefix operator. Low precedence: return, raise, etc. return x+y is return (x+y), not (return x) + y High precedence: logical negation, bitwise complement, etc. !x && y is (!x) && y, not !(x && y) """ right = p.ParseUntil(bp) return ast.ArithUnary(word.ArithId(w), right)
def LeftIncDec(p, w, left, rbp): """ For i++ and i-- """ if not tdop.IsLValue(left): raise tdop.ParseError("Can't assign to %r (%s)" % (left, left.token)) if word.ArithId(w) == Id.Arith_DPlus: op_id = Id.Node_PostDPlus elif word.ArithId(w) == Id.Arith_DMinus: op_id = Id.Node_PostDMinus else: raise AssertionError return ast.ArithUnary(op_id, left)
def NullUnaryMinus(p, t, bp): """ -1, to distinguish from binary operator. """ right = p.ParseUntil(bp) return ast.ArithUnary(Id.Node_UnaryMinus, right)
def NullIncDec(p, w, bp): """ ++x or ++x[1] """ right = p.ParseUntil(bp) if not tdop.IsLValue(right): raise tdop.ParseError("Can't assign to %r (%s)" % (right, right.token)) return ast.ArithUnary(word.ArithId(w), right)