Help needed for parsing algorithm

This topic is 3165 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

I'm trying to find a clever way to parse the following text file (well, a part of it) so that it would be organized in nodes (i'd like to end up with a c# treeview).
version // NODE
{
number 8.2
}
morphBinaryFile grizzly.pmd // NODE
figureResFile Grizzly.obj  // NODE
actor BODY:3  // NODE
{

}
actor BODY:3 // NODE
{
name    BODY
on
bend 1
dynamicsLock		0
hidden		0
includeInDepthCue		1
useZBuffer		1
parent UNIVERSE
creaseAngle 80
channels // NODE
{
groups // NODE
{
groupNode Transform  // NODE
{
parmNode Scale
parmNode xScale
parmNode yScale
parmNode zScale
parmNode Twist
parmNode Bend
parmNode Side-Side
parmNode xTran
parmNode yTran
parmNode zTran
}
groupNode Other  // NODE
{
parmNode Roar
}
}
}
}


As you can see each node section is included in a {} block. But since the file structure expands to several levels of recursion, I failed to find a way to build some code that would, for example, create an array where, for each text line, would store the parent node. I'm really stuck so any help is greatly appreciated.

Share on other sites
Have a look at boost spirit which great for parsing files.

Share on other sites
Thanks but too complicate.

Share on other sites
Recursion is one easy way of solving your problem...
void Node::read(){  string line = readline().trim();  if( line == "}" ) return;  if( line == "{" )  {    Node node = new Node(this); // set parent    node.read(); // recursive call    add(node);  }  else  {    add(new Attribute(line));  }}

[Edited by - sirGustav on April 14, 2010 12:03:43 AM]

Share on other sites
What language are you using? (And why?)

1. 1
2. 2
3. 3
Rutin
22
4. 4
5. 5
khawk
14

• 9
• 11
• 11
• 23
• 12
• Forum Statistics

• Total Topics
633654
• Total Posts
3013170
×