Example #1
0
        private void AssignToMatrixByRange(ExecEnvironment environment, Matrix_t matrix, Value value)
        {
            Int_t left1  = derefVariable.Left.FirstExpr.Evaluate(environment) as Int_t;
            Int_t left2  = derefVariable.Left.SecondExpr.Evaluate(environment) as Int_t;
            Int_t right1 = derefVariable.Right.FirstExpr.Evaluate(environment) as Int_t;
            Int_t right2 = derefVariable.Right.SecondExpr.Evaluate(environment) as Int_t;

            if (left1 is null || left2 is null || right1 is null || right2 is null)
            {
                throw new RuntimeException("Index has to be integer");
            }

            try {
                if (left1.Value == left2.Value && right1.Value == right2.Value)
                {
                    var intValue = value as Int_t;
                    if (intValue is null)
                    {
                        throw new RuntimeException("Cannot assign to int variable");
                    }
                    matrix[left1.Value, right1.Value] = intValue.Value;
                }
                else
                {
                    throw new ArthmeticOperationException("Matrix with range can be only r-value");
                }
            }
            catch (Exception) {
                throw new RuntimeException("Index out of range");
            }
        }
Example #2
0
        public static Value EvaluateMatrixDerefVar(Value l1, Value l2, Value r1, Value r2, Variable variable)
        {
            if (variable.Type != TypeValue.Matrix)
            {
                throw new ArthmeticOperationException("Cannot use [] indexers to non matrix type");
            }

            Int_t left1 = l1 as Int_t; Int_t left2 = l2 as Int_t;
            Int_t right1 = r1 as Int_t; Int_t right2 = r2 as Int_t;

            if (left1 is null || left2 is null || right1 is null || right2 is null)
            {
                throw new ArthmeticOperationException("Index has to be integer");
            }
            try {
                if (left1.Value == left2.Value && right1.Value == right2.Value)
                {
                    return(new Int_t((variable.Value as Matrix_t)[left1.Value, right1.Value]));
                }
                else
                {
                    return(new Matrix_t(
                               (variable.Value as Matrix_t).Value
                               .GetRange(left1.Value, left2.Value, right1.Value, right2.Value)));
                }
            }
            catch (Exception) {
                throw new ArthmeticOperationException("Index out of range");
            }
        }
Example #3
0
        private void AssignMatrix(ExecEnvironment environment)
        {
            Int_t first  = variable.First.Evaluate(environment) as Int_t;
            Int_t second = variable.Second.Evaluate(environment) as Int_t;

            if (first is null || second is null)
            {
                throw new RuntimeException("Cannot define matrix without size");
            }
            if (!(expression is null))
            {
                var matrix = expression.Evaluate(environment) as Matrix_t;
                if (matrix.Value.SizeX != first.Value || matrix.Value.SizeY != second.Value)
                {
                    throw new RuntimeException("Sizes of matrices is various");
                }
                variable.Value = matrix;
            }
Example #4
0
        private Value TryParseValue()
        {
            Value value;

            if (_scanner.CurrentToken.Type == TokenType.NUMBER)
            {
                value = new Int_t((_scanner.CurrentToken as Number).Value);
            }
            else if (_scanner.CurrentToken.Type == TokenType.TEXT)
            {
                value = new String_t(_scanner.CurrentToken.ToString());
            }
            else
            {
                return(null);
            }

            _scanner.Next();
            return(value);
        }