Example #1
0
        public override bool IsTheSameAs(Connective con)
        {
            if (con is ConnectiveFunction)
            {
                ConnectiveFunction c = (ConnectiveFunction)con;

                if (c.FunctionChar == this.functionChar)
                {
                    if (c.LocalArguments.Count == this.localArguments.Count)
                    {
                        bool differenceFound = false;
                        for (int i = 0; i < this.localArguments.Count; i++)
                        {
                            if (c.LocalArguments[i] != this.localArguments[i])
                            {
                                differenceFound = true;
                                break;
                            }
                        }
                        return(!differenceFound);
                    }
                }
            }
            return(false);
        }
Example #2
0
        public override Connective Copy()
        {
            ConnectiveFunction cf = new ConnectiveFunction();

            cf.SetFunctionChar(functionChar);
            foreach (char c in localArguments)
            {
                cf.AddArgument(c);
            }
            return(cf);
        }
Example #3
0
        private static Connective readPropositionStringRec()
        {
            Connective Head  = null;
            int        index = 0;


            while (PropositionList.Count != 0)
            {
                switch (PropositionList[0])
                {
                case ',':
                    //ERROR CHECKING
                    if (index == 0)
                    {
                        throw new Exception("',' has not been placed between '(' and ')'");
                    }
                    if (Head != null)
                    {
                        if (Head is ConnectiveNot || Head is ConnectiveArgument)
                        {
                            throw new Exception("'" + Head.GetLocalString() + "' does not need more than 2 parameters");
                        }
                        if (Head is ConnectiveOne)
                        {
                            if (((ConnectiveOne)Head).Con1 == null)
                            {
                                throw new Exception("'" + Head.GetLocalString() + "' is missing a left connective");
                            }
                        }
                        if (Head is ConnectiveFunction)
                        {
                            if (((ConnectiveFunction)Head).LocalArguments.Count != index)
                            {
                                throw new Exception("'" + Head.GetLocalString() + "' is missing a parameter");
                            }
                        }
                    }
                    else
                    {
                        throw new Exception("',' does not belong to any connective");
                    }

                    //SET INDEX
                    index++;
                    PropositionList.RemoveAt(0);
                    break;

                case '(':
                    //ERROR CHECKING
                    if (Head == null)
                    {
                        throw new Exception("'(' does not belong to any connective");
                    }
                    if (Head is ConnectiveArgument)
                    {
                        throw new Exception("'" + Head.GetLocalString() + "' cannot have any parameters");
                    }

                    //SET INDEX
                    index = 1;
                    PropositionList.RemoveAt(0);
                    break;

                case ')':
                    //ERROR CHECKING
                    if (index == 1)
                    {
                        if (Head is ConnectiveArgument)
                        {
                            throw new Exception("'" + Head.GetLocalString() + "' cannot have any parameters");
                        }
                        if (Head is ConnectiveOne)
                        {
                            if (((ConnectiveOne)Head).Con1 == null)
                            {
                                throw new Exception("'" + Head.GetLocalString() + "' is missing a left connective");
                            }
                        }
                        if (Head is ConnectiveFunction)
                        {
                            if (((ConnectiveFunction)Head).LocalArguments.Count == 0)
                            {
                                throw new Exception("Function '" + Head.GetLocalString() + "' is missing parameters");
                            }
                        }
                    }
                    else if (index == 2)
                    {
                        if (Head is ConnectiveNot || Head is ConnectiveArgument)
                        {
                            throw new Exception("'" + Head.GetLocalString() + "' cannot have 2 paramters, only 1");
                        }
                        if (Head is ConnectiveTwo)
                        {
                            if (((ConnectiveTwo)Head).Con2 == null)
                            {
                                throw new Exception("'" + Head.GetLocalString() + "' is missing a right connective");
                            }
                        }
                    }

                    PropositionList.RemoveAt(0);
                    return(Head);

                default:
                    if (ConnectiveTypes.Contains(PropositionList[0]))     //type found
                    {
                        Connective con;
                        switch (index)
                        {
                        case 0:
                            if (Head == null)
                            {
                                con  = getConnectiveByType(PropositionList[0]);
                                Head = con;
                                if (Head is ConnectiveQuantifier)
                                {
                                    if (PropositionList.Count >= 3)
                                    {
                                        ConnectiveQuantifier cq = (ConnectiveQuantifier)Head;
                                        if (SmallArguments.Contains(PropositionList[1]))
                                        {
                                            cq.SetArgument(PropositionList[1]);
                                            PropositionList.RemoveAt(0);         //removes @/!
                                            PropositionList.RemoveAt(0);         //removes local argument
                                        }
                                        else
                                        {
                                            throw new Exception("Invalid local variable '" + PropositionList[1] + "' for quantifier: " + PropositionList[0]);
                                        }
                                    }
                                    else
                                    {
                                        throw new Exception("Unfinished quantifier: " + PropositionList[0]);
                                    }
                                }
                                PropositionList.RemoveAt(0);         //removes type or .
                            }
                            else
                            {
                                throw new Exception("'" + PropositionList[0] + "' cannot be placed after another connective");
                            }
                            break;

                        case 1:
                            if (Head != null)
                            {
                                if (!(Head is ConnectiveArgument || Head is ConnectiveFunction))
                                {
                                    con = readPropositionStringRec();
                                    ((ConnectiveOne)Head).setLeftConnective(con);
                                }
                                else
                                {
                                    throw new Exception("'" + Head.GetLocalString() + "' does not need any connectives as parameters");
                                }
                            }
                            else
                            {
                                throw new Exception("Internal index problem occured (index = 1, Head = null)");
                            }
                            break;

                        case 2:
                            if (Head != null)
                            {
                                if (Head is ConnectiveTwo)
                                {
                                    con = readPropositionStringRec();
                                    ((ConnectiveTwo)Head).setRightConnective(con);
                                }
                                else
                                {
                                    throw new Exception("'" + Head.GetLocalString() + "' cannot have a second parameter");
                                }
                            }
                            else
                            {
                                throw new Exception("Internal index problem occured (index = 2, Head = null)");
                            }
                            break;

                        default:
                            throw new Exception("Internal index problem occured (index > 2 & head != function)");
                        }
                    }
                    else if (Arguments.Contains(PropositionList[0]))     //argument found
                    {
                        Connective con;
                        con = new ConnectiveArgument(PropositionList[0]);
                        if (PropositionList.Count > 1)
                        {
                            if (PropositionList[1] == '(')
                            {
                                con = new ConnectiveFunction();
                                ((ConnectiveFunction)con).SetFunctionChar(PropositionList[0]);
                            }
                        }

                        switch (index)
                        {
                        case 0:
                            if (Head == null)
                            {
                                PropositionList.RemoveAt(0);
                                Head = con;
                            }
                            else
                            {
                                throw new Exception("'" + PropositionList[0] + "' cannot be placed after another connective");
                            }
                            break;

                        case 1:
                            if (Head != null)
                            {
                                if (!(Head is ConnectiveArgument || Head is ConnectiveFunction))
                                {
                                    if (con is ConnectiveFunction)
                                    {
                                        con = readPropositionStringRec();
                                    }
                                    else
                                    {
                                        PropositionList.RemoveAt(0);
                                    }
                                    ((ConnectiveOne)Head).setLeftConnective(con);
                                }
                                else
                                {
                                    throw new Exception("'" + Head.GetLocalString() + "' cannot have Argument as parameter");
                                }
                            }
                            else
                            {
                                throw new Exception("Internal index problem occured (index = 1, Head = null)");
                            }
                            break;

                        case 2:
                            if (Head != null)
                            {
                                if (!(Head is ConnectiveArgument || Head is ConnectiveFunction))
                                {
                                    if (con is ConnectiveFunction)
                                    {
                                        con = readPropositionStringRec();
                                    }
                                    else
                                    {
                                        PropositionList.RemoveAt(0);
                                    }
                                    ((ConnectiveTwo)Head).setRightConnective(con);
                                }
                                else
                                {
                                    throw new Exception("'" + Head.GetLocalString() + "' cannot have Argument as parameter");
                                }
                            }
                            else
                            {
                                throw new Exception("Internal index problem occured (index = 2, Head = null)");
                            }
                            break;

                        default:
                            throw new Exception("Internal index problem occured (index > 2 & Head != Function)");
                        }
                    }
                    else if (SmallArguments.Contains(PropositionList[0]))
                    {
                        if (Head != null)
                        {
                            if (Head is ConnectiveFunction)
                            {
                                ConnectiveFunction cf = (ConnectiveFunction)Head;
                                cf.AddArgument(PropositionList[0]);
                                PropositionList.RemoveAt(0);
                            }
                            else
                            {
                                throw new Exception("Local Argument found outside Function/Quantifier: " + PropositionList[0]);
                            }
                        }
                        else
                        {
                            throw new Exception("Local Argument found outside Function/Quantifier: " + PropositionList[0]);
                        }
                    }
                    else if (PropositionList[0] != ' ')    //UNKNOWN (no space)
                    {
                        throw new Exception("Unknown character found, char: '" + PropositionList[0] + "'. Please remove it!");
                    }
                    else     //SPACE
                    {
                        PropositionList.RemoveAt(0);
                    }
                    break;
                }
            }
            //Final check for main connective
            if (Head != null)
            {
                if (!(Head is ConnectiveArgument || Head is ConnectiveFunction))
                {
                    if (Head is ConnectiveNot || Head is ConnectiveQuantifier)
                    {
                        if (((ConnectiveOne)Head).Con1 == null)
                        {
                            throw new Exception("'" + Head.GetLocalString() + "' is missing a left connective");
                        }
                    }
                    else
                    {
                        if (((ConnectiveTwo)Head).Con1 == null)
                        {
                            throw new Exception("'" + Head.GetLocalString() + "' is missing a left connective");
                        }
                        if (((ConnectiveTwo)Head).Con2 == null)
                        {
                            throw new Exception("'" + Head.GetLocalString() + "' is missing a right connective");
                        }
                    }
                }
            }
            return(Head);
        }