Jump to content
  • Advertisement

Archived

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

Structural

Text parsing - How?

This topic is 5393 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

How do you make a text parser in C/C++? For example something that parses XML to read menu data into the application. I''ve tried to work my way through an XML file with ssprintf, but I can''t even extract the contents between "<" and ">" tags. Perhaps these things are easier with something that supports regular expressions. Does anyone have tips on how I can do this? Preferably with standard C/C++ functionality.

Share this post


Link to post
Share on other sites
Advertisement
There are several XML parsers for C++ already, why not use one of them?
I don''t know any links, but I''m sure you''ll google them up.

Share this post


Link to post
Share on other sites
Go through each character, one at a time. Keep track of what "mode" your in. For example, if you read in a < but haven''t read a space or > yet, then you''re reading in a tag. Read the whole tag. Then match it up with your database of tags. If you reach a >, then end tag mode and enter regular text mode (which ends when it finds a < or one of the special characters like &. If you read a space, enter attribute mode (which ends you find a space, at which point you can enter attribute value mode, when you find an = and a "). In short, its quite complicated, unless you use lex and yacc like someone suggested (which are, in fact, generic parsers, not just used for XML and many programs use like lilypond, a nice program that generates sheet music in postscript format from code that describes the music).

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!