From: konrad Date: Mon, 25 Jul 2011 13:15:51 +0000 (+0000) Subject: comparison ops X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=61aedadcda5856d53224984c3425dcb8b5a05c25;p=web%2Fkonrad%2Felam.git comparison ops git-svn-id: https://silmor.de/svn/softmagic/elam/trunk@750 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33 --- diff --git a/src/elamfloatengine.cpp b/src/elamfloatengine.cpp index a09554a..0216b0d 100644 --- a/src/elamfloatengine.cpp +++ b/src/elamfloatengine.cpp @@ -94,6 +94,32 @@ static QVariant floatDiv(const QVariant &o1,const QVariant &o2,Engine&) return o1.toDouble()/d2; } +static QVariant fltLt(const QVariant&o1,const QVariant&o2,Engine&) +{ + return o1.toDouble()o2.toDouble(); +} +static QVariant fltLe(const QVariant&o1,const QVariant&o2,Engine&) +{ + return o1.toDouble()<=o2.toDouble(); +} +static QVariant fltGe(const QVariant&o1,const QVariant&o2,Engine&) +{ + return o1.toDouble()>=o2.toDouble(); +} +static QVariant fltEq(const QVariant&o1,const QVariant&o2,Engine&) +{ + return o1.toDouble()==o2.toDouble(); +} +static QVariant fltNe(const QVariant&o1,const QVariant&o2,Engine&) +{ + return o1.toDouble()!=o2.toDouble(); +} + + static QVariant floatFunc(const QList&lf,Engine&) { if(lf.size()!=1) @@ -125,6 +151,24 @@ void FloatEngine::configureFloatEngine(ELAM::Engine& eng) eng.unaryOperator("-").setCallback(floatMinus,fid); eng.unaryOperator("+").setCallback(floatPlus,fid); //binary + eng.binaryOperator("==",60).setCallback(fltEq,fid,fid); + eng.binaryOperator("==").setCallback(fltEq,fid,iid); + eng.binaryOperator("==").setCallback(fltEq,iid,fid); + eng.binaryOperator("!=",60).setCallback(fltNe,fid,fid); + eng.binaryOperator("!=").setCallback(fltNe,iid,fid); + eng.binaryOperator("!=").setCallback(fltNe,fid,iid); + eng.binaryOperator("<=",60).setCallback(fltLe,fid,fid); + eng.binaryOperator("<=").setCallback(fltLe,fid,iid); + eng.binaryOperator("<=").setCallback(fltLe,iid,fid); + eng.binaryOperator(">=",60).setCallback(fltGe,fid,fid); + eng.binaryOperator(">=").setCallback(fltGe,iid,fid); + eng.binaryOperator(">=").setCallback(fltGe,fid,iid); + eng.binaryOperator("<",60).setCallback(fltLt,fid,fid); + eng.binaryOperator("<").setCallback(fltLt,iid,fid); + eng.binaryOperator("<").setCallback(fltLt,fid,iid); + eng.binaryOperator(">",60).setCallback(fltGt,fid,fid); + eng.binaryOperator(">").setCallback(fltGt,iid,fid); + eng.binaryOperator(">").setCallback(fltGt,fid,iid); eng.binaryOperator("-",80).setCallback(floatMinus,fid,fid); eng.binaryOperator("-").setCallback(floatMinus,iid,fid); eng.binaryOperator("-").setCallback(floatMinus,fid,iid); diff --git a/src/elamintengine.cpp b/src/elamintengine.cpp index 26e6ff3..f050df9 100644 --- a/src/elamintengine.cpp +++ b/src/elamintengine.cpp @@ -102,6 +102,31 @@ static QVariant intNot(const QVariant&o,Engine&) return ~o.toLongLong(); } +static QVariant intLt(const QVariant&o1,const QVariant&o2,Engine&) +{ + return o1.toLongLong()o2.toLongLong(); +} +static QVariant intLe(const QVariant&o1,const QVariant&o2,Engine&) +{ + return o1.toLongLong()<=o2.toLongLong(); +} +static QVariant intGe(const QVariant&o1,const QVariant&o2,Engine&) +{ + return o1.toLongLong()>=o2.toLongLong(); +} +static QVariant intEq(const QVariant&o1,const QVariant&o2,Engine&) +{ + return o1.toLongLong()==o2.toLongLong(); +} +static QVariant intNe(const QVariant&o1,const QVariant&o2,Engine&) +{ + return o1.toLongLong()!=o2.toLongLong(); +} + int IntEngine::intParserPrio() { @@ -123,6 +148,12 @@ void IntEngine::configureIntEngine(ELAM::Engine& eng) eng.unaryOperator("+").setCallback(intPlus,iid); eng.unaryOperator("~").setCallback(intNot,iid); //binaries + eng.binaryOperator("==",60).setCallback(intEq,iid,iid); + eng.binaryOperator("!=",60).setCallback(intNe,iid,iid); + eng.binaryOperator("<=",60).setCallback(intLe,iid,iid); + eng.binaryOperator(">=",60).setCallback(intGe,iid,iid); + eng.binaryOperator("<",60).setCallback(intLt,iid,iid); + eng.binaryOperator(">",60).setCallback(intGt,iid,iid); eng.binaryOperator("-",80).setCallback(intMinus,iid,iid); eng.binaryOperator("+",80).setCallback(intAdd,iid,iid); eng.binaryOperator("*",90).setCallback(intMult,iid,iid); diff --git a/src/elamstringengine.cpp b/src/elamstringengine.cpp index 8ec10c4..559fb15 100644 --- a/src/elamstringengine.cpp +++ b/src/elamstringengine.cpp @@ -143,6 +143,17 @@ static QVariant strAdd(const QVariant&o1,const QVariant&o2,Engine&) return o1.toString()+o2.toString(); } +//compare +static QVariant strEq(const QVariant&o1,const QVariant&o2,Engine&) +{ + return o1.toString()==o2.toString(); +} +static QVariant strNe(const QVariant&o1,const QVariant&o2,Engine&) +{ + return o1.toString()!=o2.toString(); +} + + int StringEngine::stringParserPrio() { return 50; @@ -163,7 +174,13 @@ void StringEngine::configureStringEngine(Engine& eng) eng.setFunction("strlen",strlenFunc); eng.setFunction("concat",concatFunc); //operators + eng.binaryOperator("==",60).setCallback(strEq,sid,sid); + eng.binaryOperator("==").setCallback(strEq,aid,sid); + eng.binaryOperator("==").setCallback(strEq,sid,aid); + eng.binaryOperator("!=",60).setCallback(strNe,sid,sid); + eng.binaryOperator("!=").setCallback(strNe,sid,aid); + eng.binaryOperator("!=").setCallback(strNe,aid,sid); eng.binaryOperator("+",80).setCallback(strAdd,sid,sid); - eng.binaryOperator("+",80).setCallback(strAdd,aid,sid); - eng.binaryOperator("+",80).setCallback(strAdd,sid,aid); + eng.binaryOperator("+").setCallback(strAdd,aid,sid); + eng.binaryOperator("+").setCallback(strAdd,sid,aid); }