Exemple #1
0
 public override void AddNode(Node node)
 {
     if (IsComplete)
     {
         if (!(node is OperateNode))
         {
             throw new LaxerParseException();
         }
         else
         {
             OperateNode operateNode = (OperateNode)node;
             operateNode.Left = this;
             operateNode.Parent = this.Parent;
             this.Parent = operateNode;
         }
     }
     else if (Value == null)
     {
         node.Parent = this;
         this.Value = node;
     }
     else
     {
         this.Value.AddNode(node);
         while (!Object.ReferenceEquals(this, this.Value.Parent))
         {
             this.Value = this.Value.Parent;
         }
     }
 }
Exemple #2
0
        /// <summary>
        /// 转换Reader
        /// </summary>
        /// <param name="reader">Reader</param>
        /// <returns>转换结果</returns>
        public Node Parse(TextReader reader)
        {
            this.reader = reader;
            this.rootNode = null;

            while (this.Next() > 0) { }
            return this.rootNode;
        }
Exemple #3
0
        public override void AddNode(Node node)
        {
            if (this.Right == null)
            {
                if ((node is OperateNode))
                {
                    throw new LaxerParseException();
                }
                else
                {
                    node.Parent = this;
                    this.Right = node;
                    if (node.IsComplete)
                    {
                        this.TrySetCompleted();
                    }
                }
            }
            else
            {
                if (!IsComplete)
                {
                    this.Right.AddNode(node);
                }
                else
                {
                    if (!(node is OperateNode))
                    {
                        throw new LaxerParseException();
                    }

                    this.SetUnComplete();

                    OperateNode operateNode = (OperateNode)node;
                    if (this.Operate.Priority < operateNode.Operate.Priority)
                    {
                        operateNode.Left = this.Right;
                        operateNode.Parent = this;

                        this.Right = operateNode;
                    }
                    else
                    {
                        Node parent = this.Parent;
                        operateNode.Left = this;
                        this.Parent = operateNode;
                        operateNode.Parent = parent;

                        if (parent is OperateNode)
                        {
                            OperateNode operateParent = (OperateNode)parent;
                            operateParent.Right = null;
                            operateParent.AddNode(operateNode);
                        }
                    }
                }
            }
        }
Exemple #4
0
 public override void AddNode(Node node)
 {
     if (node is OperateNode)
     {
         this.Parent = node;
         ((OperateNode)node).Left = this;
     }
     else
     {
         throw new LaxerParseException();
     }
 }
Exemple #5
0
 /// <summary>
 /// 添加到Node
 /// </summary>
 /// <param name="node">需要添加的Node</param>
 private void AddToNode(Node node)
 {
     if (this.rootNode == null)
     {
         this.rootNode = node;
     }
     else
     {
         this.rootNode.AddNode(node);
         while (node.Parent != null)
         {
             node = node.Parent;
         }
         this.rootNode = node;
     }
 }
Exemple #6
0
 public override void AddNode(Node node)
 {
     // TODO Check Param Count
     if (IsComplete)
     {
         if (!(node is OperateNode))
         {
             throw new LaxerParseException();
         }
         else
         {
             OperateNode operateNode = (OperateNode)node;
             operateNode.Left = this;
             operateNode.Parent = this.Parent;
             this.Parent = operateNode;
         }
     }
     else if (paramEnded || Params.Count == 0)
     {
         if (Params.Count > Function.MaxParam)
         {
             throw new LaxerParseException();
         }
         else
         {
             node.Parent = this;
             Params.Add(node);
             paramEnded = false;
         }
     }
     else
     {
         Node last = Params.Last();
         last.AddNode(node);
         while (!Object.ReferenceEquals(this, last.Parent))
         {
             last = last.Parent;
         }
         Params[Params.Count - 1] = last;
     }
 }
Exemple #7
0
 public abstract void AddNode(Node node);