Beispiel #1
0
        /*
        private void BuildExpression()
        {
            foreach (Assignment assignment in _assignments)
            {
                string stringDelim = "\"";
                if (assignment.Variable.VariableDataType != VariableDataType.String)
                    stringDelim = string.Empty;
                _expression += assignment.Variable.Mnemonic + " = " + stringDelim + assignment.AssignmentExpression + stringDelim + ";";
            }
        }
        */
        private void Parse(ExpressionContext context, CalculationMemory calculationMemory)
        {
            _assignments.Clear();
            // assignments seprator token
            string[] temp = _expression.Split(';');
            int idx = 0;

            //temp.OrderBy?
            foreach (string assignmentExpression in temp)
            {
                if (assignmentExpression != string.Empty)
                {
                    // assignment token
                    string[] temp2 = assignmentExpression.Split('=');
                    if (temp2.Length != 2)
                        throw new InequationEngineException(ExceptionType.NumberOfAssigmentTokens);

                    string variableName = temp2[0].ToLower().Trim();
                    Variable variable = calculationMemory[variableName];
                    if (variable == null)
                        throw new InequationEngineException(ExceptionType.VariableNotFoundInCalcMemory);

                    Assignment assignment = new Assignment(variable, temp2[1]);
                    _assignments.Add(idx, assignment);
                    idx++;
                }
            }
        }
 public InequationEngine()
 {
     _context = new ExpressionContext();
     _context.Imports.AddType(typeof(CustomFunctions));
     _context.Options.EmitToAssembly = false;
     _calculationMemory = new CalculationMemory(_context);
 }
Beispiel #3
0
 public void Execute(ExpressionContext context, CalculationMemory calculationMemory)
 {
     // Execute inequation and call action block
     if (Inequation.Execute(context))
         TrueActionBlock.Execute(context, calculationMemory);
     else
         FalseActionBlock.Execute(context, calculationMemory);
 }
Beispiel #4
0
        public void Execute(ExpressionContext context, CalculationMemory calculationMemory)
        {
            if (eDynamic == null)
                this.Compile(context);

            _variable.Value = eDynamic.Evaluate();

            calculationMemory[_variable.Mnemonic] = _variable;
        }
Beispiel #5
0
        public void Compile(ExpressionContext context, CalculationMemory calculationMemory)
        {
            // Compile inequation expression
            Inequation.Compile(context);

            // Compile Action Blocks
            TrueActionBlock.Compile(context, calculationMemory);
            FalseActionBlock.Compile(context, calculationMemory);
        }
Beispiel #6
0
        public void Compile(ExpressionContext context, CalculationMemory calculationMemory)
        {
            this.Parse(context, calculationMemory);

            //_assignments.OrderBy()
            foreach(Assignment assignment in _assignments.Values)
            {
                assignment.Compile(context);
            }
        }
Beispiel #7
0
        public void Execute(ExpressionContext context, CalculationMemory calculationMemory)
        {
            if (_assignments.Count == 0)
                this.Compile(context, calculationMemory);

            //_assignments.OrderBy()
            foreach (Assignment assignment in _assignments.Values)
            {
                assignment.Execute(context, calculationMemory);
            }
        }