views:

21

answers:

1

Hi

I am stuck with a seemingly simple problem. I want to read a text hierarchy written somewhat like c# code eg;

Common
{
  MyClass1
  {
    Method1
    {
      "Helloworld";
      "GoodBye";     
    }
    Method2
    {
      "SayGoodMorning";
    }
  }
  MyClass2
  {
    Method3
    {
      "M3";
    }
  }
}

Consider common a namespace which can have many classes, a class may have many methods even a method can have another method (just n level concept). And I wish the result something like:

Common MyClass1 Method1 HelloWorld
Common MyClass1 Method1 GoodBye
Common MyClass1 Method2 SayGoodMorning
Common MyClass2 Method3 M3

This can be n level, any help or guidance will be highly appreciated

+1  A: 

Use a Stack object to keep track of the current namespace. Each time you see a "{" push the previous line onto the stack. Each time you see a "}" pop the stack. If the line ends with ";" then use the current values on the stack to build the namespace, then append the current line as the method name.

David