コード例 #1
0
		public ValueNode(ValueNode node)
		{
			Value = node.Value;
			Name = Value.ToString();
		}
コード例 #2
0
		public bool Equals(ValueNode v)
		{
			if (v != null)
				return v.Value == Value;
			else
				return false;
		}
コード例 #3
0
		private MathFuncNode MakeSubstitution(MathFuncNode node)
		{
			int ind = -1;
			for (int j = 0; j < LeftNode.Childs.Count; j++)
				if (LeftNode.Childs[j].Name == node.Name)
				{
					ind = j;
					break;
				}
			if (ind != -1)
			{
				if (_currentFunc.Childs[ind].IsTerminal)
					return _currentFunc.Childs[ind];
				else
					return new FuncNode((FuncNode)_currentFunc.Childs[ind]);
			}

			MathFuncNode result;
			switch (node.Type)
			{
				case MathNodeType.Calculated:
					result = new CalculatedNode(((CalculatedNode)node).Value);
					break;
				case MathNodeType.Value:
					result = new ValueNode((ValueNode)node);
					break;
				case MathNodeType.Constant:
				case MathNodeType.Variable:
					result = node;
					break;
				default:
				case MathNodeType.Function:
					result = ((FuncNode)node).FunctionType != null ?
						new FuncNode((KnownFuncType)((FuncNode)node).FunctionType) :
						new FuncNode(node.Name);
					break;
			}

			for (int i = 0; i < node.Childs.Count; i++)
				switch (node.Childs[i].Type)
				{
					case MathNodeType.Calculated:
						result.Childs.Add(new CalculatedNode((CalculatedNode)node.Childs[i]));
						break;
					case MathNodeType.Value:
						result.Childs.Add(new ValueNode((ValueNode)node.Childs[i]));
						break;
					case MathNodeType.Constant:
					case MathNodeType.Variable:
						result.Childs.Add(node.Childs[i]);
						break;
					case MathNodeType.Function:
						result.Childs.Add(MakeSubstitution((FuncNode)node.Childs[i]));
						break;
				}
			return result;
		}
コード例 #4
0
 public ValueNode(ValueNode node)
 {
     Value = node.Value;
     Name  = Value.ToString();
 }
コード例 #5
0
        private MathFuncNode MakeSubstitution(MathFuncNode node)
        {
            int ind = -1;

            for (int j = 0; j < LeftNode.Children.Count; j++)
            {
                if (LeftNode.Children[j].Name == node.Name)
                {
                    ind = j;
                    break;
                }
            }
            if (ind != -1)
            {
                if (_currentFunc.Children[ind].IsTerminal)
                {
                    return(_currentFunc.Children[ind]);
                }
                else
                {
                    return(new FuncNode((FuncNode)_currentFunc.Children[ind]));
                }
            }

            MathFuncNode result = null;

            switch (node)
            {
            case CalculatedNode calculatedNode:
                result = new CalculatedNode(calculatedNode.Value);
                break;

            case ValueNode valueNode:
                result = new ValueNode(valueNode);
                break;

            case ConstNode constNode:
            case VarNode varNode:
                result = node;
                break;

            case FuncNode funcNode:
                result = funcNode.FunctionType != null ?
                         new FuncNode((KnownFuncType)funcNode.FunctionType) :
                         new FuncNode(node.Name);
                break;
            }

            for (int i = 0; i < node.Children.Count; i++)
            {
                switch (node.Children[i])
                {
                case CalculatedNode calculatedNode:
                    result.Children.Add(new CalculatedNode(calculatedNode));
                    break;

                case ValueNode valueNode:
                    result.Children.Add(new ValueNode(valueNode));
                    break;

                case ConstNode constNode:
                case VarNode varNode:
                    result.Children.Add(node.Children[i]);
                    break;

                case FuncNode funcNode:
                    result.Children.Add(MakeSubstitution(funcNode));
                    break;
                }
            }
            return(result);
        }