/// <summary> /// Execute the calculation expression. /// exp: a+b /// /// Only int or double type are authorized. /// /// todo: +tard: pour les strings si opérateur +/Plus, faire une concaténation! /// </summary> /// <param name="exprExecResult"></param> /// <param name="exprLogicalNot"></param> /// <param name="exprExecBase"></param> /// <returns></returns> private bool ExecExpressionCalculation(ExecResult execResult, ExprCalculation exprCalculation, out ExpressionExecBase exprExecBase) { // the final result of the execution exprExecBase = null; // check the number of operands if (exprCalculation.ListExprOperand.Count > Definitions.ExprCalculationMaxOperandsCount) { execResult.AddErrorExec(ErrorCode.ExprCalculationTooManyOperands, "Content", exprExecBase.Expr.Token.Value, "Position", exprExecBase.Expr.Token.Position.ToString()); return(false); } // first execute all operands, one by one List <ExpressionExecBase> listExprExecBase; if (!ExecListExpression(execResult, exprCalculation.ListExprOperand, out listExprExecBase)) { // an error occurs return(false); } // check that all operand types are expected: int or double only if (!CheckTypeOperandExprCalculation(execResult, listExprExecBase)) { // an error occurs return(false); } // execute the calculation ExprExecutorCalculation exprExecutorCalculation = new ExprExecutorCalculation(); return(exprExecutorCalculation.Process(execResult, exprCalculation, listExprExecBase, out exprExecBase)); }
/// <summary> /// check that all operand types are expected: int or double only. /// TODO: string? for concatenation? later. /// /// </summary> /// <param name="execResult"></param> /// <param name="listExpr"></param> /// <returns></returns> private bool CheckTypeOperandExprCalculation(ExecResult execResult, List <ExpressionExecBase> listExprExecBase) { bool ret = true; foreach (ExpressionExecBase exprExecBase in listExprExecBase) { // is it an int? ExprExecValueInt exprInt = exprExecBase as ExprExecValueInt; if (exprInt != null) { // yes! continue; } // is it a double? ExprExecValueDouble exprDouble = exprExecBase as ExprExecValueDouble; if (exprDouble == null) { // neither an int or a double , error! execResult.AddErrorExec(ErrorCode.ExprCalculationOperandTypeUnExcepted, "Content", exprExecBase.Expr.Token.Value, "Position", exprExecBase.Expr.Token.Position.ToString()); ret = false; } } return(ret); }
/// <summary> /// Not Operand. /// The operand must be a bool: final operand, expression that return a bool. /// </summary> /// <param name="exprExecResult"></param> /// <param name="exprLogicalNot"></param> /// <param name="exprExecBase"></param> /// <returns></returns> private bool ExecExpressionLogicalNot(ExecResult exprExecResult, ExprLogicalNot exprLogicalNot, out ExpressionExecBase exprExecBase) { exprExecBase = null; //----first step is to decode/compile the operand ExpressionExecBase exprExecOperand; ExecExpression(exprExecResult, exprLogicalNot.ExprBase, out exprExecOperand); // the operand must be a bool value ExprExecValueBool exprExecValueBool = exprExecOperand as ExprExecValueBool; if (exprExecValueBool == null) { // bool type expected for the operand inner the not logical expression, but the operand has another type string strPosition = "0"; string strToken = ""; if (exprLogicalNot.ExprBase.Token != null) { strPosition = exprLogicalNot.ExprBase.Token.Position.ToString(); strToken = exprLogicalNot.ExprBase.Token.Value.ToString(); } _expressionData.ExprExecResult.AddErrorExec(ErrorCode.ExprLogicalNotOperator_InnerOperandBoolTypeExpected, "Token", strToken, "Position", strPosition); return(false); } // ok, the operand is a bool value // ok, execute the NOT logical ExprExecValueBool exprValueBoolResult = new ExprExecValueBool(); exprValueBoolResult.Value = !(exprExecValueBool.Value); exprExecBase = exprValueBoolResult; return(true); }
/// <summary> /// Execute a functionCall. /// First execute parameters and then execute the function code attached/linked. /// </summary> /// <param name="exprExecResult"></param> /// <param name="exprFunctionCall"></param> /// <param name="exprExecBase"></param> /// <returns></returns> private bool ExecExpressionFunctionCall(ExecResult exprExecResult, ExprFunctionCall exprFunctionCall, out ExpressionExecBase exprExecBase) { ExpressionExecBase exprExecParamBase; List <ExpressionExecBase> listExprExecParam = new List <ExpressionExecBase>(); bool res = true; exprExecBase = null; // get the function code FunctionToCallMapper functionToCallMapper = _exprEvalConfig.ListFunctionToCallMapper.Find(f => f.FunctionCallName.Equals(exprFunctionCall.FunctionName, StringComparison.InvariantCultureIgnoreCase)); if (functionToCallMapper == null) { // error exprExecResult.AddErrorExec(ErrorCode.FunctionCallNotLinked, "FunctionCallName", exprFunctionCall.FunctionName); return(false); } // execute params of the function foreach (ExpressionBase exprParam in exprFunctionCall.ListExprParameters) { res &= ExecExpression(exprExecResult, exprParam, out exprExecParamBase); listExprExecParam.Add(exprExecParamBase); } // a param execution failed if (!res) { return(false); } // execute the function code attached to the functionCall, provide executed params return(_exprExecutorFunctionCall.ExecExpressionFunctionCall(exprExecResult, exprFunctionCall, functionToCallMapper, listExprExecParam, out exprExecBase)); }
private bool CheckVariableSyntax(ExecResult exprExecResult, string varName) { if (string.IsNullOrWhiteSpace(varName)) { _expressionData.ExprExecResult.AddErrorExec(ErrorCode.VarNameSyntaxWrong, "SyntaxErrorType", "IsNullOrWhiteSpace"); return(false); } // check the syntax, the first char should be: a letter, or underscore if (!char.IsLetter(varName[0]) && varName[0] != '_') { _expressionData.ExprExecResult.AddErrorExec(ErrorCode.VarNameSyntaxWrong, "SyntaxErrorType", "FirstCharIsWrong"); return(false); } if (varName.Length == 1) { return(true); } // check next chars (if exists) for (int i = 0; i < varName.Length; i++) { if (!char.IsLetterOrDigit(varName[i])) { _expressionData.ExprExecResult.AddErrorExec(ErrorCode.VarNameSyntaxWrong, "SyntaxErrorType", "OneCharOrMoreIsWrong"); return(false); } } return(true); }
/// <summary> /// a+b -> a+b /// a*b -> ?? cas particulier /// a+b*c -> a+(b*c) /// a*b+c*d -> (a*b)+(c*d) /// </summary> /// <param name="execResult"></param> /// <param name="exprCalculation"></param> /// <param name="listExprExecBase"></param> /// <param name="listCalcAdd"></param> /// <returns></returns> private bool BuildCalculationExpressionWithPriority(ExecResult execResult, ExprCalculation exprCalculation, List <ExpressionExecBase> listExprExecBase, out ExprExecCalcAdd mainCalcAdd) { // init the main additions/sub mainCalcAdd = new ExprExecCalcAdd(); //bool currOperatorIsAdd = true; CalcOperatorTypeWF calcOperatorTypeWF = CalcOperatorTypeWF.Nothing; ExprExecCalcMul exprExecCalcMul = null; int pos = 0; // scan operators while (true) { // no more operator or operand if (pos >= exprCalculation.ListOperator.Count) { // the current calc operation is an add? if (calcOperatorTypeWF == CalcOperatorTypeWF.Plus) { // the current calc operation is an add/sub; add the last operand mainCalcAdd.AddOperandNumber(listExprExecBase[pos]); return(true); } else { // the current calc operation is an mul/div exprExecCalcMul.AddOperandNumber(listExprExecBase[pos]); return(true); } } // todo: sur?? il y a un operande de plus que les opérateurs if (pos >= listExprExecBase.Count) { break; } // analyze the current operator: its an add/sous or a mul/div CalcOperatorTypeWF calcOperatorTypeWFOut; ExprExecCalcMul exprExecCalcMulOut; if (!BuildCalcExprProcessOperator(execResult, exprCalculation, listExprExecBase, mainCalcAdd, pos, calcOperatorTypeWF, exprExecCalcMul, out calcOperatorTypeWFOut, out exprExecCalcMulOut)) { return(false); } // the workflow is updated by the function calcOperatorTypeWF = calcOperatorTypeWFOut; exprExecCalcMul = exprExecCalcMulOut; // goto next operator/operand pos++; } return(true); }
public bool GetCheckParamDouble(ExecResult exprExecResult, string functionCallName, ExpressionExecBase param, out ExprExecValueDouble exprParamDouble) { exprParamDouble = param as ExprExecValueDouble; if (exprParamDouble == null) { exprExecResult.AddErrorExec(ErrorCode.FunctionCallParamTypeWrong, "FunctionCallName", functionCallName, "ParamTypeExpected", "double"); //, "ParamType", param.GetType().ToString()); return(false); } return(true); }
/// <summary> /// error occurs on executing the function. /// /// </summary> /// <param name="exprExecResult"></param> /// <param name="e"></param> /// <returns></returns> public bool AddErrorExecFailed(ExecResult exprExecResult, Exception e) { string innerException = ""; if (e.InnerException != null) { innerException = e.InnerException.ToString(); } exprExecResult.AddErrorExec(ErrorCode.FunctionCallExecException, "Message", e.Message, "InnerException", innerException); return(false); }
/// <summary> /// analyze the current operator: its an add/sous or a mul/div. /// /// </summary> /// <param name="execResult"></param> /// <param name="exprCalculation"></param> /// <returns></returns> private bool BuildCalcExprProcessOperator(ExecResult execResult, ExprCalculation exprCalculation, List <ExpressionExecBase> listExprExecBase, ExprExecCalcAdd mainCalcAdd, int pos, CalcOperatorTypeWF calcOperatorTypeWFIn, ExprExecCalcMul exprExecCalcMulIn, out CalcOperatorTypeWF calcOperatorTypeWFOut, out ExprExecCalcMul exprExecCalcMulOut) { exprExecCalcMulOut = null; if (exprCalculation.ListOperator[pos].Operator == OperatorCalculationCode.Plus || exprCalculation.ListOperator[pos].Operator == OperatorCalculationCode.Minus) { // manage the previous case, exp: 2*3+4 -> (2*3)+4 finish the 2*3 mul expr and continue the addition if (calcOperatorTypeWFIn == CalcOperatorTypeWF.Mul) { // add the last operand to the mul expr exprExecCalcMulIn.AddOperandNumber(listExprExecBase[pos]); exprExecCalcMulOut = exprExecCalcMulIn; // now its an addition expression calcOperatorTypeWFOut = CalcOperatorTypeWF.Plus; //mainCalcAdd.AddOperandNumber(listExprExecBase[pos]); mainCalcAdd.ListOperator.Add(exprCalculation.ListOperator[pos]); return(true); } // the operator is a + (addition) calcOperatorTypeWFOut = CalcOperatorTypeWF.Plus; // save the current operand value and the current operator mainCalcAdd.AddOperandNumber(listExprExecBase[pos]); mainCalcAdd.ListOperator.Add(exprCalculation.ListOperator[pos]); return(true); } // its the first operator of the expression or the previous operator was: +/plus if (calcOperatorTypeWFIn == CalcOperatorTypeWF.Nothing || calcOperatorTypeWFIn == CalcOperatorTypeWF.Plus) { // start a new calc expression exprExecCalcMulOut = new ExprExecCalcMul(); exprExecCalcMulOut.AddOperandNumber(listExprExecBase[pos]); exprExecCalcMulOut.ListOperator.Add(exprCalculation.ListOperator[pos]); calcOperatorTypeWFOut = CalcOperatorTypeWF.Mul; // save it in the main addition expression mainCalcAdd.ListExprExecCalc.Add(exprExecCalcMulOut); return(true); } // the previous operator is a mul exprExecCalcMulIn.AddOperandNumber(listExprExecBase[pos]); exprExecCalcMulIn.ListOperator.Add(exprCalculation.ListOperator[pos]); calcOperatorTypeWFOut = CalcOperatorTypeWF.Mul; exprExecCalcMulOut = exprExecCalcMulIn; return(true); }
/// <summary> /// Do the calculation of the multiplication/division expr comme l'add mais le rs va remplacer l'objet Mul dans le main add) /// /// </summary> /// <param name="execResult"></param> /// <param name="exprCalculation"></param> /// <param name="mainCalcAdd"></param> /// <param name="exprExecCalcResult"></param> /// <returns></returns> private bool DoCalculationExprMul(ExecResult execResult, ExprCalculation exprCalculation, ExprExecCalcMul execCalcMul, out ExprExecCalcValue execCalcValueResult) { // the temporary result, to start the addition calculation ExprExecValueInt resInt = new ExprExecValueInt(); // the integer neutral value, the first calculation is 1*operand[0] resInt.Value = 1; ExpressionExecBase exprExecCalcResult = resInt; ExpressionExecBase exprExecTmpResult = null; int pos = 0; // scan addition expressions, two by two operands foreach (ExprExecCalcValue execCalcValue in execCalcMul.ListExprExecCalcValue) { // the item should be a number: an int or a double // get the operator ExprOperatorCalculation operatorCalc; // the first calc is special: res := 0 + firstOperand if (pos == 0) { // put the default neutral operator: + operatorCalc = new ExprOperatorCalculation(); operatorCalc.Operator = OperatorCalculationCode.Multiplication; //operatorCalc.Token = mainCalcAdd.ListOperator[0].Token; } else { // there one operator less than operand operatorCalc = execCalcMul.ListOperator[pos - 1]; } // Do the calculation: tmpRes := res +/- currentValue DoCalculationTwoOperands(execResult, exprCalculation, exprExecCalcResult, execCalcValue.ExprExecValue, operatorCalc, out exprExecTmpResult); // the current temporary result exprExecCalcResult = exprExecTmpResult; pos++; } // then replace the calc mul expr by the result execCalcValueResult = new ExprExecCalcValue(); execCalcValueResult.ExprExecValue = exprExecTmpResult; //mainCalcAdd.ListExprExecCalc[posMulInMainAdd] = execCalcValueResult; return(true); }
/// <summary> /// Execute/evaluate the addition main expression. /// </summary> /// <param name="execResult"></param> /// <param name="exprCalculation"></param> /// <param name="listCalcAdd"></param> /// <returns></returns> private bool DoCalculationMainExprAdditions(ExecResult execResult, ExprCalculation exprCalculation, ExprExecCalcAdd mainCalcAdd, out ExpressionExecBase exprExecCalcResult) { // the temporary result, to start the addition calculation ExprExecValueInt resInt = new ExprExecValueInt(); // the integer neutral value, the first calculation is 0+operand[0] resInt.Value = 0; exprExecCalcResult = resInt; ExpressionExecBase exprExecTmpResult; int pos = 0; // scan addition expressions, two by two operands foreach (ExprExecCalcBase execCalcBase in mainCalcAdd.ListExprExecCalc) { // the item should be a number: an int or a double ExprExecCalcValue execCalcValue = execCalcBase as ExprExecCalcValue; // get the operator ExprOperatorCalculation operatorCalc; // the first calc is special: res := 0 + firstOperand if (pos == 0) { // put the default neutral operator: + operatorCalc = new ExprOperatorCalculation(); operatorCalc.Operator = OperatorCalculationCode.Plus; if (mainCalcAdd.ListOperator.Count > 0) { operatorCalc.Token = mainCalcAdd.ListOperator[0].Token; } } else { // there one operator less than operand operatorCalc = mainCalcAdd.ListOperator[pos - 1]; } // Do the calculation: tmpRes := res +/- currentValue DoCalculationTwoOperands(execResult, exprCalculation, exprExecCalcResult, execCalcValue.ExprExecValue, operatorCalc, out exprExecTmpResult); // the current temporary result exprExecCalcResult = exprExecTmpResult; pos++; } return(true); }
/// <summary> /// Execute/evaluate each operand. /// Return a list of exprExec. /// </summary> /// <param name="exprExecResult"></param> /// <param name="listExprBase"></param> /// <param name="listExprExecBase"></param> /// <returns></returns> private bool ExecListExpression(ExecResult execResult, List <ExpressionBase> listExprBase, out List <ExpressionExecBase> listExprExecBase) { listExprExecBase = new List <ExpressionExecBase>(); ExpressionExecBase exprExecBase; bool res = true; foreach (ExpressionBase exprBase in listExprBase) { // execute/evaluate the expression if (!ExecExpression(execResult, exprBase, out exprExecBase)) { res = false; continue; } listExprExecBase.Add(exprExecBase); } return(res); }
/// <summary> /// Process the calculation expression. /// The expression can have two operands (one operator) at least and more. /// /// exp: a+b, a+b*c /// /// Manage the operator priority: multiplication and division first, then addition and substraction. /// a+b*c -> a+(b*c) /// /// </summary> /// <param name="execResult"></param> /// <param name="exprCalculation"></param> /// <param name="listExprExecBase"></param> /// <param name="exprExecCalcResult"></param> /// <returns></returns> public bool Process(ExecResult execResult, ExprCalculation exprCalculation, List <ExpressionExecBase> listExprExecBase, out ExpressionExecBase exprExecCalcResult) { exprExecCalcResult = null; //----organize calculation depending on operators priority: plus and mul ExprExecCalcAdd mainCalcAdd; // build expression with priority: first calculate mult and div, and then add and minus. if (!BuildCalculationExpressionWithPriority(execResult, exprCalculation, listExprExecBase, out mainCalcAdd)) { return(false); } //----do the calculation of all sub expression multiplications if (!DoCalculationSubExprMul(execResult, exprCalculation, mainCalcAdd)) { return(false); } //----do the calculation main expression additions return(DoCalculationMainExprAdditions(execResult, exprCalculation, mainCalcAdd, out exprExecCalcResult)); }
/// <summary> /// Exec the function call, return a string value. /// can have any, one or more parameters. /// </summary> /// <param name="exprExecResult"></param> /// <param name="functionToCallMapper"></param> /// <param name="exprExecFunctionCallBool"></param> /// <param name="listExprExecParam"></param> /// <param name="exprExecBase"></param> /// <returns></returns> public bool Exec(ExecResult exprExecResult, ExprExecFunctionCallString exprExecFunctionCallString, List <ExpressionExecBase> listExprExecParam, out ExpressionExecBase exprExecBase) { exprExecBase = null; string res; bool caseManaged; if (!ExecFuncRetString_Params(exprExecResult, exprExecFunctionCallString, listExprExecParam, out caseManaged, out res)) { // an error occurs return(false); } if (!caseManaged) { exprExecResult.AddErrorExec(ErrorCode.ExpressionTypeNotYetImplemented, "Type", "FunctionCall"); return(false); } // execute the function linked to the functionCall found in the expression exprExecFunctionCallString.Value = res; exprExecBase = exprExecFunctionCallString; return(true); }
/// <summary> /// Check one parameter of a function call. /// </summary> /// <param name="exprExecResult"></param> /// <param name="functionToCallMapper"></param> /// <param name="listExprExecParam"></param> /// <param name="paramNum"></param> /// <param name="dataType"></param> /// <returns></returns> private bool CheckParam(ExecResult exprExecResult, FunctionToCallMapper functionToCallMapper, List <ExpressionExecBase> listExprExecParam, int paramNum, DataType dataType) { // check param //if (dataType == DataType.NotDefined) //{ // ici(); // // any parameter // if (listExprExecParam.Count > paramNum) // { // // error! too many parameters provided // exprExecResult.AddError(ExecErrorCode.ExprFunctionCallParamCountWrong, "ParamExpectedCount", (paramNum).ToString(), "ParamFoundCount", listExprExecParam.Count.ToString()); // return false; // } // // the param type is set to NotDefined // return true; //} //// at least one parameter is expected //if (listExprExecParam.Count < paramNum) //{ // // errror! not enought provided parameters // exprExecResult.AddError(ExecErrorCode.ExprFunctionCallParamCountWrong, "ParamExpectedCount", (paramNum).ToString(), "ParamFoundCount", listExprExecParam.Count.ToString()); // return false; //} if (dataType == DataType.NotDefined) { return(true); } // check param, should be a bool if (dataType == DataType.Bool) { // check the type of the param ExprExecValueBool exprParamBool; if (!GetCheckParamBool(exprExecResult, functionToCallMapper.FunctionCallName, listExprExecParam[paramNum - 1], out exprParamBool)) { return(false); } // the param1 is ok return(true); } // check param, should be an int if (dataType == DataType.Int) { // check the type of the param ExprExecValueInt exprParamInt; if (!GetCheckParamInt(exprExecResult, functionToCallMapper.FunctionCallName, listExprExecParam[paramNum - 1], out exprParamInt)) { return(false); } // the param1 is ok return(true); } // string if (dataType == DataType.String) { // check the type of the param ExprExecValueString exprParamString; if (!GetCheckParamString(exprExecResult, functionToCallMapper.FunctionCallName, listExprExecParam[paramNum - 1], out exprParamString)) { return(false); } // the param is ok return(true); } // check param, should be a double // check the type of the param ExprExecValueDouble exprParamDouble; if (!GetCheckParamDouble(exprExecResult, functionToCallMapper.FunctionCallName, listExprExecParam[paramNum - 1], out exprParamDouble)) { return(false); } // the param is ok return(true); }
private bool ExecExpressionFinalOperand(ExecResult exprExecResult, ExprFinalOperand finalOperand, out ExpressionExecBase exprExecBase) { // is the operand a variable or a call function? if (finalOperand.ContentType == OperandType.ObjectName) { // is it a variable? ExprVariableBase exprVariableBase = _expressionData.ExprExecResult.ListExprVariable.Find(v => v.Name.Equals(finalOperand.Operand, StringComparison.InvariantCultureIgnoreCase)); if (exprVariableBase != null) { // the operand is a string variable? ExprVariableString exprVariableString = exprVariableBase as ExprVariableString; if (exprVariableString != null) { // create a var instance, depending on the type ExprExecVarString exprExecVar = new ExprExecVarString(); exprExecVar.ExprVariableString = exprVariableString; exprExecVar.Expr = finalOperand; // set the value exprExecVar.Value = exprVariableString.Value; exprExecBase = exprExecVar; return(true); } // the operand is an int variable? ExprVariableInt exprVariableInt = exprVariableBase as ExprVariableInt; if (exprVariableInt != null) { // create a var instance, depending on the type ExprExecVarInt exprExecVar = new ExprExecVarInt(); exprExecVar.ExprVariableInt = exprVariableInt; exprExecVar.Expr = finalOperand; // set the value exprExecVar.Value = exprVariableInt.Value; exprExecBase = exprExecVar; return(true); } // the operand is a double variable? ExprVariableDouble exprVariableDouble = exprVariableBase as ExprVariableDouble; if (exprVariableDouble != null) { // create a var instance, depending on the type ExprExecVarDouble exprExecVar = new ExprExecVarDouble(); exprExecVar.ExprVariableDouble = exprVariableDouble; exprExecVar.Expr = finalOperand; // set the value exprExecVar.Value = exprVariableDouble.Value; exprExecBase = exprExecVar; return(true); } // the operand is a bool variable? ExprVariableBool exprVariableBool = exprVariableBase as ExprVariableBool; if (exprVariableBool != null) { // create a var instance, depending on the type ExprExecVarBool exprExecVar = new ExprExecVarBool(); exprExecVar.ExprVariableBool = exprVariableBool; exprExecVar.Expr = finalOperand; // set the value exprExecVar.Value = exprVariableBool.Value; exprExecBase = exprExecVar; return(true); } // todo; create an error throw new Exception("The operand variable type is not yet implemented!"); } // so its a function call // todo: rechercher dans la liste des fonctions? throw new Exception("The function call is not yet implemented!"); } // is the operand a string value (a const string value)? if (finalOperand.ContentType == OperandType.ValueString) { ExprExecValueString exprValueString = new ExprExecValueString(); exprValueString.Value = finalOperand.Operand; exprExecBase = exprValueString; exprValueString.Expr = finalOperand; return(true); } // is the operand an int value? if (finalOperand.ContentType == OperandType.ValueInt) { ExprExecValueInt exprValueInt = new ExprExecValueInt(); exprValueInt.Expr = finalOperand; exprValueInt.Value = finalOperand.ValueInt; exprExecBase = exprValueInt; return(true); } // is the operand a double value? if (finalOperand.ContentType == OperandType.ValueDouble) { ExprExecValueDouble exprValueDouble = new ExprExecValueDouble(); exprValueDouble.Expr = finalOperand; exprValueDouble.Value = finalOperand.ValueDouble; exprExecBase = exprValueDouble; return(true); } // is the operand a bool value? if (finalOperand.ContentType == OperandType.ValueBool) { ExprExecValueBool exprValueBool = new ExprExecValueBool(); exprValueBool.Expr = finalOperand; exprValueBool.Value = finalOperand.ValueBool; exprExecBase = exprValueBool; return(true); } // todo: create an error throw new Exception("The operand const value is not yet implemented!"); }
//====================================================================== #region Private methods. /// <summary> /// Execute the function code attached to the function call. /// /// </summary> /// <param name="exprExecResult"></param> /// <param name="exprExecFunctionCallBool"></param> /// <param name="listExprExecParam"></param> /// <param name="exprExecBase"></param> /// <returns></returns> private bool ExecFuncRetString_Params(ExecResult exprExecResult, ExprExecFunctionCallString exprExecFunctionCallString, List <ExpressionExecBase> listExprExecParam, out bool caseManaged, out string res) { caseManaged = false; res = ""; // not enought or too many parameter //if (!CheckParamsCount(exprExecResult, listExprExecParam, 1)) // return false; try { // check the parameters, according to the definition if (!CheckParams(exprExecResult, exprExecFunctionCallString.FunctionToCallMapper, listExprExecParam)) { return(false); } //===========================RetString, any parameter if (exprExecFunctionCallString.FunctionToCallMapper.MethodSignature == MethodSignatureType.RetString) { res = exprExecFunctionCallString.FunctionToCallMapper.FuncString.Invoke(); caseManaged = true; return(true); } //===========================RetString, one parameter if (exprExecFunctionCallString.FunctionToCallMapper.MethodSignature == MethodSignatureType.RetString_Bool) { res = exprExecFunctionCallString.FunctionToCallMapper.FuncString_Bool.Invoke((listExprExecParam[0] as ExprExecValueBool).Value); caseManaged = true; return(true); } if (exprExecFunctionCallString.FunctionToCallMapper.MethodSignature == MethodSignatureType.RetString_Int) { res = exprExecFunctionCallString.FunctionToCallMapper.FuncString_Int.Invoke((listExprExecParam[0] as ExprExecValueInt).Value); caseManaged = true; return(true); } if (exprExecFunctionCallString.FunctionToCallMapper.MethodSignature == MethodSignatureType.RetString_String) { res = exprExecFunctionCallString.FunctionToCallMapper.FuncString_String.Invoke((listExprExecParam[0] as ExprExecValueString).Value); caseManaged = true; return(true); } if (exprExecFunctionCallString.FunctionToCallMapper.MethodSignature == MethodSignatureType.RetString_Double) { res = exprExecFunctionCallString.FunctionToCallMapper.FuncString_Double.Invoke((listExprExecParam[0] as ExprExecValueDouble).Value); caseManaged = true; return(true); } //===========================RetString, two parameters if (exprExecFunctionCallString.FunctionToCallMapper.MethodSignature == MethodSignatureType.RetString_Bool_Bool) { res = exprExecFunctionCallString.FunctionToCallMapper.FuncString_Bool_Bool.Invoke((listExprExecParam[0] as ExprExecValueBool).Value, (listExprExecParam[1] as ExprExecValueBool).Value); caseManaged = true; return(true); } if (exprExecFunctionCallString.FunctionToCallMapper.MethodSignature == MethodSignatureType.RetString_Bool_Int) { res = exprExecFunctionCallString.FunctionToCallMapper.FuncString_Bool_Int.Invoke((listExprExecParam[0] as ExprExecValueBool).Value, (listExprExecParam[1] as ExprExecValueInt).Value); caseManaged = true; return(true); } if (exprExecFunctionCallString.FunctionToCallMapper.MethodSignature == MethodSignatureType.RetString_Bool_String) { res = exprExecFunctionCallString.FunctionToCallMapper.FuncString_Bool_String.Invoke((listExprExecParam[0] as ExprExecValueBool).Value, (listExprExecParam[1] as ExprExecValueString).Value); caseManaged = true; return(true); } if (exprExecFunctionCallString.FunctionToCallMapper.MethodSignature == MethodSignatureType.RetString_Bool_Double) { res = exprExecFunctionCallString.FunctionToCallMapper.FuncString_Bool_Double.Invoke((listExprExecParam[0] as ExprExecValueBool).Value, (listExprExecParam[1] as ExprExecValueDouble).Value); caseManaged = true; return(true); } if (exprExecFunctionCallString.FunctionToCallMapper.MethodSignature == MethodSignatureType.RetString_Int_Bool) { res = exprExecFunctionCallString.FunctionToCallMapper.FuncString_Int_Bool.Invoke((listExprExecParam[0] as ExprExecValueInt).Value, (listExprExecParam[1] as ExprExecValueBool).Value); caseManaged = true; return(true); } if (exprExecFunctionCallString.FunctionToCallMapper.MethodSignature == MethodSignatureType.RetString_Int_Int) { res = exprExecFunctionCallString.FunctionToCallMapper.FuncString_Int_Int.Invoke((listExprExecParam[0] as ExprExecValueInt).Value, (listExprExecParam[1] as ExprExecValueInt).Value); caseManaged = true; return(true); } if (exprExecFunctionCallString.FunctionToCallMapper.MethodSignature == MethodSignatureType.RetString_Int_String) { res = exprExecFunctionCallString.FunctionToCallMapper.FuncString_Int_String.Invoke((listExprExecParam[0] as ExprExecValueInt).Value, (listExprExecParam[1] as ExprExecValueString).Value); caseManaged = true; return(true); } if (exprExecFunctionCallString.FunctionToCallMapper.MethodSignature == MethodSignatureType.RetString_Int_Double) { res = exprExecFunctionCallString.FunctionToCallMapper.FuncString_Int_Double.Invoke((listExprExecParam[0] as ExprExecValueInt).Value, (listExprExecParam[1] as ExprExecValueDouble).Value); caseManaged = true; return(true); } if (exprExecFunctionCallString.FunctionToCallMapper.MethodSignature == MethodSignatureType.RetString_String_Bool) { res = exprExecFunctionCallString.FunctionToCallMapper.FuncString_String_Bool.Invoke((listExprExecParam[0] as ExprExecValueString).Value, (listExprExecParam[1] as ExprExecValueBool).Value); caseManaged = true; return(true); } if (exprExecFunctionCallString.FunctionToCallMapper.MethodSignature == MethodSignatureType.RetString_String_Int) { res = exprExecFunctionCallString.FunctionToCallMapper.FuncString_String_Int.Invoke((listExprExecParam[0] as ExprExecValueString).Value, (listExprExecParam[1] as ExprExecValueInt).Value); caseManaged = true; return(true); } if (exprExecFunctionCallString.FunctionToCallMapper.MethodSignature == MethodSignatureType.RetString_String_String) { res = exprExecFunctionCallString.FunctionToCallMapper.FuncString_String_String.Invoke((listExprExecParam[0] as ExprExecValueString).Value, (listExprExecParam[1] as ExprExecValueString).Value); caseManaged = true; return(true); } if (exprExecFunctionCallString.FunctionToCallMapper.MethodSignature == MethodSignatureType.RetString_String_Double) { res = exprExecFunctionCallString.FunctionToCallMapper.FuncString_String_Double.Invoke((listExprExecParam[0] as ExprExecValueString).Value, (listExprExecParam[1] as ExprExecValueDouble).Value); caseManaged = true; return(true); } if (exprExecFunctionCallString.FunctionToCallMapper.MethodSignature == MethodSignatureType.RetString_Double_Bool) { res = exprExecFunctionCallString.FunctionToCallMapper.FuncString_Double_Bool.Invoke((listExprExecParam[0] as ExprExecValueDouble).Value, (listExprExecParam[1] as ExprExecValueBool).Value); caseManaged = true; return(true); } if (exprExecFunctionCallString.FunctionToCallMapper.MethodSignature == MethodSignatureType.RetString_Double_Int) { res = exprExecFunctionCallString.FunctionToCallMapper.FuncString_Double_Int.Invoke((listExprExecParam[0] as ExprExecValueDouble).Value, (listExprExecParam[1] as ExprExecValueInt).Value); caseManaged = true; return(true); } if (exprExecFunctionCallString.FunctionToCallMapper.MethodSignature == MethodSignatureType.RetString_Double_String) { res = exprExecFunctionCallString.FunctionToCallMapper.FuncString_Double_String.Invoke((listExprExecParam[0] as ExprExecValueDouble).Value, (listExprExecParam[1] as ExprExecValueString).Value); caseManaged = true; return(true); } if (exprExecFunctionCallString.FunctionToCallMapper.MethodSignature == MethodSignatureType.RetString_Double_Double) { res = exprExecFunctionCallString.FunctionToCallMapper.FuncString_Double_Double.Invoke((listExprExecParam[0] as ExprExecValueDouble).Value, (listExprExecParam[1] as ExprExecValueDouble).Value); caseManaged = true; return(true); } //===========================RetString, 3 parameters if (exprExecFunctionCallString.FunctionToCallMapper.MethodSignature == MethodSignatureType.RetString_Bool_Bool_Bool) { res = exprExecFunctionCallString.FunctionToCallMapper.FuncString_Bool_Bool_Bool.Invoke((listExprExecParam[0] as ExprExecValueBool).Value, (listExprExecParam[1] as ExprExecValueBool).Value, (listExprExecParam[2] as ExprExecValueBool).Value); caseManaged = true; return(true); } if (exprExecFunctionCallString.FunctionToCallMapper.MethodSignature == MethodSignatureType.RetString_Bool_Bool_Int) { res = exprExecFunctionCallString.FunctionToCallMapper.FuncString_Bool_Bool_Int.Invoke((listExprExecParam[0] as ExprExecValueBool).Value, (listExprExecParam[1] as ExprExecValueBool).Value, (listExprExecParam[2] as ExprExecValueInt).Value); caseManaged = true; return(true); } if (exprExecFunctionCallString.FunctionToCallMapper.MethodSignature == MethodSignatureType.RetString_Bool_Bool_String) { res = exprExecFunctionCallString.FunctionToCallMapper.FuncString_Bool_Bool_String.Invoke((listExprExecParam[0] as ExprExecValueBool).Value, (listExprExecParam[1] as ExprExecValueBool).Value, (listExprExecParam[2] as ExprExecValueString).Value); caseManaged = true; return(true); } if (exprExecFunctionCallString.FunctionToCallMapper.MethodSignature == MethodSignatureType.RetString_Bool_Bool_Double) { res = exprExecFunctionCallString.FunctionToCallMapper.FuncString_Bool_Bool_Double.Invoke((listExprExecParam[0] as ExprExecValueBool).Value, (listExprExecParam[1] as ExprExecValueBool).Value, (listExprExecParam[2] as ExprExecValueDouble).Value); caseManaged = true; return(true); } if (exprExecFunctionCallString.FunctionToCallMapper.MethodSignature == MethodSignatureType.RetString_Bool_Int_Bool) { res = exprExecFunctionCallString.FunctionToCallMapper.FuncString_Bool_Int_Bool.Invoke((listExprExecParam[0] as ExprExecValueBool).Value, (listExprExecParam[1] as ExprExecValueInt).Value, (listExprExecParam[2] as ExprExecValueBool).Value); caseManaged = true; return(true); } if (exprExecFunctionCallString.FunctionToCallMapper.MethodSignature == MethodSignatureType.RetString_Bool_Int_Int) { res = exprExecFunctionCallString.FunctionToCallMapper.FuncString_Bool_Int_Int.Invoke((listExprExecParam[0] as ExprExecValueBool).Value, (listExprExecParam[1] as ExprExecValueInt).Value, (listExprExecParam[2] as ExprExecValueInt).Value); caseManaged = true; return(true); } if (exprExecFunctionCallString.FunctionToCallMapper.MethodSignature == MethodSignatureType.RetString_Bool_Int_String) { res = exprExecFunctionCallString.FunctionToCallMapper.FuncString_Bool_Int_String.Invoke((listExprExecParam[0] as ExprExecValueBool).Value, (listExprExecParam[1] as ExprExecValueInt).Value, (listExprExecParam[2] as ExprExecValueString).Value); caseManaged = true; return(true); } if (exprExecFunctionCallString.FunctionToCallMapper.MethodSignature == MethodSignatureType.RetString_Bool_Int_Double) { res = exprExecFunctionCallString.FunctionToCallMapper.FuncString_Bool_Int_Double.Invoke((listExprExecParam[0] as ExprExecValueBool).Value, (listExprExecParam[1] as ExprExecValueInt).Value, (listExprExecParam[2] as ExprExecValueDouble).Value); caseManaged = true; return(true); } if (exprExecFunctionCallString.FunctionToCallMapper.MethodSignature == MethodSignatureType.RetString_Bool_String_Bool) { res = exprExecFunctionCallString.FunctionToCallMapper.FuncString_Bool_String_Bool.Invoke((listExprExecParam[0] as ExprExecValueBool).Value, (listExprExecParam[1] as ExprExecValueString).Value, (listExprExecParam[2] as ExprExecValueBool).Value); caseManaged = true; return(true); } if (exprExecFunctionCallString.FunctionToCallMapper.MethodSignature == MethodSignatureType.RetString_Bool_String_Int) { res = exprExecFunctionCallString.FunctionToCallMapper.FuncString_Bool_String_Int.Invoke((listExprExecParam[0] as ExprExecValueBool).Value, (listExprExecParam[1] as ExprExecValueString).Value, (listExprExecParam[2] as ExprExecValueInt).Value); caseManaged = true; return(true); } if (exprExecFunctionCallString.FunctionToCallMapper.MethodSignature == MethodSignatureType.RetString_Bool_String_String) { res = exprExecFunctionCallString.FunctionToCallMapper.FuncString_Bool_String_String.Invoke((listExprExecParam[0] as ExprExecValueBool).Value, (listExprExecParam[1] as ExprExecValueString).Value, (listExprExecParam[2] as ExprExecValueString).Value); caseManaged = true; return(true); } if (exprExecFunctionCallString.FunctionToCallMapper.MethodSignature == MethodSignatureType.RetString_Bool_String_Double) { res = exprExecFunctionCallString.FunctionToCallMapper.FuncString_Bool_String_Double.Invoke((listExprExecParam[0] as ExprExecValueBool).Value, (listExprExecParam[1] as ExprExecValueString).Value, (listExprExecParam[2] as ExprExecValueDouble).Value); caseManaged = true; return(true); } if (exprExecFunctionCallString.FunctionToCallMapper.MethodSignature == MethodSignatureType.RetString_Bool_Double_Bool) { res = exprExecFunctionCallString.FunctionToCallMapper.FuncString_Bool_Double_Bool.Invoke((listExprExecParam[0] as ExprExecValueBool).Value, (listExprExecParam[1] as ExprExecValueDouble).Value, (listExprExecParam[2] as ExprExecValueBool).Value); caseManaged = true; return(true); } if (exprExecFunctionCallString.FunctionToCallMapper.MethodSignature == MethodSignatureType.RetString_Bool_Double_Int) { res = exprExecFunctionCallString.FunctionToCallMapper.FuncString_Bool_Double_Int.Invoke((listExprExecParam[0] as ExprExecValueBool).Value, (listExprExecParam[1] as ExprExecValueDouble).Value, (listExprExecParam[2] as ExprExecValueInt).Value); caseManaged = true; return(true); } if (exprExecFunctionCallString.FunctionToCallMapper.MethodSignature == MethodSignatureType.RetString_Bool_Double_String) { res = exprExecFunctionCallString.FunctionToCallMapper.FuncString_Bool_Double_String.Invoke((listExprExecParam[0] as ExprExecValueBool).Value, (listExprExecParam[1] as ExprExecValueDouble).Value, (listExprExecParam[2] as ExprExecValueString).Value); caseManaged = true; return(true); } if (exprExecFunctionCallString.FunctionToCallMapper.MethodSignature == MethodSignatureType.RetString_Bool_Double_Double) { res = exprExecFunctionCallString.FunctionToCallMapper.FuncString_Bool_Double_Double.Invoke((listExprExecParam[0] as ExprExecValueBool).Value, (listExprExecParam[1] as ExprExecValueDouble).Value, (listExprExecParam[2] as ExprExecValueDouble).Value); caseManaged = true; return(true); } if (exprExecFunctionCallString.FunctionToCallMapper.MethodSignature == MethodSignatureType.RetString_Int_Bool_Bool) { res = exprExecFunctionCallString.FunctionToCallMapper.FuncString_Int_Bool_Bool.Invoke((listExprExecParam[0] as ExprExecValueInt).Value, (listExprExecParam[1] as ExprExecValueBool).Value, (listExprExecParam[2] as ExprExecValueBool).Value); caseManaged = true; return(true); } if (exprExecFunctionCallString.FunctionToCallMapper.MethodSignature == MethodSignatureType.RetString_Int_Bool_Int) { res = exprExecFunctionCallString.FunctionToCallMapper.FuncString_Int_Bool_Int.Invoke((listExprExecParam[0] as ExprExecValueInt).Value, (listExprExecParam[1] as ExprExecValueBool).Value, (listExprExecParam[2] as ExprExecValueInt).Value); caseManaged = true; return(true); } if (exprExecFunctionCallString.FunctionToCallMapper.MethodSignature == MethodSignatureType.RetString_Int_Bool_String) { res = exprExecFunctionCallString.FunctionToCallMapper.FuncString_Int_Bool_String.Invoke((listExprExecParam[0] as ExprExecValueInt).Value, (listExprExecParam[1] as ExprExecValueBool).Value, (listExprExecParam[2] as ExprExecValueString).Value); caseManaged = true; return(true); } if (exprExecFunctionCallString.FunctionToCallMapper.MethodSignature == MethodSignatureType.RetString_Int_Bool_Double) { res = exprExecFunctionCallString.FunctionToCallMapper.FuncString_Int_Bool_Double.Invoke((listExprExecParam[0] as ExprExecValueInt).Value, (listExprExecParam[1] as ExprExecValueBool).Value, (listExprExecParam[2] as ExprExecValueDouble).Value); caseManaged = true; return(true); } if (exprExecFunctionCallString.FunctionToCallMapper.MethodSignature == MethodSignatureType.RetString_Int_Int_Bool) { res = exprExecFunctionCallString.FunctionToCallMapper.FuncString_Int_Int_Bool.Invoke((listExprExecParam[0] as ExprExecValueInt).Value, (listExprExecParam[1] as ExprExecValueInt).Value, (listExprExecParam[2] as ExprExecValueBool).Value); caseManaged = true; return(true); } if (exprExecFunctionCallString.FunctionToCallMapper.MethodSignature == MethodSignatureType.RetString_Int_Int_Int) { res = exprExecFunctionCallString.FunctionToCallMapper.FuncString_Int_Int_Int.Invoke((listExprExecParam[0] as ExprExecValueInt).Value, (listExprExecParam[1] as ExprExecValueInt).Value, (listExprExecParam[2] as ExprExecValueInt).Value); caseManaged = true; return(true); } if (exprExecFunctionCallString.FunctionToCallMapper.MethodSignature == MethodSignatureType.RetString_Int_Int_String) { res = exprExecFunctionCallString.FunctionToCallMapper.FuncString_Int_Int_String.Invoke((listExprExecParam[0] as ExprExecValueInt).Value, (listExprExecParam[1] as ExprExecValueInt).Value, (listExprExecParam[2] as ExprExecValueString).Value); caseManaged = true; return(true); } if (exprExecFunctionCallString.FunctionToCallMapper.MethodSignature == MethodSignatureType.RetString_Int_Int_Double) { res = exprExecFunctionCallString.FunctionToCallMapper.FuncString_Int_Int_Double.Invoke((listExprExecParam[0] as ExprExecValueInt).Value, (listExprExecParam[1] as ExprExecValueInt).Value, (listExprExecParam[2] as ExprExecValueDouble).Value); caseManaged = true; return(true); } if (exprExecFunctionCallString.FunctionToCallMapper.MethodSignature == MethodSignatureType.RetString_Int_String_Bool) { res = exprExecFunctionCallString.FunctionToCallMapper.FuncString_Int_String_Bool.Invoke((listExprExecParam[0] as ExprExecValueInt).Value, (listExprExecParam[1] as ExprExecValueString).Value, (listExprExecParam[2] as ExprExecValueBool).Value); caseManaged = true; return(true); } if (exprExecFunctionCallString.FunctionToCallMapper.MethodSignature == MethodSignatureType.RetString_Int_String_Int) { res = exprExecFunctionCallString.FunctionToCallMapper.FuncString_Int_String_Int.Invoke((listExprExecParam[0] as ExprExecValueInt).Value, (listExprExecParam[1] as ExprExecValueString).Value, (listExprExecParam[2] as ExprExecValueInt).Value); caseManaged = true; return(true); } if (exprExecFunctionCallString.FunctionToCallMapper.MethodSignature == MethodSignatureType.RetString_Int_String_String) { res = exprExecFunctionCallString.FunctionToCallMapper.FuncString_Int_String_String.Invoke((listExprExecParam[0] as ExprExecValueInt).Value, (listExprExecParam[1] as ExprExecValueString).Value, (listExprExecParam[2] as ExprExecValueString).Value); caseManaged = true; return(true); } if (exprExecFunctionCallString.FunctionToCallMapper.MethodSignature == MethodSignatureType.RetString_Int_String_Double) { res = exprExecFunctionCallString.FunctionToCallMapper.FuncString_Int_String_Double.Invoke((listExprExecParam[0] as ExprExecValueInt).Value, (listExprExecParam[1] as ExprExecValueString).Value, (listExprExecParam[2] as ExprExecValueDouble).Value); caseManaged = true; return(true); } if (exprExecFunctionCallString.FunctionToCallMapper.MethodSignature == MethodSignatureType.RetString_Int_Double_Bool) { res = exprExecFunctionCallString.FunctionToCallMapper.FuncString_Int_Double_Bool.Invoke((listExprExecParam[0] as ExprExecValueInt).Value, (listExprExecParam[1] as ExprExecValueDouble).Value, (listExprExecParam[2] as ExprExecValueBool).Value); caseManaged = true; return(true); } if (exprExecFunctionCallString.FunctionToCallMapper.MethodSignature == MethodSignatureType.RetString_Int_Double_Int) { res = exprExecFunctionCallString.FunctionToCallMapper.FuncString_Int_Double_Int.Invoke((listExprExecParam[0] as ExprExecValueInt).Value, (listExprExecParam[1] as ExprExecValueDouble).Value, (listExprExecParam[2] as ExprExecValueInt).Value); caseManaged = true; return(true); } if (exprExecFunctionCallString.FunctionToCallMapper.MethodSignature == MethodSignatureType.RetString_Int_Double_String) { res = exprExecFunctionCallString.FunctionToCallMapper.FuncString_Int_Double_String.Invoke((listExprExecParam[0] as ExprExecValueInt).Value, (listExprExecParam[1] as ExprExecValueDouble).Value, (listExprExecParam[2] as ExprExecValueString).Value); caseManaged = true; return(true); } if (exprExecFunctionCallString.FunctionToCallMapper.MethodSignature == MethodSignatureType.RetString_Int_Double_Double) { res = exprExecFunctionCallString.FunctionToCallMapper.FuncString_Int_Double_Double.Invoke((listExprExecParam[0] as ExprExecValueInt).Value, (listExprExecParam[1] as ExprExecValueDouble).Value, (listExprExecParam[2] as ExprExecValueDouble).Value); caseManaged = true; return(true); } if (exprExecFunctionCallString.FunctionToCallMapper.MethodSignature == MethodSignatureType.RetString_String_Bool_Bool) { res = exprExecFunctionCallString.FunctionToCallMapper.FuncString_String_Bool_Bool.Invoke((listExprExecParam[0] as ExprExecValueString).Value, (listExprExecParam[1] as ExprExecValueBool).Value, (listExprExecParam[2] as ExprExecValueBool).Value); caseManaged = true; return(true); } if (exprExecFunctionCallString.FunctionToCallMapper.MethodSignature == MethodSignatureType.RetString_String_Bool_Int) { res = exprExecFunctionCallString.FunctionToCallMapper.FuncString_String_Bool_Int.Invoke((listExprExecParam[0] as ExprExecValueString).Value, (listExprExecParam[1] as ExprExecValueBool).Value, (listExprExecParam[2] as ExprExecValueInt).Value); caseManaged = true; return(true); } if (exprExecFunctionCallString.FunctionToCallMapper.MethodSignature == MethodSignatureType.RetString_String_Bool_String) { res = exprExecFunctionCallString.FunctionToCallMapper.FuncString_String_Bool_String.Invoke((listExprExecParam[0] as ExprExecValueString).Value, (listExprExecParam[1] as ExprExecValueBool).Value, (listExprExecParam[2] as ExprExecValueString).Value); caseManaged = true; return(true); } if (exprExecFunctionCallString.FunctionToCallMapper.MethodSignature == MethodSignatureType.RetString_String_Bool_Double) { res = exprExecFunctionCallString.FunctionToCallMapper.FuncString_String_Bool_Double.Invoke((listExprExecParam[0] as ExprExecValueString).Value, (listExprExecParam[1] as ExprExecValueBool).Value, (listExprExecParam[2] as ExprExecValueDouble).Value); caseManaged = true; return(true); } if (exprExecFunctionCallString.FunctionToCallMapper.MethodSignature == MethodSignatureType.RetString_String_Int_Bool) { res = exprExecFunctionCallString.FunctionToCallMapper.FuncString_String_Int_Bool.Invoke((listExprExecParam[0] as ExprExecValueString).Value, (listExprExecParam[1] as ExprExecValueInt).Value, (listExprExecParam[2] as ExprExecValueBool).Value); caseManaged = true; return(true); } if (exprExecFunctionCallString.FunctionToCallMapper.MethodSignature == MethodSignatureType.RetString_String_Int_Int) { res = exprExecFunctionCallString.FunctionToCallMapper.FuncString_String_Int_Int.Invoke((listExprExecParam[0] as ExprExecValueString).Value, (listExprExecParam[1] as ExprExecValueInt).Value, (listExprExecParam[2] as ExprExecValueInt).Value); caseManaged = true; return(true); } if (exprExecFunctionCallString.FunctionToCallMapper.MethodSignature == MethodSignatureType.RetString_String_Int_String) { res = exprExecFunctionCallString.FunctionToCallMapper.FuncString_String_Int_String.Invoke((listExprExecParam[0] as ExprExecValueString).Value, (listExprExecParam[1] as ExprExecValueInt).Value, (listExprExecParam[2] as ExprExecValueString).Value); caseManaged = true; return(true); } if (exprExecFunctionCallString.FunctionToCallMapper.MethodSignature == MethodSignatureType.RetString_String_Int_Double) { res = exprExecFunctionCallString.FunctionToCallMapper.FuncString_String_Int_Double.Invoke((listExprExecParam[0] as ExprExecValueString).Value, (listExprExecParam[1] as ExprExecValueInt).Value, (listExprExecParam[2] as ExprExecValueDouble).Value); caseManaged = true; return(true); } if (exprExecFunctionCallString.FunctionToCallMapper.MethodSignature == MethodSignatureType.RetString_String_String_Bool) { res = exprExecFunctionCallString.FunctionToCallMapper.FuncString_String_String_Bool.Invoke((listExprExecParam[0] as ExprExecValueString).Value, (listExprExecParam[1] as ExprExecValueString).Value, (listExprExecParam[2] as ExprExecValueBool).Value); caseManaged = true; return(true); } if (exprExecFunctionCallString.FunctionToCallMapper.MethodSignature == MethodSignatureType.RetString_String_String_Int) { res = exprExecFunctionCallString.FunctionToCallMapper.FuncString_String_String_Int.Invoke((listExprExecParam[0] as ExprExecValueString).Value, (listExprExecParam[1] as ExprExecValueString).Value, (listExprExecParam[2] as ExprExecValueInt).Value); caseManaged = true; return(true); } if (exprExecFunctionCallString.FunctionToCallMapper.MethodSignature == MethodSignatureType.RetString_String_String_String) { res = exprExecFunctionCallString.FunctionToCallMapper.FuncString_String_String_String.Invoke((listExprExecParam[0] as ExprExecValueString).Value, (listExprExecParam[1] as ExprExecValueString).Value, (listExprExecParam[2] as ExprExecValueString).Value); caseManaged = true; return(true); } if (exprExecFunctionCallString.FunctionToCallMapper.MethodSignature == MethodSignatureType.RetString_String_String_Double) { res = exprExecFunctionCallString.FunctionToCallMapper.FuncString_String_String_Double.Invoke((listExprExecParam[0] as ExprExecValueString).Value, (listExprExecParam[1] as ExprExecValueString).Value, (listExprExecParam[2] as ExprExecValueDouble).Value); caseManaged = true; return(true); } if (exprExecFunctionCallString.FunctionToCallMapper.MethodSignature == MethodSignatureType.RetString_String_Double_Bool) { res = exprExecFunctionCallString.FunctionToCallMapper.FuncString_String_Double_Bool.Invoke((listExprExecParam[0] as ExprExecValueString).Value, (listExprExecParam[1] as ExprExecValueDouble).Value, (listExprExecParam[2] as ExprExecValueBool).Value); caseManaged = true; return(true); } if (exprExecFunctionCallString.FunctionToCallMapper.MethodSignature == MethodSignatureType.RetString_String_Double_Int) { res = exprExecFunctionCallString.FunctionToCallMapper.FuncString_String_Double_Int.Invoke((listExprExecParam[0] as ExprExecValueString).Value, (listExprExecParam[1] as ExprExecValueDouble).Value, (listExprExecParam[2] as ExprExecValueInt).Value); caseManaged = true; return(true); } if (exprExecFunctionCallString.FunctionToCallMapper.MethodSignature == MethodSignatureType.RetString_String_Double_String) { res = exprExecFunctionCallString.FunctionToCallMapper.FuncString_String_Double_String.Invoke((listExprExecParam[0] as ExprExecValueString).Value, (listExprExecParam[1] as ExprExecValueDouble).Value, (listExprExecParam[2] as ExprExecValueString).Value); caseManaged = true; return(true); } if (exprExecFunctionCallString.FunctionToCallMapper.MethodSignature == MethodSignatureType.RetString_String_Double_Double) { res = exprExecFunctionCallString.FunctionToCallMapper.FuncString_String_Double_Double.Invoke((listExprExecParam[0] as ExprExecValueString).Value, (listExprExecParam[1] as ExprExecValueDouble).Value, (listExprExecParam[2] as ExprExecValueDouble).Value); caseManaged = true; return(true); } if (exprExecFunctionCallString.FunctionToCallMapper.MethodSignature == MethodSignatureType.RetString_Double_Bool_Bool) { res = exprExecFunctionCallString.FunctionToCallMapper.FuncString_Double_Bool_Bool.Invoke((listExprExecParam[0] as ExprExecValueDouble).Value, (listExprExecParam[1] as ExprExecValueBool).Value, (listExprExecParam[2] as ExprExecValueBool).Value); caseManaged = true; return(true); } if (exprExecFunctionCallString.FunctionToCallMapper.MethodSignature == MethodSignatureType.RetString_Double_Bool_Int) { res = exprExecFunctionCallString.FunctionToCallMapper.FuncString_Double_Bool_Int.Invoke((listExprExecParam[0] as ExprExecValueDouble).Value, (listExprExecParam[1] as ExprExecValueBool).Value, (listExprExecParam[2] as ExprExecValueInt).Value); caseManaged = true; return(true); } if (exprExecFunctionCallString.FunctionToCallMapper.MethodSignature == MethodSignatureType.RetString_Double_Bool_String) { res = exprExecFunctionCallString.FunctionToCallMapper.FuncString_Double_Bool_String.Invoke((listExprExecParam[0] as ExprExecValueDouble).Value, (listExprExecParam[1] as ExprExecValueBool).Value, (listExprExecParam[2] as ExprExecValueString).Value); caseManaged = true; return(true); } if (exprExecFunctionCallString.FunctionToCallMapper.MethodSignature == MethodSignatureType.RetString_Double_Bool_Double) { res = exprExecFunctionCallString.FunctionToCallMapper.FuncString_Double_Bool_Double.Invoke((listExprExecParam[0] as ExprExecValueDouble).Value, (listExprExecParam[1] as ExprExecValueBool).Value, (listExprExecParam[2] as ExprExecValueDouble).Value); caseManaged = true; return(true); } if (exprExecFunctionCallString.FunctionToCallMapper.MethodSignature == MethodSignatureType.RetString_Double_Int_Bool) { res = exprExecFunctionCallString.FunctionToCallMapper.FuncString_Double_Int_Bool.Invoke((listExprExecParam[0] as ExprExecValueDouble).Value, (listExprExecParam[1] as ExprExecValueInt).Value, (listExprExecParam[2] as ExprExecValueBool).Value); caseManaged = true; return(true); } if (exprExecFunctionCallString.FunctionToCallMapper.MethodSignature == MethodSignatureType.RetString_Double_Int_Int) { res = exprExecFunctionCallString.FunctionToCallMapper.FuncString_Double_Int_Int.Invoke((listExprExecParam[0] as ExprExecValueDouble).Value, (listExprExecParam[1] as ExprExecValueInt).Value, (listExprExecParam[2] as ExprExecValueInt).Value); caseManaged = true; return(true); } if (exprExecFunctionCallString.FunctionToCallMapper.MethodSignature == MethodSignatureType.RetString_Double_Int_String) { res = exprExecFunctionCallString.FunctionToCallMapper.FuncString_Double_Int_String.Invoke((listExprExecParam[0] as ExprExecValueDouble).Value, (listExprExecParam[1] as ExprExecValueInt).Value, (listExprExecParam[2] as ExprExecValueString).Value); caseManaged = true; return(true); } if (exprExecFunctionCallString.FunctionToCallMapper.MethodSignature == MethodSignatureType.RetString_Double_Int_Double) { res = exprExecFunctionCallString.FunctionToCallMapper.FuncString_Double_Int_Double.Invoke((listExprExecParam[0] as ExprExecValueDouble).Value, (listExprExecParam[1] as ExprExecValueInt).Value, (listExprExecParam[2] as ExprExecValueDouble).Value); caseManaged = true; return(true); } if (exprExecFunctionCallString.FunctionToCallMapper.MethodSignature == MethodSignatureType.RetString_Double_String_Bool) { res = exprExecFunctionCallString.FunctionToCallMapper.FuncString_Double_String_Bool.Invoke((listExprExecParam[0] as ExprExecValueDouble).Value, (listExprExecParam[1] as ExprExecValueString).Value, (listExprExecParam[2] as ExprExecValueBool).Value); caseManaged = true; return(true); } if (exprExecFunctionCallString.FunctionToCallMapper.MethodSignature == MethodSignatureType.RetString_Double_String_Int) { res = exprExecFunctionCallString.FunctionToCallMapper.FuncString_Double_String_Int.Invoke((listExprExecParam[0] as ExprExecValueDouble).Value, (listExprExecParam[1] as ExprExecValueString).Value, (listExprExecParam[2] as ExprExecValueInt).Value); caseManaged = true; return(true); } if (exprExecFunctionCallString.FunctionToCallMapper.MethodSignature == MethodSignatureType.RetString_Double_String_String) { res = exprExecFunctionCallString.FunctionToCallMapper.FuncString_Double_String_String.Invoke((listExprExecParam[0] as ExprExecValueDouble).Value, (listExprExecParam[1] as ExprExecValueString).Value, (listExprExecParam[2] as ExprExecValueString).Value); caseManaged = true; return(true); } if (exprExecFunctionCallString.FunctionToCallMapper.MethodSignature == MethodSignatureType.RetString_Double_String_Double) { res = exprExecFunctionCallString.FunctionToCallMapper.FuncString_Double_String_Double.Invoke((listExprExecParam[0] as ExprExecValueDouble).Value, (listExprExecParam[1] as ExprExecValueString).Value, (listExprExecParam[2] as ExprExecValueDouble).Value); caseManaged = true; return(true); } if (exprExecFunctionCallString.FunctionToCallMapper.MethodSignature == MethodSignatureType.RetString_Double_Double_Bool) { res = exprExecFunctionCallString.FunctionToCallMapper.FuncString_Double_Double_Bool.Invoke((listExprExecParam[0] as ExprExecValueDouble).Value, (listExprExecParam[1] as ExprExecValueDouble).Value, (listExprExecParam[2] as ExprExecValueBool).Value); caseManaged = true; return(true); } if (exprExecFunctionCallString.FunctionToCallMapper.MethodSignature == MethodSignatureType.RetString_Double_Double_Int) { res = exprExecFunctionCallString.FunctionToCallMapper.FuncString_Double_Double_Int.Invoke((listExprExecParam[0] as ExprExecValueDouble).Value, (listExprExecParam[1] as ExprExecValueDouble).Value, (listExprExecParam[2] as ExprExecValueInt).Value); caseManaged = true; return(true); } if (exprExecFunctionCallString.FunctionToCallMapper.MethodSignature == MethodSignatureType.RetString_Double_Double_String) { res = exprExecFunctionCallString.FunctionToCallMapper.FuncString_Double_Double_String.Invoke((listExprExecParam[0] as ExprExecValueDouble).Value, (listExprExecParam[1] as ExprExecValueDouble).Value, (listExprExecParam[2] as ExprExecValueString).Value); caseManaged = true; return(true); } if (exprExecFunctionCallString.FunctionToCallMapper.MethodSignature == MethodSignatureType.RetString_Double_Double_Double) { res = exprExecFunctionCallString.FunctionToCallMapper.FuncString_Double_Double_Double.Invoke((listExprExecParam[0] as ExprExecValueDouble).Value, (listExprExecParam[1] as ExprExecValueDouble).Value, (listExprExecParam[2] as ExprExecValueDouble).Value); caseManaged = true; return(true); } return(false); } catch (Exception e) { // error occurs on executing the function return(AddErrorExecFailed(exprExecResult, e)); } }
/// <summary> /// execute the expression, execute the right part, execute the left part, then exec the expr (as 2 value operands) /// /// Returns always a bool value. /// exp: a=12, a>=13 /// /// managed type; int and double. /// for the bool and the string type, only equals and diff are authorized. /// </summary> /// <param name="exprComparison"></param> /// <returns></returns> private bool ExecExpressionComparison(ExecResult exprExecResult, ExprComparison exprComparison, out ExpressionExecBase exprExecBase) { exprExecBase = null; //----first step is to decode/compile both operands ExpressionExecBase exprExecBaseLeft; ExecExpression(exprExecResult, exprComparison.ExprLeft, out exprExecBaseLeft); ExpressionExecBase exprExecBaseRight; ExecExpression(exprExecResult, exprComparison.ExprRight, out exprExecBaseRight); //---Are the operands boolean? ExprExecValueBool exprExecValueLeftBool = exprExecBaseLeft as ExprExecValueBool; if (exprExecValueLeftBool != null) { // decode the right operand, should be a bool value too ExprExecValueBool exprExecValueRightBool = exprExecBaseRight as ExprExecValueBool; if (exprExecValueRightBool == null) { // the type of both operands mismatch! exprExecResult.AddErrorExec(ErrorCode.ExprComparisonOperandsTypeMismatchBoolExpected, "Position", exprComparison.ExprRight.Token.Position.ToString()); return(false); } ExprExecValueBool exprValueBoolResult = new ExprExecValueBool(); // is the operator Equals? if (exprComparison.Operator == OperatorComparisonCode.Equals) { // ok, execute the comparison exprValueBoolResult.Value = exprExecValueLeftBool.Value == exprExecValueRightBool.Value; exprExecBase = exprValueBoolResult; return(true); } // is the operator different? if (exprComparison.Operator == OperatorComparisonCode.Different) { // ok, execute the comparison exprValueBoolResult.Value = exprExecValueLeftBool.Value != exprExecValueRightBool.Value; exprExecBase = exprValueBoolResult; return(true); } // other operators are not allowed on the boolean type exprExecResult.AddErrorExec(ErrorCode.ExprComparisonOperatorNotAllowedForBoolType, "Position", exprComparison.ExprLeft.Token.Position.ToString(), "Operator", exprComparison.Operator.ToString()); return(false); } //---Are the operands integer? ExprExecValueInt exprExecValueLeftInt = exprExecBaseLeft as ExprExecValueInt; if (exprExecValueLeftInt != null) { // decode the right operand, should be an int value too ExprExecValueInt exprExecValueRightInt = exprExecBaseRight as ExprExecValueInt; if (exprExecValueRightInt == null) { // the type of both operands mismatch! exprExecResult.AddErrorExec(ErrorCode.ExprComparisonOperandsTypeMismatchIntExpected, "Position", exprComparison.ExprRight.Token.Position.ToString()); return(false); } ExprExecValueBool exprValueBoolResult = new ExprExecValueBool(); // is the operator Equals? if (exprComparison.Operator == OperatorComparisonCode.Equals) { // ok, execute the comparison exprValueBoolResult.Value = exprExecValueLeftInt.Value == exprExecValueRightInt.Value; exprExecBase = exprValueBoolResult; return(true); } // is the operator different? if (exprComparison.Operator == OperatorComparisonCode.Different) { // ok, execute the comparison exprValueBoolResult.Value = exprExecValueLeftInt.Value != exprExecValueRightInt.Value; exprExecBase = exprValueBoolResult; return(true); } // is the operator greater than? if (exprComparison.Operator == OperatorComparisonCode.Greater) { // ok, execute the comparison exprValueBoolResult.Value = exprExecValueLeftInt.Value > exprExecValueRightInt.Value; exprExecBase = exprValueBoolResult; return(true); } // is the operator lesser than? if (exprComparison.Operator == OperatorComparisonCode.Less) { // ok, execute the comparison exprValueBoolResult.Value = exprExecValueLeftInt.Value < exprExecValueRightInt.Value; exprExecBase = exprValueBoolResult; return(true); } // is the operator greater or equals than? if (exprComparison.Operator == OperatorComparisonCode.GreaterEquals) { // ok, execute the comparison exprValueBoolResult.Value = exprExecValueLeftInt.Value >= exprExecValueRightInt.Value; exprExecBase = exprValueBoolResult; return(true); } // is the operator lesser or equals than? if (exprComparison.Operator == OperatorComparisonCode.LessEquals) { // ok, execute the comparison exprValueBoolResult.Value = exprExecValueLeftInt.Value <= exprExecValueRightInt.Value; exprExecBase = exprValueBoolResult; return(true); } // other operators are not allowed on the boolean type (impossible to be there!) exprExecResult.AddErrorExec(ErrorCode.ExprComparisonOperatorNotYetImplementedForIntType, "Position", exprComparison.ExprLeft.Token.Position.ToString(), "Operator", exprComparison.Operator.ToString()); return(false); } //---Are the operands double? ExprExecValueDouble exprExecValueLeftDouble = exprExecBaseLeft as ExprExecValueDouble; if (exprExecValueLeftDouble != null) { // decode the right operand, should be an int value too ExprExecValueDouble exprExecValueRightDouble = exprExecBaseRight as ExprExecValueDouble; if (exprExecValueRightDouble == null) { // the type of both operands mismatch! exprExecResult.AddErrorExec(ErrorCode.ExprComparisonOperandsTypeMismatchDoubleExpected, "Position", exprComparison.ExprRight.Token.Position.ToString()); return(false); } // the result is always a bool (its a comparison) ExprExecValueBool exprValueBoolResult = new ExprExecValueBool(); // is the operator Equals? if (exprComparison.Operator == OperatorComparisonCode.Equals) { // ok, execute the comparison exprValueBoolResult.Value = exprExecValueLeftDouble.Value == exprExecValueRightDouble.Value; exprExecBase = exprValueBoolResult; return(true); } // is the operator different? if (exprComparison.Operator == OperatorComparisonCode.Different) { // ok, execute the comparison exprValueBoolResult.Value = exprExecValueLeftDouble.Value != exprExecValueRightDouble.Value; exprExecBase = exprValueBoolResult; return(true); } // is the operator greater than? if (exprComparison.Operator == OperatorComparisonCode.Greater) { // ok, execute the comparison exprValueBoolResult.Value = exprExecValueLeftDouble.Value > exprExecValueRightDouble.Value; exprExecBase = exprValueBoolResult; return(true); } // is the operator lesser than? if (exprComparison.Operator == OperatorComparisonCode.Less) { // ok, execute the comparison exprValueBoolResult.Value = exprExecValueLeftDouble.Value < exprExecValueRightDouble.Value; exprExecBase = exprValueBoolResult; return(true); } // is the operator greater or equals than? if (exprComparison.Operator == OperatorComparisonCode.GreaterEquals) { // ok, execute the comparison exprValueBoolResult.Value = exprExecValueLeftDouble.Value >= exprExecValueRightDouble.Value; exprExecBase = exprValueBoolResult; return(true); } // is the operator lesser or equals than? if (exprComparison.Operator == OperatorComparisonCode.LessEquals) { // ok, execute the comparison exprValueBoolResult.Value = exprExecValueLeftDouble.Value <= exprExecValueRightDouble.Value; exprExecBase = exprValueBoolResult; return(true); } // other operators are not allowed on the boolean type (impossible to be there!) exprExecResult.AddErrorExec(ErrorCode.ExprComparisonOperatorNotYetImplementedForDoubleType, "Position", exprComparison.ExprLeft.Token.Position.ToString(), "Operator", exprComparison.Operator.ToString()); return(false); } //---Are the operands string? ExprExecValueString exprExecValueLeftString = exprExecBaseLeft as ExprExecValueString; if (exprExecValueLeftString != null) { // decode the right operand, should be a bool value too ExprExecValueString exprExecValueRightString = exprExecBaseRight as ExprExecValueString; if (exprExecValueRightString == null) { // the type of both operands mismatch! exprExecResult.AddErrorExec(ErrorCode.ExprComparisonOperandsTypeMismatchStringExpected, "Position", exprComparison.ExprRight.Token.Position.ToString()); return(false); } ExprExecValueBool exprValueBoolResult = new ExprExecValueBool(); // is the operator Equals? if (exprComparison.Operator == OperatorComparisonCode.Equals) { // ok, execute the comparison exprValueBoolResult.Value = exprExecValueLeftString.Value == exprExecValueRightString.Value; exprExecBase = exprValueBoolResult; return(true); } // is the operator different? if (exprComparison.Operator == OperatorComparisonCode.Different) { // ok, execute the comparison exprValueBoolResult.Value = exprExecValueLeftString.Value != exprExecValueRightString.Value; exprExecBase = exprValueBoolResult; return(true); } // other operators are not allowed on the boolean type exprExecResult.AddErrorExec(ErrorCode.ExprComparisonOperatorNotAllowedForStringType, "Position", exprComparison.ExprLeft.Token.Position.ToString(), "Operator", exprComparison.Operator.ToString()); return(false); } // if reached, the operand type is not yet implemented (or unknowed) exprExecResult.AddErrorExec(ErrorCode.ExprComparisonOperandTypeNotYetImplemented, "Position", exprComparison.ExprLeft.Token.Position.ToString(), "Token", exprExecBaseLeft.Expr.Token.ToString()); return(false); }
/// <summary> /// Do the calculation: res := operandLeft operator operandRight. /// Both operand must be number, int or double. /// the operator can be: +, -, *, /. /// </summary> /// <param name="execResult"></param> /// <param name="exprExecBase"></param> /// <returns></returns> private bool DoCalculationTwoOperands(ExecResult execResult, ExprCalculation exprCalculation, ExpressionExecBase exprExecBaseLeft, ExpressionExecBase exprExecBaseRight, ExprOperatorCalculation operatorCalc, out ExpressionExecBase exprExecCalcResult) { exprExecCalcResult = null; CalcIntOrDouble calcIntOrDoubleLeft = CalcIntOrDouble.NotDefined; CalcIntOrDouble calcIntOrDoubleRight = CalcIntOrDouble.NotDefined; int valLeftInt = 0; int valRightInt = 0; double valLeftDouble = 0; double valRightDouble = 0; //---parse the left operand ExprExecValueInt exprExecValueLeftInt = exprExecBaseLeft as ExprExecValueInt; if (exprExecValueLeftInt != null) { valLeftInt = exprExecValueLeftInt.Value; calcIntOrDoubleLeft = CalcIntOrDouble.IsInt; } else { ExprExecValueDouble exprExecValueLeftDouble = exprExecBaseLeft as ExprExecValueDouble; if (exprExecValueLeftDouble != null) { valLeftDouble = exprExecValueLeftDouble.Value; calcIntOrDoubleLeft = CalcIntOrDouble.IsDouble; } } //---parse the right operand ExprExecValueInt exprExecValueRightInt = exprExecBaseRight as ExprExecValueInt; if (exprExecValueRightInt != null) { valRightInt = exprExecValueRightInt.Value; calcIntOrDoubleRight = CalcIntOrDouble.IsInt; } else { ExprExecValueDouble exprExecValueRightDouble = exprExecBaseRight as ExprExecValueDouble; if (exprExecValueRightDouble != null) { valRightDouble = exprExecValueRightDouble.Value; calcIntOrDoubleRight = CalcIntOrDouble.IsDouble; } } //----wrong type if (calcIntOrDoubleLeft == CalcIntOrDouble.NotDefined) { // other operators are not allowed on the boolean type (only bool) execResult.AddErrorExec(ErrorCode.ExprCalculationOperandTypeUnExcepted, "Position", exprExecBaseLeft.Expr.Token.Position.ToString(), "Operand", exprExecBaseLeft.Expr.Token.Value); return(false); } if (calcIntOrDoubleRight == CalcIntOrDouble.NotDefined) { // other operators are not allowed on the boolean type (only bool) execResult.AddErrorExec(ErrorCode.ExprCalculationOperandTypeUnExcepted, "Position", exprExecBaseRight.Expr.Token.Position.ToString(), "Operand", exprExecBaseRight.Expr.Token.Value); return(false); } // if one of both operand is an double, convert the other to a double if (calcIntOrDoubleLeft == CalcIntOrDouble.IsDouble || calcIntOrDoubleRight == CalcIntOrDouble.IsDouble) { if (calcIntOrDoubleLeft == CalcIntOrDouble.IsInt) { valLeftDouble = (double)valLeftInt; } if (calcIntOrDoubleRight == CalcIntOrDouble.IsInt) { valRightDouble = (double)valRightInt; } // used to define the calculation type calcIntOrDoubleLeft = CalcIntOrDouble.IsDouble; } //----calculate, depending on the operator: Plus if (operatorCalc.Operator == OperatorCalculationCode.Plus) { if (calcIntOrDoubleLeft == CalcIntOrDouble.IsDouble) { ExprExecValueDouble resDouble = new ExprExecValueDouble(); resDouble.Value = valLeftDouble + valRightDouble; exprExecCalcResult = resDouble; return(true); } ExprExecValueInt resInt = new ExprExecValueInt(); resInt.Value = valLeftInt + valRightInt; exprExecCalcResult = resInt; return(true); } //----calculate, depending on the operator: Minus if (operatorCalc.Operator == OperatorCalculationCode.Minus) { if (calcIntOrDoubleLeft == CalcIntOrDouble.IsDouble) { ExprExecValueDouble resDouble = new ExprExecValueDouble(); resDouble.Value = valLeftDouble - valRightDouble; exprExecCalcResult = resDouble; return(true); } ExprExecValueInt resInt = new ExprExecValueInt(); resInt.Value = valLeftInt - valRightInt; exprExecCalcResult = resInt; return(true); } //----calculate, depending on the operator: Multiplication if (operatorCalc.Operator == OperatorCalculationCode.Multiplication) { if (calcIntOrDoubleLeft == CalcIntOrDouble.IsDouble) { ExprExecValueDouble resDouble = new ExprExecValueDouble(); resDouble.Value = valLeftDouble * valRightDouble; exprExecCalcResult = resDouble; return(true); } ExprExecValueInt resInt = new ExprExecValueInt(); resInt.Value = valLeftInt * valRightInt; exprExecCalcResult = resInt; return(true); } //----calculate, depending on the operator: Division if (operatorCalc.Operator == OperatorCalculationCode.Division) { if (calcIntOrDoubleLeft == CalcIntOrDouble.IsDouble) { ExprExecValueDouble resDouble = new ExprExecValueDouble(); resDouble.Value = valLeftDouble / valRightDouble; exprExecCalcResult = resDouble; return(true); } // the result can be a double! double res = (double)valLeftInt / (double)valRightInt; double res2 = res - Math.Truncate(res); if (res2 == 0) { ExprExecValueInt resInt = new ExprExecValueInt(); resInt.Value = valLeftInt / valRightInt; exprExecCalcResult = resInt; return(true); } else { ExprExecValueDouble resDouble = new ExprExecValueDouble(); resDouble.Value = res; // valLeftInt / valRightInt; exprExecCalcResult = resDouble; return(true); } return(true); } // operator not yet implemented execResult.AddErrorExec(ErrorCode.ExprCalculationOperatorNotYetImplemented, "Position", exprExecBaseLeft.Expr.Token.Position.ToString(), "Operand", exprExecBaseLeft.Expr.Token.Value); return(false); }
/// <summary> /// start the execution, analyze and return the list of variables to create. /// todo: recréer un syntax tree, avec des valeurs! /// /// -->Doit renvoyer comme résultat un objet de type ExprValueXXX, non?? (si pas d'erreur). /// </summary> /// <returns></returns> private bool ExecExpression(ExecResult exprExecResult, ExpressionBase expr, out ExpressionExecBase exprExecBase) { exprExecBase = null; //----is it a final operand (value, var or call function)? ExprFinalOperand finalOperand = expr as ExprFinalOperand; if (finalOperand != null) { return(ExecExpressionFinalOperand(exprExecResult, finalOperand, out exprExecBase)); } //----is it a comparison expression? ExprComparison exprComparison = expr as ExprComparison; if (exprComparison != null) { // execute the expression, execute the right part, execute the left part, then exec the expr (as 2 value operands) return(ExecExpressionComparison(exprExecResult, exprComparison, out exprExecBase)); } //----is it a logical expression (bin/2 operands)? ExprLogical exprLogical = expr as ExprLogical; if (exprLogical != null) { return(ExecExpressionLogical(exprExecResult, exprLogical, out exprExecBase)); } //----is it a NOT logical expression? ExprLogicalNot exprLogicalNot = expr as ExprLogicalNot; if (exprLogicalNot != null) { return(ExecExpressionLogicalNot(exprExecResult, exprLogicalNot, out exprExecBase)); } //----is it a calculation expression? ExprCalculation exprCalculation = expr as ExprCalculation; if (exprCalculation != null) { // execute the expression, execute the right part, execute the left part, then exec the expr (as 2 value operands) return(ExecExpressionCalculation(exprExecResult, exprCalculation, out exprExecBase)); } //----is it function call? ExprFunctionCall exprFunctionCall = expr as ExprFunctionCall; if (exprFunctionCall != null) { return(ExecExpressionFunctionCall(exprExecResult, exprFunctionCall, out exprExecBase)); } //----is it a setValue expression? // todo: future // todo: error, expression not yet implemented!! exprExecResult.AddErrorExec(ErrorCode.ExpressionTypeNotYetImplemented, "Expr", expr.GetType().ToString()); return(false); }
/// <summary> /// Execute the logical expression. /// exp: (a AND b) /// /// Only bool type are authorized. /// </summary> /// <param name="exprExecResult"></param> /// <param name="exprComparison"></param> /// <param name="exprExecBase"></param> /// <returns></returns> private bool ExecExpressionLogical(ExecResult exprExecResult, ExprLogical exprLogical, out ExpressionExecBase exprExecBase) { exprExecBase = null; //----first step is to execute both operands ExpressionExecBase exprExecBaseLeft; ExecExpression(exprExecResult, exprLogical.ExprLeft, out exprExecBaseLeft); ExpressionExecBase exprExecBaseRight; ExecExpression(exprExecResult, exprLogical.ExprRight, out exprExecBaseRight); //---Are the operands boolean type? ExprExecValueBool exprExecValueLeftBool = exprExecBaseLeft as ExprExecValueBool; if (exprExecValueLeftBool != null) { // decode the right operand, should be a bool value too ExprExecValueBool exprExecValueRightBool = exprExecBaseRight as ExprExecValueBool; if (exprExecValueRightBool == null) { // the type of both operands mismatch! exprExecResult.AddErrorExec(ErrorCode.ExprLogicalOperandsTypeMismatchBoolExpected, "Position", exprLogical.ExprRight.Token.Position.ToString()); return(false); } ExprExecValueBool exprValueBoolResult = new ExprExecValueBool(); // is the operator AND? if (exprLogical.Operator == OperatorLogicalCode.And) { // ok, execute the comparison exprValueBoolResult.Value = exprExecValueLeftBool.Value && exprExecValueRightBool.Value; exprExecBase = exprValueBoolResult; return(true); } // is the operator OR? if (exprLogical.Operator == OperatorLogicalCode.Or) { // ok, execute the comparison exprValueBoolResult.Value = (exprExecValueLeftBool.Value || exprExecValueRightBool.Value); exprExecBase = exprValueBoolResult; return(true); } // is the operator XOR? if (exprLogical.Operator == OperatorLogicalCode.Xor) { // ok, execute the comparison, the operator doesn't exists so do firts a OR exprValueBoolResult.Value = (exprExecValueLeftBool.Value || exprExecValueRightBool.Value); // the xor case: both operands are true so the result is false if (exprExecValueLeftBool.Value && exprExecValueRightBool.Value) { exprValueBoolResult.Value = false; } exprExecBase = exprValueBoolResult; return(true); } // other operators are not allowed on the boolean type (only bool) exprExecResult.AddErrorExec(ErrorCode.ExprLogicalOperatorNotAllowed, "Position", exprLogical.ExprLeft.Token.Position.ToString(), "Operator", exprLogical.Operator.ToString()); return(false); } //---Are the operands others type? -> error exprExecResult.AddErrorExec(ErrorCode.ExprLogicalOperandTypeNotAllowed, "Position", exprLogical.ExprLeft.Token.Position.ToString(), "Token", exprExecBaseLeft.GetType().ToString()); return(false); }