コード例 #1
0
ファイル: BracketNode.cs プロジェクト: yutuo/Laxer
 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;
         }
     }
 }
コード例 #2
0
ファイル: LaxerParse.cs プロジェクト: yutuo/Laxer
        /// <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;
        }
コード例 #3
0
ファイル: OperateNode.cs プロジェクト: yutuo/Laxer
        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);
                        }
                    }
                }
            }
        }
コード例 #4
0
ファイル: DataNode.cs プロジェクト: yutuo/Laxer
 public override void AddNode(Node node)
 {
     if (node is OperateNode)
     {
         this.Parent = node;
         ((OperateNode)node).Left = this;
     }
     else
     {
         throw new LaxerParseException();
     }
 }
コード例 #5
0
ファイル: LaxerParse.cs プロジェクト: yutuo/Laxer
 /// <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;
     }
 }
コード例 #6
0
ファイル: FunctionNode.cs プロジェクト: yutuo/Laxer
 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;
     }
 }
コード例 #7
0
ファイル: Node.cs プロジェクト: yutuo/Laxer
 public abstract void AddNode(Node node);