Skip to main content
gamedev.net
🔒 Locked

Need Help

Started by Rtan 1 reply 200+ views
Original Post
Rtan
Rtan
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?
TR
SiCrane
SiCrane
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.
DarkHamster
DarkHamster
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.


"There is no dark side of the moon really,
As a matter of fact, its all dark."

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.