public static PredicateList execute(PropositionSyntacticElement element, PredicateList predicateState) { // when a proposition element is executed the proposition // must be set to true. This can only be done when: // the proposition is found in the list // the proposition must not be false // the element can then be set to true PredicateSyntacticElement pse = predicateState.GetPredicate(element.PredicateName); if (pse == null) { element.Value = false; throw new ArgumentNullException(element.PredicateName + "could not bo found in state for " + element.Text); } else { if (pse.Value == false) { element.Value = false; } else { pse.Value = true; element.Value = true; } } return(predicateState); }
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(); }
public static bool?Evaluate(PredicateExpression exp, PredicateList state) { if (state.IsPredicate(exp.PredicateName)) { PredicateSyntacticElement p = state.GetPredicate(exp.PredicateName); return(p.Value); } else { throw new ArgumentOutOfRangeException("predicate not found in state"); } }
public Boolean AddPredicate(PredicateSyntacticElement predicate) { if (IsPredicate(predicate.Name)) { return(false); } else { Predicates.Add(predicate); return(true); } }
public void LineParser_ValidPredicateDefinition_NoValue_ReturnsPredicate_Unknown() { string line; line = "\tpredicate p > raining in chicago"; SyntacticElement parseResult; parseResult = LineParser.Parse(line); Assert.AreEqual(parseResult.GetType(), typeof(PredicateSyntacticElement)); Assert.AreEqual(parseResult.State, State.Unknown); PredicateSyntacticElement pe = (PredicateSyntacticElement)parseResult; Assert.AreEqual("p", pe.Name); Assert.AreEqual("raining in chicago", pe.Predicate); }
public void LineParser_ValidPredicateDefinition_nospaces_ReturnsPredicate() { string line; line = "\tpredicate p>raining in chicago=false"; SyntacticElement parseResult; parseResult = LineParser.Parse(line); Assert.AreEqual(parseResult.GetType(), typeof(PredicateSyntacticElement)); Assert.AreEqual(parseResult.State, State.Known); Assert.AreEqual(parseResult.Value, false); PredicateSyntacticElement pe = (PredicateSyntacticElement)parseResult; Assert.AreEqual(pe.Name, "p"); Assert.AreEqual(pe.Predicate, "raining in chicago"); }
public void LineParser_ValidPredicateDefinition_IntegerValue1_ReturnsPredicate_KnownTrue() { string line; line = "\tpredicate p > raining in chicago = 1"; SyntacticElement parseResult; parseResult = LineParser.Parse(line); Assert.AreEqual(parseResult.GetType(), typeof(PredicateSyntacticElement)); Assert.AreEqual(parseResult.State, State.Known); Assert.AreEqual(parseResult.Value, true); PredicateSyntacticElement pe = (PredicateSyntacticElement)parseResult; Assert.AreEqual(pe.Name, "p"); Assert.AreEqual("raining in chicago", pe.Predicate); }
public PredicateCommand(string commandText, PredicateSyntacticElement pse) : base(commandText) { this.pse = pse; }
public bool Add(PredicateSyntacticElement pse) { return(predicateList.AddPredicate(pse)); }