Example #1
0
        /// <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));
        }
Example #2
0
        /// <summary>
        /// analyze and return the list of variables and functionCalls found in the expression to define before execute it.
        /// Do also some checks.
        /// </summary>
        /// <param name="exprParseResult"></param>
        /// <param name="expr"></param>
        /// <returns></returns>
        private bool AnalyzeSyntaxTree(ParseResult result, ExpressionBase expr)
        {
            //----is it a final operand?
            ExprFinalOperand exprFinalOperand = expr as ExprFinalOperand;

            if (exprFinalOperand != null)
            {
                if (exprFinalOperand.ContentType == OperandType.ObjectName)
                {
                    // save the objectName (variable)
                    result.AddVariable(exprFinalOperand.Operand);
                }
                return(true);
            }

            //----is it a function call?
            ExprFunctionCall exprFunctionCall = expr as ExprFunctionCall;

            if (exprFunctionCall != null)
            {
                // scan parameters of the function call
                foreach (ExpressionBase exprParam in exprFunctionCall.ListExprParameters)
                {
                    AnalyzeSyntaxTree(result, exprParam);
                }
                result.AddFunctionCall(exprFunctionCall.FunctionName, exprFunctionCall.ListExprParameters.Count);
                return(true);
            }

            //----is it an expression comparison?
            ExprComparison exprComparison = expr as ExprComparison;

            if (exprComparison != null)
            {
                AnalyzeSyntaxTree(result, exprComparison.ExprLeft);
                AnalyzeSyntaxTree(result, exprComparison.ExprRight);
                return(true);
            }

            //----is it an expression logical?
            ExprLogical exprLogical = expr as ExprLogical;

            if (exprLogical != null)
            {
                AnalyzeSyntaxTree(result, exprLogical.ExprLeft);
                AnalyzeSyntaxTree(result, exprLogical.ExprRight);
                return(true);
            }

            //----is it an expression logical NOT?
            ExprLogicalNot exprLogicalNot = expr as ExprLogicalNot;

            if (exprLogicalNot != null)
            {
                AnalyzeSyntaxTree(result, exprLogicalNot.ExprBase);
                return(true);
            }

            //----is it an expression calculation?
            ExprCalculation exprCalculation = expr as ExprCalculation;

            if (exprCalculation != null)
            {
                // analyze all operands of the calculation expression
                bool res = true;
                foreach (ExpressionBase exprChild in exprCalculation.ListExprOperand)
                {
                    res = res && AnalyzeSyntaxTree(result, exprChild);
                }

                //AnalyzeSyntaxTree(result, exprCalculation.ExprLeft);
                //AnalyzeSyntaxTree(result, exprCalculation.ExprRight);
                return(res);
            }

            //----is it a set value expression ?
            // todo:


            throw new Exception("todo: AnalyzeSyntaxTree(), expression type not yet implemented!");
        }
Example #3
0
        /// <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);
        }