// 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); }
private int CompareOperations(ISyntaxNode a, ISyntaxNode b, int aCountBracket, int bCountBracket) { if (aCountBracket < bCountBracket) { return(1); } if (aCountBracket > bCountBracket) { return(-1); } if (listOperations.IndexOf(a.ToStringValue()) < listOperations.IndexOf(b.ToStringValue())) { return(1); } if (listOperations.IndexOf(a.ToStringValue()) > listOperations.IndexOf(b.ToStringValue())) { return(-1); } return(0); }