private IAsciiBasePropositionalOperator GetOperator(byte value, char name)
        {
            switch (value)
            {
            case 0:
                IAsciiBasePropositionalOperator oper = new NotPropositionalOperator(_argumentManager);
                oper.Instantiate(new IAsciiBasePropositionalOperator[] { _argumentManager.RequestOperator(name) });
                return(oper);

            case 1:
                return(_argumentManager.RequestOperator(name));
            }
            return(null);
        }
        public virtual void ChangeArgument(char from, char to)
        {
            foreach (var asciiBasePropositionalOperator in GetChilds().Where(x =>
                                                                             !(x is ScalarPropositionalOperator) && x.GetChilds().Length > 0))
            {
                asciiBasePropositionalOperator.ChangeArgument(from, to);
            }

            var childs = GetChilds();

            for (var i = 0; i < childs.Length; i++)
            {
                if (!(childs[i] is ScalarPropositionalOperator t) || t.GetName() != @from)
                {
                    continue;
                }

                UpdateChild(i, _argumentManager.RequestOperator(to));
                return;
            }
        }
Example #3
0
        private IAsciiBasePropositionalOperator Process(IAsciiBasePropositionalOperator work)
        {
            var logic = work as IAsciiSinglePropositionalOperator;

            if (logic != null)
            {
                switch (logic.GetAsciiSymbol())
                {
                case '>':
                    var or = new OrPropositionalOperator(_manager);
                    or.Instantiate(new [] { SurroundWithNot(logic.GetChilds()[0]), logic.GetChilds()[1] });
                    return(HandleOr(or));

                case '=':
                    var implication1 = new IfThenPropositionalOperator(_manager);
                    implication1.Instantiate(new [] { logic.GetChilds()[0], logic.GetChilds()[1] });

                    var implication2 = new IfThenPropositionalOperator(_manager);
                    implication2.Instantiate(new IAsciiBasePropositionalOperator[] { logic.GetChilds()[1], logic.GetChilds()[0] });

                    var and = new AndPropositionalOperator(_manager);
                    and.Instantiate(new IAsciiBasePropositionalOperator[] { implication1, implication2 });
                    return(HandleAnd(and));

                case '&':
                    return(HandleAnd((AndPropositionalOperator)logic));

                case '|':
                    return(HandleOr((OrPropositionalOperator)logic));

                case '~':
                    return(logic);

                case '%':
                    var nAnd = new AndPropositionalOperator(_manager);
                    nAnd.Instantiate(logic.GetChilds());
                    return(SurroundWithNot(HandleAnd(nAnd)));

                case 'F':
                    return(new TruePropositionalOperator(_manager));

                case 'T':
                    return(new FalsePropositionalOperator(_manager));

                case '@':
                    if (work is UniversalQuantifierOperator workUnversal)
                    {
                        var ext = new ExtensionalQuantifierOperator(_manager);
                        ext.SetVariable(workUnversal.GetVariable());
                        ext.Instantiate(new[] { SurroundWithNot(logic.GetChilds()[0]) });
                        return(SurroundWithNot(ext));
                    }
                    break;

                case '!':
                    if (work is ExtensionalQuantifierOperator workExtensional)
                    {
                        var universal = new UniversalQuantifierOperator(_manager);
                        universal.SetVariable(workExtensional.GetVariable());
                        universal.Instantiate(new[] { SurroundWithNot(logic.GetChilds()[0]) });
                        return(SurroundWithNot(universal));
                    }
                    break;
                }
            }

            if (work is PredicateOperator predicate)
            {
                var result = new PredicateOperator(_manager);
                result.SetName(predicate.GetName());
                foreach (var child in work.GetChilds())
                {
                    result.AddChild(Process(child));
                }
                return(result);
            }

            if (work is ScalarPropositionalOperator scalar)
            {
                return(_manager.RequestOperator(scalar.GetName()));
            }
            throw new System.Exception("Operator not found");
        }