hi i have that code
and this function gives me static overflow when i run the problem and stopped to work can anyone tell me why is this happening

      public bool declaration_List()
    {
       // sc.token();

            if (declaration_List())

            {
                if (declaration())


                return (true);
            }
            else
                return (false);

        if (declaration())
        {
            return (true);
        }
        else
            return (false);

    }

The first thing your function does is call itself. That seems like it would go on forever and accomplish nothing unless there is something I'm missing.

It seems there shoud be one more return at the bottom OR
the function needs to be rewritten.

Some of this could depend on what happens inside the call to declaration(). Is it also recursive?

If you first change line 16 (and below) to just " return declaration(); ", you can start to figure out what the first part is supposed to be doing.

bguild has this spot on.

The first thing your code does is call itself, this will lead to an infinite loop. Eventually you run out of stack space and the program crashes (giving you your exception).

From the code you've posted, I can't really infer what you're trying to do, but I would imagine you need it to be recursive.

If you do, you should perform logic before attempting to call the same method again.

public Boolean RecursiveResultFinder(ClassWithChildren parent)
{
    // This method will stop as soon as resultIWant = true
    Boolean resultIWant = child.IsItMeYoureLookingFor;

    if(!resultIWant)
    {
        foreach(ClassWithChildren child in parent.Children)
        {
            Boolean childResult = RecursiveResultFinder(child);
            if(childResult)
                return true;
        }

        return false;
    }

    return true;
}

The above is a small example of a recursive function. The above will perform a depth first search to find the first object with the variable marked true.
There is also a width first search (which may be more efficient, depends on your use case)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.