[antlr-interest] Language-Neutral Actions

Terence Parr parrt at cs.usfca.edu
Sat Apr 16 16:09:09 PDT 2005


On Apr 15, 2005, at 6:37 AM, Scott Stanchfield wrote:
> I'd really like to see language-neutral actions in ANTLR 3.
>
> The basic idea is that all action code is simply calls to behavior 
> methods
> in some other object.
>
> Depending on what target language is specified, different "glue" code 
> is
> formed to contact that other object.

An attractive idea I have considered.  I even considered building a 
simple language people could use to directly code actions in the 
grammar.

> This would allow a grammar to be targeted to pretty much any language.

Well, in my experience you always need an action where you don't have 
one yet and you need local variables access and parameters etc...  How 
do you pass arguments around to different rules in a language 
independent way?

> Some old parser generators I used did things like
>
>   foo: fee fie fo @doSomething(fee,fie,fo);
>
> which would allow you to target it to multiple languages. The parser
> generator would change @doSomething(...) into whatever was appropriate 
> for
> the target language.

This is sort of a "SAX" model and works well for some stuff.

> I don't know that we'd want to use the same syntax (I like the {...} 
> for
> actions), but we could have a grammar option that specifies 
> language-netrual
> actions and all {...} code is assumed neutral.

I'm not sure language independence is achievable with this mechanism 
though it is attractive in many cases.

Ter
--
CS Professor & Grad Director, University of San Francisco
Creator, ANTLR Parser Generator, http://www.antlr.org
Cofounder, http://www.jguru.com





More information about the antlr-interest mailing list