Ejemplo n.º 1
0
 public virtual void Visit(ImplicationNode node){}
Ejemplo n.º 2
0
 public override void Visit(ImplicationNode node)
 {
     throw new NotSupportedException(String.Format(
         "Not a CNF or fatal error: '{0}", node.Parent));
 }
Ejemplo n.º 3
0
        /// <summary>
        /// A method that is called to actually build a tree from a given input. Is called from ProcessStringInput()
        /// </summary>
        /// <param name="input">input string</param>
        /// <param name="root">Node used in recursion for creating a binary tree</param>
        /// <exception cref="Exception"></exception>
        private void BuildTree(string input, Node root)
        {
            if (input == string.Empty)
            {
                return;
            }

            char first_character = input[0];

            if (first_character == '~')
            {
                NotNode node = new NotNode(input, root);
                root.Insert(node);
                BuildTree(node.Value, node);
            }
            else if (first_character == '>')
            {
                ImplicationNode node = new ImplicationNode(input, root);
                root.Insert(node);
                BuildTree(node.Value, node);
            }
            else if (first_character == '=')
            {
                BiImplicationNode node = new BiImplicationNode(input, root);
                root.Insert(node);
                BuildTree(node.Value, node);
            }
            else if (first_character == '&')
            {
                ConjunctionNode node = new ConjunctionNode(input, root);
                root.Insert(node);
                BuildTree(node.Value, node);
            }
            else if (first_character == '|')
            {
                DisjunctionNode node = new DisjunctionNode(input, root);
                root.Insert(node);
                BuildTree(node.Value, node);
            }
            else if (first_character == '%')
            {
                NandNode node = new NandNode(input, root);
                root.Insert(node);
                BuildTree(node.Value, node);
            }
            else if (Char.IsUpper(first_character) && input[1] == '(')
            {
                /* predicate case */
                /* P(x), Q(x) */

                int closingBracketIndex = GetIndexOfClosingBracket(input, 1);

                var vars = QuantifierInputHandler.StringStartEndIndex(input, 2, closingBracketIndex - 1).Split(',');

                PredicateNode predicate = new PredicateNode(first_character);

                List <PropositionNode> propositions = new List <PropositionNode>();

                foreach (var variable in vars)
                {
                    propositions.Add(new PropositionNode(variable));
                }

                predicate.Formulas = propositions;

                root.Insert(predicate);
                predicate.parent = root;

                input = input.Substring(closingBracketIndex + 1);

                BuildTree(input, predicate);
            }
            else if (first_character == '@' || first_character == '!')
            {
                string quantifierInput = QuantifierInputHandler.ParseOutInputForQuantifiers(input);
                QuantifierInputHandler quantifierInputHandler = new QuantifierInputHandler(quantifierInput);
                var node = quantifierInputHandler.Create();

                node.parent = root;

                root.Insert(node);

                var newInput = input.Substring(IndexTillWhichStringAreSame(quantifierInput, input) + 1);

                BuildTree(newInput, node);
            }
            else if (first_character == ',')
            {
                if (root.parent == null)
                {
                    throw new Exception("Error in your input");
                }

                root  = root.parent;
                input = input.Substring(1);
                BuildTree(input, root);
            }
            else if (Char.IsLetter(first_character))
            {
                PropositionNode node = new PropositionNode(first_character.ToString(), input, root);
                root.Insert(node);
                BuildTree(node.Value, node);
            }
            else if (first_character == ')')
            {
                int numberOflevels = CalculateNumberOfLevelsToGoUp(input);

                for (int i = 0; i < numberOflevels; i++)
                {
                    if (root.parent != null)
                    {
                        root = root.parent;
                    }
                    else
                    {
                        throw new Exception("Error in string input. Source: class Processor, method BuildTree, else if (')')");
                    }
                }

                input = input.Substring(numberOflevels);
                BuildTree(input, root);
            }
            else if (first_character == '(')
            {
                input = input.Substring(1);
                BuildTree(input, root);
            }
        }
Ejemplo n.º 4
0
 protected virtual IAstTreeNode Xform(ImplicationNode node) { return null; }
Ejemplo n.º 5
0
 public sealed override void Visit(ImplicationNode node) { VisitAndXform(node, Xform(node)); }
Ejemplo n.º 6
0
 protected override IAstTreeNode Xform(ImplicationNode node)
 {
     return new OrNode(!node.Premise, node.Conclusion);
 }