コード例 #1
0
 internal void Complete()
 {
     if (_nodeStack.Count != 0)
     {
         StackNode data = (StackNode)_nodeStack.Pop();
         throw ParserException.ParenNotMatch(data.charPushed);
     }
     _nodeStack = null;
     // fix null
     if (_root.Expression == null)
     {
         if (_root.OperandCount == 0)
         {
             _root = null;
         }
         else if (_root.OperandCount > 1)
         {
             throw ParserException.InternalError();
         }
         else
         {
             _root         = (ExprNode)_root.Operands[0];
             _root._parent = null;
         }
     }
 }
コード例 #2
0
        internal void AddOperator(Operator expr)
        {
            _isStart = false;
            ExprNode newNode     = new ExprNode(expr);
            ExprNode lastOperand = _top.LastOperand;

            if (_top.Expression == null)
            {
                _top.Expression = expr;
            }
            else
            {
                Operator op = _top.Expression as Operator;
                if (op == null)
                {
                    throw ParserException.InternalError();
                }
                else
                {
                    if (expr.Priority > op.Priority)
                    {
                        if (lastOperand != null)
                        {
                            _top.Remove(lastOperand);
                            newNode.Add(lastOperand);
                            _top.Add(newNode);
                            _top = newNode;
                        }
                        else
                        {
                            throw ParserException.InternalError();
                        }
                    }
                    else
                    {
                        if (_top.Parent != null)
                        {
                            newNode.Add(_root);
                            _root = newNode;
                            _top  = newNode;
                        }
                        else
                        {
                            newNode.Add(_top);
                            _top  = newNode;
                            _root = _top;
                        }
                    }
                }
            }
        }