Sign in to follow this  

intermediate code generation

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

This topic is 3459 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this