private void MergeNodeToLeftSide(BinaryFunctionSemanticNode root, BinaryFunctionSemanticNode node) { var currentNode = root; while (currentNode.LeftChild.Type == SemanticNodeTypes.BinaryFunction) { currentNode = (BinaryFunctionSemanticNode)currentNode.LeftChild; } currentNode.LeftChild = node; }
private List <SemanticNode> CreateFlatList(IList <SyntaxToken> syntaxTokens) { var flatSemanticNodes = new List <SemanticNode>(16); foreach (var token in syntaxTokens) { SemanticNode node; switch (token.Type) { case SyntaxTokenTypes.Number: { node = new NumberSemanticNode(token.Value); } break; case SyntaxTokenTypes.BinaryFunction: { var priority = _functionPriorityStore.GetPripority(token.Value); node = new BinaryFunctionSemanticNode(token.Value, priority); } break; case SyntaxTokenTypes.Braces: { var bst = (BracesSyntaxToken)token; var childNodes = ConvertSyntaxToSemantics(bst.ChildTokens); node = new BracesSemanticNode(childNodes); } break; case SyntaxTokenTypes.UnaryFunction: { var ufst = (UnaryFunctionSyntaxToken)token; var braces = (BracesSemanticNode)ConvertSyntaxToSemantics(new[] { ufst.Braces }).Single(); node = new UnaryFunctionSemanticNode(ufst.Value, braces); } break; default: { throw new NotSupportedException( _resourceStore.GetExceptionMessage("UnknownSyntaxTokenType", token.Type)); } } flatSemanticNodes.Add(node); } return(flatSemanticNodes); }