[antlr-interest] C++ & JAVA code in the same grammar file?

Bryan Ewbank ewbank at gmail.com
Sun Mar 26 04:06:50 PST 2006

On 3/25/06, John Williams <jr.williams at tiscali.co.uk> wrote:
> Is there any way that I can ask ANTLR to use the included JAVA code when I
> specify language="java" and the included C++ code when I specify
> language="Cpp"?

Since C and java use common syntax for some stuff (e.g., function calls), you
might explore how close you can get by extracting /all/ behavior to another
file, and then just doing callouts in the grammar file - e.g., calling
functions inherited from the baseclass.

This would allow one ANTLR input file that requires minor preprocessing
changes, as with sed, to work for both target languages.  This would be ideal,
but I'm sure there will be other minor tweaks required...
    sed 's/language="java"/language="Cpp"/'

Hope this helps,
- Bryan

More information about the antlr-interest mailing list