Implement == and != operators for AExpressions.

Refs #5789
This commit is contained in:
Gunnar Beutner 2014-03-18 08:34:56 +01:00
parent ce737ff2f3
commit 04b8724cb8
5 changed files with 30 additions and 6 deletions

View File

@ -65,6 +65,10 @@ Value AExpression::Evaluate(const Object::Ptr& thisRef) const
return (long)left << (long)right;
case AEShiftRight:
return (long)left >> (long)right;
case AEEqual:
return left == right;
case AENotEqual:
return left != right;
default:
ASSERT(!"Invalid operator.");
}

View File

@ -41,7 +41,9 @@ enum AOperator
AEBinaryAnd,
AEBinaryOr,
AEShiftLeft,
AEShiftRight
AEShiftRight,
AEEqual,
AENotEqual,
};
/**

View File

@ -232,7 +232,9 @@ const return T_CONST;
-?[0-9]+(\.[0-9]+)?m { yylval->num = strtod(yytext, NULL) * 60; return T_NUMBER; }
-?[0-9]+(\.[0-9]+)?s { yylval->num = strtod(yytext, NULL); return T_NUMBER; }
-?[0-9]+(\.[0-9]+)? { yylval->num = strtod(yytext, NULL); return T_NUMBER; }
= { yylval->op = OperatorSet; return T_EQUAL; }
== { yylval->op = OperatorEqual; return T_EQUAL; }
!= { yylval->op = OperatorNotEqual; return T_NOT_EQUAL; }
= { yylval->op = OperatorSet; return T_SET; }
\+= { yylval->op = OperatorPlus; return T_PLUS_EQUAL; }
-= { yylval->op = OperatorMinus; return T_MINUS_EQUAL; }
\*= { yylval->op = OperatorMultiply; return T_MULTIPLY_EQUAL; }

View File

@ -69,7 +69,9 @@ using namespace icinga;
%token <num> T_NUMBER
%token T_NULL
%token <text> T_IDENTIFIER
%token <op> T_EQUAL "= (T_EQUAL)"
%token <op> T_EQUAL "== (T_EQUAL)"
%token <op> T_NOT_EQUAL "!= (T_NOT_EQUAL)"
%token <op> T_SET "= (T_SET)"
%token <op> T_PLUS_EQUAL "+= (T_PLUS_EQUAL)"
%token <op> T_MINUS_EQUAL "-= (T_MINUS_EQUAL)"
%token <op> T_MULTIPLY_EQUAL "*= (T_MULTIPLY_EQUAL)"
@ -191,7 +193,7 @@ library: T_LIBRARY T_STRING
}
;
variable: variable_decl identifier T_EQUAL value
variable: variable_decl identifier T_SET value
{
Value *value = $4;
if (value->IsObjectType<ExpressionList>()) {
@ -480,7 +482,7 @@ expression: identifier operator value
}
;
operator: T_EQUAL
operator: T_SET
| T_PLUS_EQUAL
| T_MINUS_EQUAL
| T_MULTIPLY_EQUAL
@ -591,6 +593,18 @@ aexpression: T_STRING
$$ = new Value(make_shared<AExpression>(AENegate, static_cast<AExpression::Ptr>(*$2)));
delete $2;
}
| aexpression T_EQUAL aexpression
{
$$ = new Value(make_shared<AExpression>(AEEqual, static_cast<AExpression::Ptr>(*$1), static_cast<AExpression::Ptr>(*$3)));
delete $1;
delete $3;
}
| aexpression T_NOT_EQUAL aexpression
{
$$ = new Value(make_shared<AExpression>(AENotEqual, static_cast<AExpression::Ptr>(*$1), static_cast<AExpression::Ptr>(*$3)));
delete $1;
delete $3;
}
| aexpression '+' aexpression
{
$$ = new Value(make_shared<AExpression>(AEAdd, static_cast<AExpression::Ptr>(*$1), static_cast<AExpression::Ptr>(*$3)));

View File

@ -43,7 +43,9 @@ enum ExpressionOperator
OperatorPlus,
OperatorMinus,
OperatorMultiply,
OperatorDivide
OperatorDivide,
OperatorEqual, /* Not used for Expressions */
OperatorNotEqual, /* Not used for Expressions */
};
class ExpressionList;