예제 #1
0
 private static PropositionExpression RunProposition(PropositionExpression pse, LogicArgument program)
 {
     if (pse is ImplicationSyntacticExpression)
     {
         ExpressionExecutive.execute((ImplicationSyntacticExpression)pse, program.predicateList);
     }
     else if (pse is IfAndOnlyIfSyntacticExpression)
     {
         ExpressionExecutive.execute((IfAndOnlyIfSyntacticExpression)pse, program.predicateList);
     }
     else
     {
         throw new NotImplementedException("this bit cannot be reached and records a design error");
     }
     return(pse);
 }
예제 #2
0
 private static PredicateSetterSyntacticElement RunPredicateSetter(PredicateSetterSyntacticElement pse, LogicArgument program)
 {
     if (pse is PropositionSyntacticElement)
     {
         program.predicateList = ExpressionExecutive.execute((PropositionSyntacticElement)pse, program.predicateList);
     }
     else if (pse is PropositionNegationSyntacticElement)
     {
         program.predicateList = ExpressionExecutive.execute((PropositionNegationSyntacticElement)pse, program.predicateList);
     }
     else
     {   // case cannot currently exist
         throw new NotImplementedException();
     }
     return(pse);
 }
예제 #3
0
        //what does this do?
        // if the conclusion is known, it works out what the conclusion should be and
        // returns the actual conclusion and the given one.
        // p->q conclusion is q predicate is p after execution p is known or not depending on value of p
        // if both are set then? is the truth table checked? do interested in state before and after
        // so how does an implies statement work?
        //  p --> q   ==== !p or q
        //  0  1  0
        //  0  1  1
        //  1  0  0
        //  1  1  1
        /// <summary>
        /// Execute with a full trace of what happened
        /// </summary>
        /// <param name="program"></param>
        public static List <string> Execute(LogicArgument program, out ProgramReturnCode errorCode)
        {
            // we want a value for the whole program and
            // we want a value for each line in the program
            // from the start to the end

            // executing must suggest a value for a predicate,
            // if this value cannot be set
            //    1 can be set to 1
            //    0 can be set to 0
            //    ? can be set to anything  1, 0 or ?

            // The execution must be such that it runs through setting predicates

            // run predicates -- if fails produce result
            // run not expressions -- if fails produce result
            // run propositions in order
            // produce result
            List <string> programOutput = new List <string>();

            // if no errors
            errorCode = Validate(program, ref programOutput);
            if (errorCode == ProgramReturnCode.No_errors)
            {
                errorCode = RunPredicateSetters(program, ref programOutput);
                if (errorCode == ProgramReturnCode.No_errors)
                {
                    // run propositions
                    errorCode = RunPropositions(program, ref programOutput);
                    if (errorCode == ProgramReturnCode.No_errors)
                    {
                        // run therefore statement
                        ExpressionExecutive.execute(program.thereforeSyntacticElement, program.predicateList);
                        program.Conclusion = program.thereforeSyntacticElement.Value;
                        if (program.Conclusion == true)
                        {
                            programOutput.Add("Your arguments conclusion was true.");
                        }
                        else
                        {
                            programOutput.Add("Your arguments conclusion was false.");
                        }
                    }
                }
            }
            return(programOutput);
        }