예제 #1
0
 /*
  * Recursively prints All children nodes of the tree
  */
 public static void PrintTree(BooleanNode tree)
 {
     if (tree != null)
     {
         Console.WriteLine(tree.ToString());
         PrintTree(tree.firstVar);
         PrintTree(tree.secondVar);
     }
 }
예제 #2
0
 /*
  * Creates the root expression which recursively creates the whole expression
  */
 private void CreateRootExpression(String expression)
 {
     if (BooleanNode.IsSingleVar(expression))
     {
         this.RootExpression = new VariableNode(expression);
     }
     else
     {
         this.RootExpression = new GateNode(expression);
     }
 }
예제 #3
0
        /*
         * The actually important function, creates children expressions, and then determines the types of nodes that need to be created as
         * children
         */
        public override Dictionary <String, List <VariableNode> > CreateChildren(Dictionary <String, List <VariableNode> > variables)
        {
            Tuple <String, String> expressions = this.CreateChildrenExpressions();

            if (expressions.Item1.Equals("") && expressions.Item2.Equals(""))
            {
                Console.WriteLine("ERROR");
            }
            if (expressions.Item2.Equals("SingleInv")) // single inverter case
            {
                this.firstVar = new VariableNode(expressions.Item1);
                this.firstVar.CreateChildren(variables);
                this.secondVar = null;
            }
            else if (expressions.Item2.Equals("MultiInv")) // single inverter case
            {
                this.firstVar = new GateNode(expressions.Item1);
                this.firstVar.CreateChildren(variables);
                this.secondVar = null;
            }
            else
            {
                if (BooleanNode.IsSingleVar(expressions.Item1))
                {
                    this.firstVar = new VariableNode(expressions.Item1);
                }
                else
                {
                    this.firstVar = new GateNode(expressions.Item1);
                }

                this.firstVar.CreateChildren(variables);

                if (BooleanNode.IsSingleVar(expressions.Item2))
                {
                    this.secondVar = new VariableNode(expressions.Item2);
                }
                else
                {
                    this.secondVar = new GateNode(expressions.Item2);
                }

                this.secondVar.CreateChildren(variables);
            }

            return(variables);
        }
예제 #4
0
 /*
  * Uses the static method on the BooleanNode class to print all child expressions of the the
  * root node in this case
  */
 public void PrintTree()
 {
     BooleanNode.PrintTree(this.RootExpression);
 }