[antlr-interest] target language independent action code

Arnulf Heller aheller at gmx.at
Sun Jan 20 12:14:23 PST 2008


hi,

I know this topic was discussed a couple of times here ...

But as far as I know there is no solution available right now 
(possibly apart from Loring Cramers yggdrasil).

I think target language independent action code would be of great help because:

1. ANTLR provides a steadily growing foundation of grammars for 
various languages (which is very cool). Unfortunately its almost 
certain that the grammar targets a different language ...
2. Action code clutters the readability of the grammar - especially 
if its in a target language that you don't know.

Because ANTLR changes a lot over time, action code should be embedded 
into ANTLR directly with "on board" tools.

So why not use these wonderful string templates?

Instead of writing

{ myDict.add($ID.text()); }

one could write for instance

[ DictAdd(ID) ]

which ANTLR could translate on the fly to target language code at 
that position.

Then the writer of the grammar needs to provide a string template 
group (with a template "DictAdd") which performs the translation to 
"his" target language.
This way targetting a different language amounts to rewriting the 
string template group.
This does not alter the original grammar and will hopefully be posted :-)

The target language folks even could provide a minimal toolset for 
dictionaries and the like. If there is a good collection of tools, 
the action code gets structured, documented and well known by the time.

What do you think?



More information about the antlr-interest mailing list