Jump to content
  • Advertisement

Archived

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

Rtan

Need Help

This topic is 5273 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 have to write a compiler that reads a text file and parses strings as follows: a = 2 + (1 * 3) - 7; print a; c = a + 4; print c; ** comment save c; ** saves c in a file print c * (a + 45); I have to do it in C. Does anybody have an idea how to start?

Share this post


Link to post
Share on other sites
Advertisement
If you want to do it by hand, I''d look up an article about recursive decent parsing. There are also some decent threads about this in the forums if you can get the search to find them.

For automated tools, I''d recommend lex and yacc (or some of the variants like flex and bison). There are some pretty good tutorials on how to use them on the net. Alternately, you can try the book "Lex and Yacc" by John Levine, Tony Mason, and Doug Brown.

Share this post


Link to post
Share on other sites
Something that simple can easily be done with a recursive descent parser. If you can use C++ though, look into spirit (boost.org), it''s a C++ meta-language parser, that I''ve found to be both powerful and easy to use.

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!