예제 #1
0
        public void GenTestTree()
        {
            Operator root = new Operator("x");
            root.LeftChild = new Number("4");
            root.RightChild = new Number("1");

            tree = root;
        }
예제 #2
0
파일: TreeIterator.cs 프로젝트: TIRKIN/RDP
 public TreeIterator(ASTNode parent)
 {
     while (!CheckChildren(parent))
     {
         ASTNode bottom = GetBottom(parent);
         Variable combination = CombineChildren(bottom);
         ChangeNode(bottom, combination);
     }
     ASTNode finalNode = CombineChildren(parent);
     Console.Write(finalNode.Value);
 }
예제 #3
0
파일: TreeIterator.cs 프로젝트: TIRKIN/RDP
 private Boolean CheckLeftChild(ASTNode parent)
 {
     if (parent.LeftChild.GetType() == typeof (Number))
     {
         return true;
     }
     if (parent.LeftChild.GetType() == typeof (Variable))
     {
         return true;
     }
     return false;
 }
예제 #4
0
파일: TreeIterator.cs 프로젝트: TIRKIN/RDP
 private void ChangeNode(ASTNode oldNode, ASTNode newNode)
 {
     if (oldNode.Parent.LeftChild.Value == oldNode.Value)
     {
         oldNode.Parent.LeftChild = newNode;
     }
     else
     {
         oldNode.Parent.RightChild = newNode;
     }
     newNode.Parent = oldNode.Parent;
 }
예제 #5
0
        public IEnumerable<ASTNode> PreOrderTraversal(ASTNode node)
        {
            Stack<ASTNode> parent = new Stack<ASTNode>();

            while (parent.Count != 0 || node != null)
            {
                if (node != null)
                {
                    yield return node;
                    parent.Push(node.RightChild);
                    node = node.LeftChild;
                }
                else
                {
                    node = parent.Pop();
                }
            }
        }
예제 #6
0
파일: TreeIterator.cs 프로젝트: TIRKIN/RDP
 private ASTNode GetBottomLeftParent(ASTNode start)
 {
     while (!CheckLeftChild(start))
     {
         start = start.LeftChild;
     }
     return start;
 }
예제 #7
0
파일: TreeIterator.cs 프로젝트: TIRKIN/RDP
 private ASTNode GetBottom(ASTNode start)
 {
     while (!CheckChildren(start))
     {
         ASTNode newNode = GetBottomLeftParent(start);
         if (CheckRightChild(newNode))
         {
             start = newNode;
         }
         else
         {
             start = newNode.RightChild;
         }
     }
     return start;
 }
예제 #8
0
파일: TreeIterator.cs 프로젝트: TIRKIN/RDP
 /*private SemanticAnalyzer.SyntaxTree.ASTNode Operate(SemanticAnalyzer.SyntaxTree.ASTNode operateNode)
 {
     String Operator = operateNode.Value;
     float newValue;
     double doubleValue;
     String Value;
     switch (Operator)
     {
         case "*":
             newValue = Single.Parse(operateNode.LeftChild.Value) * Single.Parse(operateNode.RightChild.Value);
         case "+":
             newValue = Single.Parse(operateNode.LeftChild.Value) + Single.Parse(operateNode.RightChild.Value);
         case "-":
             newValue = Single.Parse(operateNode.LeftChild.Value) - Single.Parse(operateNode.RightChild.Value);
         case "^":
             doubleValue = Math.Pow(Single.Parse(operateNode.LeftChild.Value), Single.Parse(operateNode.RightChild.Value));
     }
     if(newValue != null)
     {
         Value = newValue.ToString();
     }
     else if (doubleValue != null)
     {
         Value = doubleValue.ToString();
     }
     else
     {
         Value = "";
     }
     SemanticAnalyzer.SyntaxTree.Node.Number newNode = new SemanticAnalyzer.SyntaxTree.Node.Number(Value);
     changeNode(operateNode, newNode);
     return newNode;
 }*/
 private Variable CombineChildren(ASTNode parent)
 {
     String newString = parent.LeftChild.Value + parent.Value + parent.RightChild.Value;
     var newNode = new Variable(newString);
     return newNode;
 }
예제 #9
0
 private DrawingNode GenDrawingTree(ASTNode node)
 {
     return null;
 }