intermediate code generation

Discussion in 'C' started by haba, Jun 23, 2008.

  1. haba

    haba New Member

    Joined:
    Nov 18, 2007
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    Hey,

    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
     
  2. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    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.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice