Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

McZ

parsing text..

This topic is 5269 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 using fstream to read in text using the getline function.. but how can I parse different strings from that line? e.g. if I have a script file something like this Material "Marble" { Effect 3 .color.ambient = 0.3 0.3 0.3 .color.diffuse = 0.5 0.5 0.5 .texture[0].file = "textures\marble.tga" } how do I search for the keywords?

Share this post


Link to post
Share on other sites
Advertisement
why not consider using xml. TinyXML is small and eay to use, and solves the "Just Another Text File Parser"-problem


http://www.grinninglizard.com/tinyxml/

Share this post


Link to post
Share on other sites
I want to do it myself.. for educational purpose..

I want to know how I can make it work this way I can create some kind of script engine later.. but first I want to know a good/easy way to parse text for my material scripts and so, and settings files

Share this post


Link to post
Share on other sites
One place to start looking would be stringstream. You can set it equal to a std::string, and then it will act like a std::stream. Thus, you can call things like getline() on it, to read substrings up to characters like ''.'', and read numeric values out of it just like any other stream.

Share this post


Link to post
Share on other sites
Boost's Spirit library is possibly one of the better ways, but it may be overkill if your parsing is not very complex. Take a compiler design class when you get a chance.

Edit: Did I just recommend boost? Ugh, how gamedev.net of me. Someone kill me if I start using D.

[edited by - bobstevens on April 21, 2004 10:18:30 AM]

Share this post


Link to post
Share on other sites
quote:
Original post by bobstevens
Boost''s Spirit library is possibly one of the better ways, but it may be overkill if your parsing is not very complex. Take a compiler design class when you get a chance.

Edit: Did I just recommend boost? Ugh, how gamedev.net of me. Someone kill me if I start using D.

[edited by - bobstevens on April 21, 2004 10:18:30 AM]

Bison isn''t too bad if you can bear using the trainwreck known as C.

Share this post


Link to post
Share on other sites
I was reminded of my love for boost::spirit today. So I''ll second or third that. It has a decent learning curve, but it is fun, just tinker with the examples for awhile.

Share this post


Link to post
Share on other sites
boost::spirit is quite powerful and fun to play with, but I''d say the learning curve can grow appreciably depending on the complexity of the script/setting files you''re parsing.

I''m personally a fan of XML files, even more so since I started getting into C#/.NET development. And I just think they''re very, very cool.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!