Пример #1
0
        private static ProgramReturnCode RunPropositions(LogicArgument program, ref List <string> programOutput)
        {
            ProgramReturnCode errorCode = ProgramReturnCode.No_errors;

            for (int i = 0; i < program.propositionList.PropositionCount(); i++)
            {
                PropositionExpression pse = program.propositionList.GetPropositionAt(i);
                try
                {
                    pse = RunProposition(pse, program);
                    if (pse.Value == false)
                    {
                        string error = pse.Text + " : Evaluated to false";
                        programOutput.Add(error);
                        errorCode = ProgramReturnCode.Predicate_evaluates_to_false;
                    }
                    if (pse.Value == null)
                    {
                        string error = pse.Text + " : Evaluated to null";
                        programOutput.Add(error);
                        errorCode = ProgramReturnCode.Predicate_evaluates_to_unknown;
                    }
                }
                catch (Exception ex)
                {
                    programOutput.Add(ex.Message);
                }
            }
            return(errorCode);
        }
Пример #2
0
 public override string ToString()
 {
     if (PropositionExpression != null)
     {
         return(PropositionExpression.ToString());
     }
     return(base.ToString());
 }
Пример #3
0
 public Boolean AddProposition(PropositionExpression proposition)
 {
     if (proposition == null)
     {
         throw new ArgumentNullException("PropositionList.AddProposition: cannot add nulls");
     }
     Propositions.Add(proposition);
     return(true);
 }
Пример #4
0
        public override void Execute()
        {
            if (Command is PredicateSyntacticElement)
            {
                PredicateSyntacticElement pse = (PredicateSyntacticElement)(Command);
                Bertrand.program.Add(commandText);
                if (pse.State == State.Known)
                {
                    Console.WriteLine("added predicate {0} > '{1}' with a value of {2}", pse.Name, pse.Predicate, pse.Value.ToString());
                }
                else
                {
                    Console.WriteLine("added predicate {0} > '{1}' with an unknown value", pse.Name, pse.Predicate);
                }
                return;
            }
            if (Command is PropositionExpression)
            {
                PropositionExpression pse = (PropositionExpression)(Command);
                Bertrand.program.Add(commandText);
                Console.WriteLine("added proposition {0}' ", pse.Text);
                return;
            }
            if (Command is PropositionSyntacticElement)
            {
                PropositionSyntacticElement pse = (PropositionSyntacticElement)(Command);
                Bertrand.program.Add(commandText);
                Console.WriteLine("added proposition setter {0}' ", pse.Text);
                return;
            }

            if (Command is PropositionNegationSyntacticElement)
            {
                PropositionExpression pse = (PropositionExpression)(Command);
                Bertrand.program.Add(commandText);
                Console.WriteLine("added proposition setter {0}' ", pse.Text);
                return;
            }

            if (Command is ThereforeSyntacticElement)
            {
                ThereforeSyntacticElement pse = (ThereforeSyntacticElement)(Command);
                Bertrand.program.Add(commandText);
                Console.WriteLine("added therefore command {0}' ", pse.Text);
                return;
            }

            if (Command is InvalidSyntacticElement)
            {
                InvalidSyntacticElement ise = (InvalidSyntacticElement)Command;
                Console.WriteLine("Error> {0}: {1}", ise.Title, ise.Message);
                Console.WriteLine(commandText);
                return;
            }
            throw new NotImplementedException();
        }
Пример #5
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);
 }
Пример #6
0
        // assumes a valid syntactic element
        public ProgramFile Add(string line)
        {
            SyntacticElement se = LineParser.Parse(line);

            if (se is InvalidSyntacticElement)
            {
                throw new ArgumentException("Unable to add invalid syntactic element! " + se.Text);
            }
            if (se is PredicateSyntacticElement)
            {
                PredicateSyntacticElement p = (PredicateSyntacticElement)se;
                if (!programData.Add(p))
                {
                    throw new ArgumentException("Predicate {0} already exists", p.Name);
                }
            }
            if (se is PropositionExpression)
            {
                PropositionExpression p = (PropositionExpression)se;
                programData.Add(p);
            }
            if (se is PredicateSetterSyntacticElement)
            {
                programData.Add((PredicateSetterSyntacticElement)se);
            }
            if (se is ThereforeSyntacticElement)
            {
                ThereforeSyntacticElement t = (ThereforeSyntacticElement)se;
                programData.Add(t);
            }
            if (!(se is NullSyntacticElement))
            {
                Listing.Add(line);
            }
            return(this);
        }
Пример #7
0
 public bool Add(PropositionExpression pse)
 {
     propositionList.AddProposition(pse);
     return(true);
 }