Jump to content
  • Advertisement
Sign in to follow this  
FreJa

intermediate code generation

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

Hey, I'm trying to generate three-address instructions for simple C programs, however, I'm having a hard time understanding all this, and have a few questions: 1) Why are symbol tables needed? Isn't using a quadruple table enough to hold all the statementes enough? 2) Googling about this stuff I see a bunch of presentations using attributes of non-terminals like place, code, begin, after, end, etc. Is this really needed? Can't I just traverse the parse tree and generate the code there? Huge huge thanks!

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by FreJa
Hey,

I'm trying to generate three-address instructions for simple C programs, however, I'm having a hard time understanding all this, and have a few questions:
1) Why are symbol tables needed? Isn't using a quadruple table enough to hold all the statementes enough?
2) Googling about this stuff I see a bunch of presentations using attributes of non-terminals like place, code, begin, after, end, etc. Is this really needed? Can't I just traverse the parse tree and generate the code there?

Huge huge thanks!


1) You need a symbol table to hold info about your operands. A table of 3 operands and an op isn't enough to tell you about operand types, alignment, corresponding machine type, base register and displacement for addressing, volatile or not, number of elements, etc.

2) If you want to do it in two passes then yes, generate a tree then traverse it depth first. If you want to do it in one pass you have to generate temporary labels for forward branches then fill them in later. To do that you need some production rules and a grammer, and you use non-terminals in these rules.

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.

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!