/// <summary> /// Check that all found variables in the expression are defined/ created with a value. /// </summary> /// <returns></returns> private bool CheckVariables() { bool errVarCreated = true; // scan each defined var by the parser foreach (ExprObjectUsedBase objectName in _expressionData.ExprParseResult.ListExprVarUsed) { ExprVariableBase variable = _expressionData.ExprExecResult.ListExprVariable.Find(v => v.Name.Equals(objectName.Name, StringComparison.InvariantCultureIgnoreCase)); if (variable == null) { // the variable is not created! no type and no value _expressionData.ExprExecResult.AddErrorExec(ErrorCode.VariableNotDefined, "VarName", objectName.Name); errVarCreated = false; } } return(errVarCreated); }
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!"); }