コード例 #1
0
ファイル: Model.cs プロジェクト: bclgenki/tvn-cosine
        public bool?visitBinarySentence(ComplexSentence bs, bool?arg)
        {
            bool?firstValue  = bs.getSimplerSentence(0).accept(this, null);
            bool?secondValue = bs.getSimplerSentence(1).accept(this, null);

            if ((firstValue == null) || (secondValue == null))
            {
                // strictly not true for or/and
                // -FIX later
                return(null);
            }
            else
            {
                Connective connective = bs.getConnective();
                if (connective.Equals(Connective.AND))
                {
                    return(firstValue.Value && secondValue.Value);
                }
                else if (connective.Equals(Connective.OR))
                {
                    return(firstValue.Value || secondValue.Value);
                }
                else if (connective.Equals(Connective.IMPLICATION))
                {
                    return(!(firstValue.Value && !secondValue.Value));
                }
                else if (connective.Equals(Connective.BICONDITIONAL))
                {
                    return(firstValue.Equals(secondValue));
                }
                return(null);
            }
        }
コード例 #2
0
        // No hace falta override porque PLVisitor es una interfaz
        public bool?VisitBinarySentence(ComplexSentence bs, bool?arg)
        {
            bool?      firstValue      = (bool?)bs.GetSimplerSentence(0).Accept(this, null);
            bool?      secondValue     = (bool?)bs.GetSimplerSentence(1).Accept(this, null);
            bool       bothValuesKnown = firstValue != null && secondValue != null;
            Connective connective      = bs.GetConnective();

            // He reprogramado todo esto
            if (connective.Equals(Connective.AND))
            {
                if (firstValue.Equals(false) || secondValue.Equals(false))
                {
                    return(false);
                }
                else if (bothValuesKnown)
                {
                    return(true);                      // Si no se cumple, saldrá como null
                }
            }
            else if (connective.Equals(Connective.OR))
            {
                if (firstValue.Equals(true) || secondValue.Equals(true))
                {
                    return(true);
                }
                else if (bothValuesKnown)
                {
                    return(false);                      // Si no se cumple, saldrá como null
                }
            }
            else if (connective.Equals(Connective.IMPLICATION))
            {
                if (firstValue.Equals(false) || secondValue.Equals(true))
                {
                    return(true);
                }
                else if (bothValuesKnown)
                {
                    return(false);                      // Si no se cumple, saldrá como null
                }
            }
            else if (connective.Equals(Connective.BICONDITIONAL))
            {
                if (bothValuesKnown)
                {
                    return(firstValue.Equals(secondValue));                 // Si no se cumple, saldrá como null
                }
            }

            return(null);
        }