コード例 #1
0
        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);
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: GeoffBowden/ZedLang
        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();
        }
コード例 #3
0
 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");
     }
 }
コード例 #4
0
ファイル: PredicateList.cs プロジェクト: GeoffBowden/ZedLang
 public Boolean AddPredicate(PredicateSyntacticElement predicate)
 {
     if (IsPredicate(predicate.Name))
     {
         return(false);
     }
     else
     {
         Predicates.Add(predicate);
         return(true);
     }
 }
コード例 #5
0
        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);
        }
コード例 #6
0
        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");
        }
コード例 #7
0
        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);
        }
コード例 #8
0
ファイル: Program.cs プロジェクト: GeoffBowden/ZedLang
 public PredicateCommand(string commandText, PredicateSyntacticElement pse) : base(commandText)
 {
     this.pse = pse;
 }
コード例 #9
0
ファイル: LogicArgument.cs プロジェクト: GeoffBowden/ZedLang
 public bool Add(PredicateSyntacticElement pse)
 {
     return(predicateList.AddPredicate(pse));
 }