예제 #1
0
 public static SyntacticElement Parse(List <string> lineElements)
 {
     if (string.Compare("therefore", lineElements[0], StringComparison.OrdinalIgnoreCase) == 0)
     {
         ThereforeSyntacticElement therefore = new ThereforeSyntacticElement();
         // get lhs prop p and q imp z
         List <string>    expressionText = lineElements.Skip(1).ToList();
         SyntacticElement expression     = ExpressionParser.Parse(expressionText);
         // check lhs
         if (expression == null)
         {
             return(new InvalidSyntacticElement("No expression for therefore", "Nothing to be proved? why are you here?"));
         }
         else if (expression is InvalidSyntacticElement)
         {
             return(new InvalidSyntacticElement("Invalid expression for therefore", ((InvalidSyntacticElement)expression).Message));
         }
         else if (expression is ExpressionSyntacticElement)
         {
             therefore.expression = (ExpressionSyntacticElement)expression;
         }
         else
         {
             throw new InvalidOperationException();
         }
         return(therefore);
     }
     else
     {   // this is here if someone changes the design.
         return(new InvalidSyntacticElement("No therefore header", "cannot parse what does not exist"));
     }
 }
예제 #2
0
 public void Clear()
 {
     predicateList             = new PredicateList();
     propositionList           = new PropositionList();
     predicateSetterList       = new PredicateSetterList();
     thereforeSyntacticElement = null;
 }
예제 #3
0
 public LogicArgument()
 {
     predicateList             = new PredicateList();
     propositionList           = new PropositionList();
     predicateSetterList       = new PredicateSetterList();
     thereforeSyntacticElement = null;
     Conclusion = null;
 }
예제 #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
 public bool Add(ThereforeSyntacticElement tse)
 {
     // only one allowed
     if (thereforeSyntacticElement == null)
     {
         thereforeSyntacticElement = tse;
         return(true);
     }
     else
     {
         return(false);
     }
 }
예제 #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
 /// <summary>
 /// each of the following expressions all rely on expressions either unary or binary
 /// these are defined in the evaluate function, these can only really be worked out when all predicate suppositions
 /// are made. For propositions like p and not p must be run
 /// </summary>
 /// <param name="element"></param>
 /// <param name="predicateState"></param>
 /// <returns></returns>
 public static PredicateList execute(ThereforeSyntacticElement element, PredicateList predicateState)
 {
     // for of a therefore are
     element.Value = ExpressionExecutive.Evaluate(element.expression, predicateState);
     return(predicateState);
 }