2
$\begingroup$

I'm working on a compiler. The textbooks I have say to output a 3-address intermediate code. This can be translated into the target language of choice.

I don't have a problem with the bulk of the source being translated to 3-addr code. But for the data-rich symbol table, this is awkward.

Is the exclusive use of 3-addr code old, obsolete advice? My compiler is multi-pass compiler. I'm working pretty hard to build a symbol table in my first pass, and I'm pretty much having to reconstruct it in 3-address code for the next pass. This seems like make-work to me when I could create from my symbol table XML or JSON. I could write that to the intermediate file instead.

How should I represent my symbol table in the intermediate code?

$\endgroup$
5
$\begingroup$

XML and JSON are formats for representing data. The actual kind of data depends upon how you use them. For instance, they could be used to represent 3-address intermediate code or an abstract syntax tree, or even a symbol table.

3-address intermediate code is best generated only at the very end, as input to the code generator. For all other passes, keep as much information around as possible. This could include a decorated abstract syntax tree (decorated with types and other information) and a symbol table.

In fact, I'd only use the 3-address format if you are generating assembly. For a higher level target language, use a higher-level intermediate format.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.