Example #1
0
        internal void AddOperand(Operand expr)
        {
            _isStart = false;
            ExprNode argNode = new ExprNode(expr);

            _top.Add(argNode);
        }
Example #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;
                        }
                    }
                }
            }
        }
Example #3
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;
						}
					}

				}
			}
		}