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

Jim Idle jimi at temporal-wave.com
Fri Jan 8 12:30:55 PST 2010


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

> -----Original Message-----
> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> bounces at antlr.org] On Behalf Of Pauba, Kevin L
> Sent: Friday, January 08, 2010 7:50 AM
> To: antlr-interest at antlr.org
> Subject: [antlr-interest] Can ST be used to generate binary output?
> 
> I would like to use my ANTLR-based DSL compiler to generate pretty-
> printed source, documentation (similar to javadocs) and bytecode output
> using StringTemplate.  The interpreter for this DSL needs bytecode in
> binary form.
> 
> Is ST able to generate binary output (I know it can do the gruntwork
> for pretty-printing and documentation)?  If so, might you have some
> pointers on how to do it?
> 
> Thanks!
> 
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-
> email-address





More information about the antlr-interest mailing list