Question

i have a class that starts with a variable of type TreeNode in System.Windows.Forms. The class's functions job is to add some nodes to this variable .. but the problem is when i try to add some nodes to it the debugger freeze up and doesn't show any response .. I searched over the internet but i didn't find such a problem .This is one of those functions

NOTE : the line that produce issue is commented

public Node Factor()
    {
        Node result = new Node();
        if (count < tokens.Count && tokens[count] == TokenType.LeftParentheses)
        {
            this.Match(TokenType.LeftParentheses);
            result = this.Expression();
            if (!this.Match(TokenType.RightParentheses))
                return null;
            result.viewnode.Text = "Expression";
        }
        else if (tokens[count] == TokenType.Num)
        {
            if (!this.Match(TokenType.Num))
                return null;
            NumberNode nnode = new NumberNode(lexemes[count - 1]);
            nnode.childs = "NumberNode : Value " + nnode.value + '\n';
            nnode.viewnode = new TreeNode("Number - Value = " + nnode.value);
            result = nnode;
            result.viewnode = nnode.viewnode;
            result.viewnode.Nodes.Add(nnode.viewnode);
        }
        else
        {
            if (!this.Match(TokenType.ID))
                return null;
            IdNode inode = new IdNode(lexemes[count - 1], "0");
            inode.childs = "IdNode - Value : " + inode.name + '\n';
            inode.viewnode = new TreeNode("Id - " + inode.name);
            result = inode;
            result.viewnode = inode.viewnode;
            //the program freezes at this line
            inode.viewnode.Nodes.Add(inode.viewnode);
        }
        return result;
    }
Was it helpful?

Solution

You are adding the node to itself.

should be result.viewnode ...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top