[antlr-interest] Intermediate code generation...

sohail at taggedtype.net sohail at taggedtype.net
Thu Nov 24 11:20:07 PST 2005


> I'm curious what strategies people use when generating intermediate
> code from an ANTLR grammar/language.
>
> I'm putzing with a BASIC (that RBASIC sample I needed help with
> earlier) compiler which I would like to have multiple target CPUs
> coming out of the backend (principally 6502, 65c02, and 65816, but
> potentially for embedded devices too).
>
> The general process was to be source code ==compile=> intermediate
> code ==optimize=> intermediate code ==generate=> target CPU assembly
> ==assemble=> executable. I think that's fairly standard...
>
> What has me stymied a bit is that ANTLR to intermediate code
> generation step. I'm pretty much looking at a separate Java
> application to take the generated AST and start writing code. It feels
> brute-force, but I'm not certain there's really a better method. I see
> a lot of people dump stuff into the TreeParser, but seems to add
> confusion rather than clarity.

Hi Rob,

I would suggest having a TreeParser to create your AST and then multiple
TreeParsers to generate code. I don't know how well you could optimize
with multiple tree parsers though.

Sohail


More information about the antlr-interest mailing list