-= { yylval->csop = OpSetSubtract; return T_SET_SUBTRACT; }
\*= { yylval->csop = OpSetMultiply; return T_SET_MULTIPLY; }
\/= { yylval->csop = OpSetDivide; return T_SET_DIVIDE; }
+\%= { yylval->csop = OpSetModulo; return T_SET_MODULO; }
+\^= { yylval->csop = OpSetXor; return T_SET_XOR; }
+\&= { yylval->csop = OpSetBinaryAnd; return T_SET_BINARY_AND; }
+\|= { yylval->csop = OpSetBinaryOr; return T_SET_BINARY_OR; }
\+ return T_PLUS;
\- return T_MINUS;
\* return T_MULTIPLY;
\/ return T_DIVIDE_OP;
+\% return T_MODULO;
+\^ return T_XOR;
\& return T_BINARY_AND;
\| return T_BINARY_OR;
\< return T_LESS_THAN;
%token <csop> T_SET_SUBTRACT "-= (T_SET_SUBTRACT)"
%token <csop> T_SET_MULTIPLY "*= (T_SET_MULTIPLY)"
%token <csop> T_SET_DIVIDE "/= (T_SET_DIVIDE)"
+%token <csop> T_SET_MODULO "%= (T_SET_MODULO)"
+%token <csop> T_SET_XOR "^= (T_SET_XOR)"
+%token <csop> T_SET_BINARY_AND "&= (T_SET_BINARY_AND)"
+%token <csop> T_SET_BINARY_OR "|= (T_SET_BINARY_OR)"
%token T_SHIFT_LEFT "<< (T_SHIFT_LEFT)"
%token T_SHIFT_RIGHT ">> (T_SHIFT_RIGHT)"
%token T_MINUS "- (T_MINUS)"
%token T_MULTIPLY "* (T_MULTIPLY)"
%token T_DIVIDE_OP "/ (T_DIVIDE_OP)"
+%token T_MODULO "% (T_MODULO)"
+%token T_XOR "^ (T_XOR)"
%token T_BINARY_AND "& (T_BINARY_AND)"
%token T_BINARY_OR "| (T_BINARY_OR)"
%token T_LESS_THAN "< (T_LESS_THAN)"
%left T_LOGICAL_AND
%left T_LOCAL T_RETURN
%left T_IDENTIFIER
-%left T_SET T_SET_ADD T_SET_SUBTRACT T_SET_MULTIPLY T_SET_DIVIDE
+%left T_SET T_SET_ADD T_SET_SUBTRACT T_SET_MULTIPLY T_SET_DIVIDE T_SET_MODULO T_SET_XOR T_SET_BINARY_AND T_SET_BINARY_OR
%left T_BINARY_OR
+%left T_XOR T_MODULO
%left T_BINARY_AND
%left T_IN T_NOT_IN
%nonassoc T_EQUAL T_NOT_EQUAL
| T_SET_SUBTRACT
| T_SET_MULTIPLY
| T_SET_DIVIDE
+ | T_SET_MODULO
+ | T_SET_XOR
+ | T_SET_BINARY_AND
+ | T_SET_BINARY_OR
{
$$ = $1;
}
| rterm T_MINUS rterm { MakeRBinaryOp<SubtractExpression>(&$$, $1, $3, @1, @3); }
| rterm T_MULTIPLY rterm { MakeRBinaryOp<MultiplyExpression>(&$$, $1, $3, @1, @3); }
| rterm T_DIVIDE_OP rterm { MakeRBinaryOp<DivideExpression>(&$$, $1, $3, @1, @3); }
+ | rterm T_MODULO rterm { MakeRBinaryOp<ModuloExpression>(&$$, $1, $3, @1, @3); }
+ | rterm T_XOR rterm { MakeRBinaryOp<XorExpression>(&$$, $1, $3, @1, @3); }
| T_FUNCTION identifier '(' identifier_items ')' use_specifier rterm_scope
{
DictExpression *aexpr = dynamic_cast<DictExpression *>($7);
return m_Operand1->Evaluate(frame) / m_Operand2->Evaluate(frame);
}
+Value ModuloExpression::DoEvaluate(VMFrame& frame, DebugHint *dhint) const
+{
+ return (long)m_Operand1->Evaluate(frame) % (long)m_Operand2->Evaluate(frame);
+}
+
+Value XorExpression::DoEvaluate(VMFrame& frame, DebugHint *dhint) const
+{
+ return (long)m_Operand1->Evaluate(frame) ^ (long)m_Operand2->Evaluate(frame);
+}
+
Value BinaryAndExpression::DoEvaluate(VMFrame& frame, DebugHint *dhint) const
{
return m_Operand1->Evaluate(frame) & m_Operand2->Evaluate(frame);
case OpSetDivide:
right = DivideExpression(lhs, rhs, m_DebugInfo).Evaluate(frame, dhint);
break;
+ case OpSetModulo:
+ right = ModuloExpression(lhs, rhs, m_DebugInfo).Evaluate(frame, dhint);
+ break;
+ case OpSetXor:
+ right = XorExpression(lhs, rhs, m_DebugInfo).Evaluate(frame, dhint);
+ break;
+ case OpSetBinaryAnd:
+ right = BinaryAndExpression(lhs, rhs, m_DebugInfo).Evaluate(frame, dhint);
+ break;
+ case OpSetBinaryOr:
+ right = BinaryOrExpression(lhs, rhs, m_DebugInfo).Evaluate(frame, dhint);
+ break;
default:
VERIFY(!"Invalid opcode.");
}
OpSetAdd,
OpSetSubtract,
OpSetMultiply,
- OpSetDivide
+ OpSetDivide,
+ OpSetModulo,
+ OpSetXor,
+ OpSetBinaryAnd,
+ OpSetBinaryOr
};
class InterruptExecutionError : virtual public std::exception, virtual public boost::exception
protected:
virtual Value DoEvaluate(VMFrame& frame, DebugHint *dhint) const;
};
-
+
+class I2_CONFIG_API ModuloExpression : public BinaryExpression
+{
+public:
+ ModuloExpression(Expression *operand1, Expression *operand2, const DebugInfo& debugInfo = DebugInfo())
+ : BinaryExpression(operand1, operand2, debugInfo)
+ { }
+
+protected:
+ virtual Value DoEvaluate(VMFrame& frame, DebugHint *dhint) const;
+};
+
+class I2_CONFIG_API XorExpression : public BinaryExpression
+{
+public:
+ XorExpression(Expression *operand1, Expression *operand2, const DebugInfo& debugInfo = DebugInfo())
+ : BinaryExpression(operand1, operand2, debugInfo)
+ { }
+
+protected:
+ virtual Value DoEvaluate(VMFrame& frame, DebugHint *dhint) const;
+};
+
class I2_CONFIG_API BinaryAndExpression : public BinaryExpression
{
public: