示例#1
0
        private List <WFF> IdentityDecompose(Identity i, Connective f)
        {
            if (f is Biconditional)
            {
                return(IdentityDecompose(i, (Biconditional)f));
            }
            else if (f is Conditional)
            {
                return(IdentityDecompose(i, (Conditional)f));
            }
            else if (f is Conjunction)
            {
                return(IdentityDecompose(i, (Conjunction)f));
            }
            else if (f is Disjunction)
            {
                return(IdentityDecompose(i, (Disjunction)f));
            }
            else if (f is Negation)
            {
                return(IdentityDecompose(i, (Negation)f));
            }

            throw new NotImplementedException(f.GetType().ToString());
        }
示例#2
0
        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);
            }
        }
示例#3
0
        private Decomposition DecomposeWFF(Connective f)
        {
            if (f is Biconditional)
            {
                return(DecomposeWFF((Biconditional)f));
            }
            else if (f is Conditional)
            {
                return(DecomposeWFF((Conditional)f));
            }
            else if (f is Conjunction)
            {
                return(DecomposeWFF((Conjunction)f));
            }
            else if (f is Disjunction)
            {
                return(DecomposeWFF((Disjunction)f));
            }
            else if (f is Negation)
            {
                return(DecomposeWFF((Negation)f));
            }

            throw new NotImplementedException(f.GetType().ToString());
        }
示例#4
0
        private ParseNode parseConnective()
        {
            Token      token      = lookAhead(1);
            Connective connective = Connective.get(token.getText());

            consume();
            return(new ParseNode(connective, token));
        }
示例#5
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);
        }
示例#6
0
        private Token connective()
        {
            int            startPosition = getCurrentPositionInInput();
            IStringBuilder sbuf          = TextFactory.CreateStringBuilder();

            // Ensure pull out just one connective at a time, the isConnective(...)
            // test ensures we handle chained expressions like the following:
            // ~~P
            while (null != lookAhead(1) && Connective.isConnectiveIdentifierPart(lookAhead(1).Value) && !isConnective(sbuf.ToString()))
            {
                sbuf.Append(lookAhead(1));
                consume();
            }

            string symbol = sbuf.ToString();

            if (isConnective(symbol))
            {
                return(new Token(LogicTokenTypes.CONNECTIVE, sbuf.ToString(), startPosition));
            }

            throw new LexerException("Lexing error on connective " + symbol + " at position " + getCurrentPositionInInput(), getCurrentPositionInInput());
        }
示例#7
0
 public static int SortOrder(this Connective f)
 {
     if (f is Biconditional)
     {
         return(2);
     }
     else if (f is Conditional)
     {
         return(2);
     }
     else if (f is Conjunction)
     {
         return(1);
     }
     else if (f is Disjunction)
     {
         return(((Disjunction)f).arity);
     }
     else if (f is Negation)
     {
         return(SortOrder((Negation)f));
     }
     throw new NotImplementedException(f.GetType().ToString());
 }
示例#8
0
 public static bool Decomposable(this Connective f)
 {
     if (f is Biconditional)
     {
         return(true);
     }
     else if (f is Conditional)
     {
         return(true);
     }
     else if (f is Conjunction)
     {
         return(true);
     }
     else if (f is Disjunction)
     {
         return(true);
     }
     else if (f is Negation)
     {
         return(Decomposable((Negation)f));
     }
     throw new NotImplementedException(f.GetType().ToString());
 }
示例#9
0
        private ICollection <ParseNode> groupSimplerSentencesByConnective(
            Connective connectiveToConstruct, ICollection <ParseNode> parseNodes)
        {
            ICollection <ParseNode> newParseNodes = CollectionFactory.CreateQueue <ParseNode>();
            int numSentencesMade = 0;

            // Go right to left in order to make right associative,
            // which is a natural default for propositional logic
            for (int i = parseNodes.Size() - 1; i >= 0; i--)
            {
                ParseNode parseNode = parseNodes.Get(i);
                if (parseNode.node is Connective)
                {
                    Connective tokenConnective = (Connective)parseNode.node;
                    if (tokenConnective == Connective.NOT)
                    {
                        // A unary connective
                        if (i + 1 < parseNodes.Size() &&
                            parseNodes.Get(i + 1).node is Sentence)
                        {
                            if (tokenConnective == connectiveToConstruct)
                            {
                                ComplexSentence newSentence = new ComplexSentence(
                                    connectiveToConstruct,
                                    (Sentence)parseNodes.Get(i + 1).node);
                                parseNodes.Set(i, new ParseNode(newSentence, parseNode.token));
                                parseNodes.Set(i + 1, null);
                                numSentencesMade++;
                            }
                        }
                        else
                        {
                            throw new ParserException(
                                      "Unary connective argurment is not a sentence at input position "
                                      + parseNode.token
                                      .getStartCharPositionInInput(),
                                      parseNode.token);
                        }
                    }
                    else
                    {
                        // A Binary connective
                        if ((i - 1 >= 0 && parseNodes.Get(i - 1).node is Sentence)

                            && (i + 1 < parseNodes.Size() && parseNodes
                                .Get(i + 1).node is Sentence))
                        {
                            // A binary connective
                            if (tokenConnective == connectiveToConstruct)
                            {
                                ComplexSentence newSentence = new ComplexSentence(
                                    connectiveToConstruct,
                                    (Sentence)parseNodes.Get(i - 1).node,
                                    (Sentence)parseNodes.Get(i + 1).node);
                                parseNodes.Set(i - 1, new ParseNode(newSentence, parseNode.token));
                                parseNodes.Set(i, null);
                                parseNodes.Set(i + 1, null);
                                numSentencesMade++;
                            }
                        }
                        else
                        {
                            throw new ParserException("Binary connective argurments are not sentences at input position "
                                                      + parseNode.token
                                                      .getStartCharPositionInInput(),
                                                      parseNode.token);
                        }
                    }
                }
            }

            for (int i = 0; i < parseNodes.Size(); ++i)
            {
                ParseNode parseNode = parseNodes.Get(i);
                if (parseNode != null)
                {
                    newParseNodes.Add(parseNode);
                }
            }

            // Ensure no tokens left unaccounted for in this pass.
            int toSubtract = 0;

            if (connectiveToConstruct == Connective.NOT)
            {
                toSubtract = (numSentencesMade * 2) - numSentencesMade;
            }
            else
            {
                toSubtract = (numSentencesMade * 3) - numSentencesMade;
            }

            if (parseNodes.Size() - toSubtract != newParseNodes.Size())
            {
                throw new ParserException(
                          "Unable to construct sentence for connective: "
                          + connectiveToConstruct + " from: " + parseNodes,
                          getTokens(parseNodes));
            }

            return(newParseNodes);
        }
示例#10
0
 private bool connectiveDetected(char leadingChar)
 {
     return(Connective.isConnectiveIdentifierStart(leadingChar));
 }
示例#11
0
 private bool isConnective(string aSymbol)
 {
     return(Connective.isConnective(aSymbol));
 }