[antlr-interest] Can ST be used to generate binary output?

Pauba, Kevin L KLPauba at west.com
Fri Jan 8 13:53:01 PST 2010


Thanks (again!) Jim.

I'll take that under advisement.  I've had the LIPs ebook for some time now (just received the hardcopy this week) but haven't dug too deep in it.  I'll do that now.



-----Original Message-----
From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-bounces at antlr.org] On Behalf Of Jim Idle
Sent: Friday, January 08, 2010 2:31 PM
To: antlr-interest at antlr.org
Subject: Re: [antlr-interest] Can ST be used to generate binary output?

It is usually better to produce an intermediate assembler representation of your byte code then have a parser that can assemble that in to byte code. You will for instance need to resolve the targets of 'jmp' and things like that and having an assembly language listing of the 'byte code' lets you be more productive when debugging and so on. Such assembly/intermediate languages are also good for optimizing phases.

When I need multiple different outputs like this then I create an Abstract class with common functionality for code generation and derive generators for each target from that. I have the code generator create StringTemplates when this is what is needed and also have a code generator that produces the byte code. Then I have the tree walker call the code generation methods rather than create templates directly in the tree grammar. You can then do multiple walks with different code generators.

If you are trying to generate Java byte code then write a code generator that interfaces to the ASM package: http://asm.ow2.org/ which is very good. There is also LLVM of course.

Finally I think that you would benefit greatly from reading the new book:

http://pragprog.com/titles/tpdsl/language-implementation-patterns

Which will guide you through some working of examples of all of this stuff.

Jim




More information about the antlr-interest mailing list