Exemplo n.º 1
0
        // after reading syntaxes creates syntax tree
        // - removes extra brackets
        // - finds operator with minimum prio
        private ISyntaxNode BuildSyntaxTree(List <ISyntaxNode> listNode)
        {
            DeleteExcessiveBrackets(listNode);
            if (listNode.Count == 1)
            {
                return(listNode[0]);
            }

            int         position;
            ISyntaxNode min = FindMinPrioritiOperation(listNode, out position);

            if (listBinaryOperations.IndexOf(min.ToStringValue()) != -1)
            {
                BinaryOperation operation = min as BinaryOperation;
                operation.SetA(BuildSyntaxTree(listNode.GetRange(0, position)));
                operation.SetB(BuildSyntaxTree(listNode.GetRange(position + 1, listNode.Count - (position + 1))));
            }
            if (listUnaryOperations.IndexOf(min.ToStringValue()) != -1)
            {
                UnaryOperation operation = min as UnaryOperation;
                operation.SetA(BuildSyntaxTree(listNode.GetRange(position + 1, listNode.Count - (position + 1))));
            }
            if (listFunctions.IndexOf(min.ToStringValue()) != -1)
            {
                Function function = min as Function;
                function.SetX(BuildSyntaxTree(listNode.GetRange(position + 1, listNode.Count - (position + 1))));
            }
            return(min);
        }