Esempio n. 1
0
        public FunctionBodyValidator(Function function)
        {
            _localContext = ExecutorContextFactory.CreateLocalContext();
            foreach (var variable in function.Parameters)
            {
                _localContext._variablesRepository.Add(variable, 0);
            }

            _validatorStack = new ValidatorLexemesStack();
            _validatorState = new OpeningBracketOperatorState();
        }
Esempio n. 2
0
        public static double?Execute(FunctionSignature signature, Function function, ExecutorContext context)
        {
            var localContext = ExecutorContextFactory.CreateLocalContext();

            for (var index = 0; index < signature.Arguments.Count; index++)
            {
                var argument  = signature.Arguments[index];
                var parameter = function.Parameters[index];

                var argumentCalculator = new Interpreter(context);
                var argumentValue      = argumentCalculator.Execute(argument.Body);

                localContext._variablesRepository.Add(parameter, argumentValue.Value);
            }

            var bodyCalculator = new Interpreter(localContext);
            var functionValue  = bodyCalculator.Execute(function.Body);

            return(functionValue.Value);
        }