Jump to content
  • Advertisement
Sign in to follow this  
Alessandro

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.

If you intended to correct an error in the post then please contact us.

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
	addToMenu	1
	castsShadow		1
	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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!