private void AddChildToOperator(TokenNode child, TokenNode parent)
        {
            bool mergeCommas = (parent.Token.IsSymbol(",") && child.Token.IsSymbol(","));
            bool mergeColons = (parent.Token.IsSymbol(":") && child.Token.IsSymbol(":") && child.ChildrenTokenNodes.Count == 2);

            if(mergeCommas || mergeColons) {
                foreach(var newChild in child.ChildrenTokenNodes) {
                    parent.ChildrenTokenNodes.Add(newChild);
                }
            } else {
                parent.ChildrenTokenNodes.Add(child);
            }
        }
Exemple #2
0
        private TokenNode ReadBinaryExpression(TokenNode tree)
        {
            var opcodeToken = this.tokens.Dequeue();
            var right = ReadLevel(GetOperatorTier(opcodeToken.Value.ToString(), BinaryOperatorTiers) + 1);

            if(right == null) {
                throw new MissingDataException("Expected something after operator " + opcodeToken.Value);
            }

            var opcodeNode = new TokenNode(opcodeToken);

            AddChildToOperator(tree, opcodeNode);

            opcodeNode.ChildrenNodes.Add(right);

            return opcodeNode;
        }
Exemple #3
0
        public bool Equals(TokenNode otherTokenNode)
        {
            if(otherTokenNode == null) {
                return false;
            }

            if(otherTokenNode.Token == null) {
                if(this.Token != null) {
                    return false;
                }
            } else if(!otherTokenNode.Token.Equals(this.Token)) {
                return false;
            }

            if(!otherTokenNode.ChildrenTokenNodes.SequenceEqual(this.ChildrenTokenNodes)) {
                return false;
            }

            return true;
        }
Exemple #4
0
        public bool GetBoolFrom(TokenNode tokenNode)
        {
            if(tokenNode == null) {
                throw new ArgumentNullException("tokenNode");
            }

            return GetBoolFrom(tokenNode.Evaluate(this));
        }
Exemple #5
0
 public ConditionSet(TokenNode condition, IList<NodeBase> children)
 {
     Condition = condition;
     ChildrenNodes = children;
 }
Exemple #6
0
 public ConditionSet(TokenNode condition)
     : this(condition, new List<NodeBase>())
 {
 }
        private TokenNode ReadUnaryOperator()
        {
            var token = this.tokens.Dequeue();
            var node = new TokenNode(token);

            node.ChildrenTokenNodes.Add(ReadLevel(GetOperatorTier(token.Value.ToString(), UnaryOperatorTiers)));

            return node;
        }
        private TokenNode ReadIdentifier()
        {
            var identifier = this.tokens.Dequeue();
            var identifierNode = new TokenNode(identifier);

            if(this.tokens.Count != 0 && this.tokens.Peek().IsSymbol("(")) {
                this.tokens.Dequeue();

                var arguments = ReadLevel(0);

                if(arguments != null) {
                    identifierNode.ChildrenTokenNodes.Add(arguments);
                }

                ReadClosingParentheses();
            }

            return identifierNode;
        }
        private static void CheckTree(object expected, TokenNode tree)
        {
            object[] array = expected as object[];

            if(array != null) {
                CheckTree(array[0], tree);

                var tokenChildren = tree.ChildrenTokenNodes;

                Assert.AreEqual(array.Length - 1, tokenChildren.Count);

                for(int i = 1; i < array.Length; ++i) {
                    CheckTree(array[i], tokenChildren[i - 1]);
                }
            } else {
                Assert.AreEqual(expected, tree.Token.Value);
            }
        }