Integrating ANTLR 4 in a C++ application

antlr, c++, dsl

Solution

ANTLR v3 has various different targets, most notably Java (of course), C, C#, JavaScript and Python. For a full list, see: http://www.antlr.org/wiki/display/ANTLR3/Code+Generation+Targets

ANTLR v4, however, only has a Java target at this moment.

Problem

Recently I picked up a copy of `The Definitive ANTLR 4 Reference` and since I am sophisticated when it comes to working with grammars and languages I wanted to work on my DSL I once have written using `yacc` and `bison`. The general idea is to write a translator (with included validation for type safety(1)) which translates the DSL to JavaScript during runtime which is then executed by v8. Although ANTLR was designed for inclusion in Java applications I would like to stay with native C++. Can ANTLR 4 produce such a C parser/lexer(2) which I can include using a C++-style wrapper? And how to do so? (1) The book has some good examples which I will use as a template. (2) I am not sure but I think that I read somewhere that ANTLR doesn't support output in C++, am I right?

Original source