Esempio n. 1
0
 public override int GetHashCode()
 {
     unchecked
     {
         int result = Column == null ? 0 : Column.GetHashCode();
         result = (result * 397) ^ (OpName == null ? 0 : OpName.GetHashCode());
         result = (result * 397) ^ (Operand == null ? 0 : Operand.GetHashCode());
         return(result);
     }
 }
Esempio n. 2
0
        public override object GetValue(Dictionary <GridCoordinates, object> childCells, out ParserError error)
        {
            leftValue = LeftOpRand.GetValue(childCells, out error);
            if (!error.IsEmpty)
            {
                return(null);
            }

            rightValue = RightOpRand.GetValue(childCells, out error);
            if (!error.IsEmpty)
            {
                return(null);
            }

            try {
                switch (OpName)
                {
                case OperationToken.Operation.Plus: return(GetPlusValue(childCells, out error));

                case OperationToken.Operation.Minus: return(GetMinusValue(childCells, out error));

                case OperationToken.Operation.Mult: return(GetMultValue(childCells, out error));

                case OperationToken.Operation.Divide: return(GetDivideValue(childCells, out error));

                case OperationToken.Operation.Mod: return(GetModValue(childCells, out error));

                case OperationToken.Operation.Div: return(GetDivValue(childCells, out error));

                case OperationToken.Operation.More: return(GetMoreValue(childCells, out error));

                case OperationToken.Operation.MoreEq: return(GetMoreEqValue(childCells, out error));

                case OperationToken.Operation.Less: return(GetLessValue(childCells, out error));

                case OperationToken.Operation.LessEq: return(GetLessEqValue(childCells, out error));

                case OperationToken.Operation.Equal: return(GetEqualValue(childCells, out error));

                case OperationToken.Operation.UnEqual: return(GetUnEqualValue(childCells, out error));

                default: {
                    error = new ParserError($"Strange binar operation{OpName.ToString()}");
                    return(null);
                }
                }
            } catch (Exception e) {
                error = new ParserError(e.Message);
                return(null);
            }
        }
Esempio n. 3
0
        private object GetPlusValue(Dictionary <GridCoordinates, object> childCells, out ParserError error)
        {
            object argValue = Argument.GetValue(childCells, out error);

            if (!error.IsEmpty)
            {
                return(null);
            }

            if (argValue is Decimal decValue)
            {
                return(+decValue);
            }

            error = new ParserError($"Unar {OpName.ToString()} operation has wrong argument type");
            return(null);
        }
Esempio n. 4
0
        public override object GetValue(Dictionary <GridCoordinates, object> childCells, out ParserError error)
        {
            try {
                switch (OpName)
                {
                case OperationToken.Operation.If: return(GetIfValue(childCells, out error));

                case OperationToken.Operation.Plus: return(GetPlusValue(childCells, out error));

                case OperationToken.Operation.Minus: return(GetMinusValue(childCells, out error));

                case OperationToken.Operation.Not: return(GetNotValue(childCells, out error));

                default: {
                    error = new ParserError($"Unexpected UnarOperation: {OpName.ToString()}");
                    return(null);
                }
                }
            } catch (Exception e) {
                error = new ParserError(e.Message);
                return(null);
            }
        }
            private void Evaluate()
            {
                string[] operands = OpName.Split(sysOperation, StringSplitOptions.RemoveEmptyEntries);
                if (operands.Length == 1 && !OpName.StartsWith("¬"))
                {
                    return;
                }
                char op = OpName.Split(operands, StringSplitOptions.RemoveEmptyEntries)[0][0];   //Get 1st char of 1st element in the array.

                truthValues = new bool[truthTtable.Height];

                bool[] col1 = truthTtable.GetOpFromTruthTable(operands[0]).TruthValues;
                bool[] col2 = new bool[0];
                if (operands.Length == 2)
                {
                    col2 = truthTtable.GetOpFromTruthTable(operands[1]).TruthValues;
                }

                if (operands.Length == 1)
                {
                    OpName = "(" + op + truthTtable.GetOpFromTruthTable(operands[0]).OpName + ")";
                }
                else
                {
                    OpName = "(" + truthTtable.GetOpFromTruthTable(operands[0]).OpName
                             + op + truthTtable.GetOpFromTruthTable(operands[1]).OpName + ")";
                }
                Label = id++;

                switch (op)
                {
                case '¬':
                    Negiation(col1);
                    break;

                case '^':
                    And(col1, col2);
                    break;

                case '˅':
                    Or(col1, col2);
                    break;

                case '→':
                    Implies(col1, col2);
                    break;

                case '↔':
                    Equivalence(col1, col2);
                    break;
                }


                bool value = true;

                for (int i = 0; i < truthValues.Length; i++)
                {
                    value = value && truthValues[i];
                }
                if (value)
                {
                    Type = "Tautology";
                    return;
                }

                value = false;
                for (int i = 0; i < truthValues.Length; i++)
                {
                    value = value || truthValues[i];
                }

                if (!value)
                {
                    Type = "Contradictory";
                    return;
                }

                Type = "Contigent";
            }
Esempio n. 6
0
 private void SetUp(OpName op, SpirvInstructionTreeBuilder treeBuilder)
 {
     Target = treeBuilder.GetNode(op.Target);
     Value  = op.Value;
     SetUpDecorations(op, treeBuilder);
 }