intermediate code generation
I'm trying to generate three address instructions for some VERY simple C programs, however, I'm having a bit of trouble understanding all this. Googling this stuff I found a bunch of presentations using attributes of non-terminals, such as place and code. I don't really see the need for this. Isn't it enough to traverse the parse tree and generate the code from that?
Also, one more thing, why would I need symbol tables? Isn't it enough to just have a quadruple for each statement?
Thank you very much
Re: intermediate code generation
I've no idea what much of your post means, you're obviously in the middle of something (writing a compiler?) but you're asking questions that can only be answered by someone who understands exactly where you're at.
If you don't see the need for features used by other peoples' implementations of whatever you're implementing then don't use them. Bookmark them as interesting possibilities for later on when/if you get stuck, but nobody's forcing you to implement this project the same way as they did.
I've no idea what a quadruple is. If you don't think you need a symbol table then don't use one. But if you are writing a compiler you'll need some kind of lookup table for user-defined things so that later on in the same code you'll know what a particular symbol means. e.g. int i=5; then later on i++; You'll need to know what i is so that you can syntax-check i++ and so that you can generate the correct object code, if i is an int then just adding 1 will do, but if it's a pointer you'll need to add sizeof(pointer), and if it's a constant then you'll need to throw an error. But you can try implementing the project just by using quadruples and ignoring the concept of symbol tables altogether, if you like.
|All times are GMT +5.5. The time now is 18:22.|