[antlr-interest] Combining front-ends and back-ends

Cameron Ross cross at kojeware.com
Tue Mar 16 06:29:05 PDT 2010


I need to translate text files from language A to language B.  I already
have the following antlr3 gear for these languages:
  - an antlr grammar for language A that produces AST_A
  - a tree walker (tw_A) that transforms AST_A to AST_B'
  - an antlr grammar for language B that produces AST_B
  - a tree walker (tw_B) that uses string templates to transform AST_B into
text for language B

I'd like to establish the following pipeline to translate text files from
language A to language B:
 - text_A -> lexer_A -> parser_A -> tw_A -> tw_B -> text_B

However, tw_B does does not properly walk trees generated by tw_A.  This is
probably a result of the tree walkers being compiled against difference
token vocabularies.  Is there a way to somehow integrate vocabularies so
that you can reuse a pre-compiled back-end like this?

If not, I guess I'll have to integrate tw_B with the source generation
process for the language A components.  However, this also has challenges.
 Note that AST_B' (from language A) is a subset of AST_B and not all of the
tokens referenced in tw_B are present in tw_A.  That is, , so tw_B requires
more than just tokenVocab=tw_A.

I could cut-and-paste tw_B to create a tw_A2, but I plan to use AST_B as an
intermediate form for translating several languages to language B, so I'm
looking to reuse...  I'd like to keep tw_B independent from tw_A.

Thanks,
Cameron.


More information about the antlr-interest mailing list