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: [email protected] [mailto:antlr-interest-
> [email protected]] On Behalf Of Pauba, Kevin L
> Sent: Friday, January 08, 2010 7:50 AM
> To: [email protected]
> 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




List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address
-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.


Reply via email to